Filter Block
Filter an array based on boolean conditions
Overview
The Filter Block allows you to filter an array based on a corresponding array of boolean values. It takes an array of any data type and an array of boolean values of the same length, then outputs a new array containing only the elements where the corresponding boolean value is true
.
This block is particularly useful for filtering arrays based on specific conditions, especially when combined with other blocks like Compare in a batched operation.
Inputs
The array to be filtered. Non-array inputs will be coerced into an array.
An array of boolean values indicating whether to include each element in the array. The length of this array should match the length of the array input.
Outputs
The filtered array, containing only the elements where the corresponding boolean value in the include input was true
. The output maintains the data type of the input array.
Example: Filter numbers greater than 3
- Create an Array Block with values
[1, 2, 3, 4, 5]
. - Add a Compare Block, set comparison to
>
, and enable batching. - Create a Number Block with value
3
. - Connect the Array Block to Compare Block’s
A
input, and Number Block toB
input. - Add a Filter Block, connect Array Block to
array
input and Compare Block’sResult
toinclude
input. - Run the flow. The Filter Block’s
filtered
output should be[4, 5]
.
Error Handling
The Filter Block will error if:
- The
array
orinclude
inputs are not provided - The lengths of the input arrays do not match