Skip to main content
Version: Next

Filter

Creates a new list with all items that pass the test of the predicate function.

Description

The filter brick creates a new list that contains all items for which the provided function (predicate) returns true and so pass the test.

The output control flow is triggered when all items have been processed.

In other words, Filter selects some elements of a list and is equivalent to Javascript's <a href="https://medium.com/@JeffLombardJr/understanding-foreach-map-filter-and-find-in-javascript-f91da93b9f2c" target="_blank">filter()</a>

Example:

  • inputs

    1. list = ["spray", "limit", "elite", "exuberant", "destruction", "present"]
    2. predicate = (word) =&gt; word.length &gt; 6
  • outputs

    1. filtered list = ["exuberant", "destruction", "present"]

Inputs

  • Control Flow (Control Flow)
  • list (List): The original list to iterate on.
  • predicate (Predicate): The predicate function that test whether an item is present in the filtered list.
    Inputs:
    - start (Control Flow): Triggered when the item is to be processed.
    - item (Object): The current item of the list.
    - rank (Number): The rank of the current item.
    - list (List): The full list being iterated.

    Outputs:
    - end (Control Flow): Triggered when the processing is completed.
    - result (Boolean): Set it to true if item is to be selected by the filter and should be kept in filtered list.

Outputs

  • Control Flow (Control Flow)
  • filtered list (List): The created list with items that pass the test.