$set.filter($func)
Filters set by applying the func predicate function to each of its elements. The resulting set contains only the elements that the func predicate function has evaluated as true.
| Name | Type | Description | Mandatory | Default |
|---|---|---|---|---|
| set | Set | A set to be filtered according to func. |
yes | |
| func | Function | Predicate function to be applied to all elements of set. |
yes |
Type: Set
A new set containing all elements from set for which the predicate function resulted true.
list(1, 3, 5, 3, 7, 8, 3, 9)
.filter(x -> $x > 4)
Output: A set with the elements [5, 7, 8, 9].
For all other numbers, the function returns false.