Filters various data types received at its input, by passing forward only certain parts of the data based on some criteria.

filt(din: Union, *, fixsel) → din.types[fixsel]:

Receive data of the Union type, and passes the data forward only when the Union carries the data type designated by the fixsel compile time parameter. Output data type is the Union type designated by the fixsel parameter.

In the example, the driver drv sends data of the type Union[Uint[8], Int[8]], which means that the data can either be an 8-bit unsigned integer or an 8-bit signed integer. Types in the Union are enumerated in the order they are listed, so Uint[8] has an ID of 0 and Int[8] has an ID of 1. The driver alternates between sending the unsigned and signed values, but only the unsigned values are passed forward since filt() is configured to pass the values of the type with the ID of 0 (fixsel = 0).

drv(t=Union[Uint[8], Int[8]], seq=[(1, 0), (2, 1), (3, 0), (4, 1), (5, 0)]) \
    | filt(fixsel=0) \
    | check(ref=[1, 3, 5])
filt(din: Queue, *, f) → din

Receives a Queue and filters-out elements of the Queue based on the decision made by the function f() which is received as a parameter. Function f() should receive elements of the input Queue and output values of type Bool, either 0 if the element should be discarded or 1 if it should be passed forward. It should have a following signature:

f(x: → Bool

The example shows how filt() can be used to select even numbers from a Queue of numbers 0 to 9 sent by the driver. In order to retain the consistency of the output Queue.

def even(x: Uint) -> Bool:
    return not x[0]

drv(t=Queue[Uint[8]], seq=[list(range(10))]) \
    | filt(f=even) \
    | check(ref=[list(range(0, 10, 2))])

The filt() gear needs to delay output of the received data in order to maintain the proper Queue formatting. In the following example, the first element that is received needs to be kept in the buffer and finally output together with the eot (end of transaction) flag.

drv(t=Queue[Uint[8]], seq=[[0, 1, 3, 5, 7, 9]]) \

If all elements of the Queue are filtered out, nothing is sent forward:

drv(t=Queue[Uint[8]], seq=[[1, 3, 5, 9]]) \
filt(din: Tuple[{'data': Union, 'sel': Uint}]) → din['data']

Same functionality as the first filt() variant, but allows for the sel parameter to be specified at run time.