Sentinel
Language: Collection Operations
Collection operations are expressions that are performed on a list or map to return a variation of the initial data.
At the moment, filter
is the only collection operation available.
Filter Expression
filter
is a quantifier
expression that
returns a subset of the provided collection. Only elements whose filter body
returns true will be returned. If any of the elements filter body returns
undefined, the final result will be undefined.
Filter uses the same syntax as the any
and all
boolean
expressions:
filter list as value { condition } // Single-iterator, list
filter list as idx, value { condition } // Double-iterator, list
filter map as key { condition } // Single-iterator, map
filter map as key, value { condition } // Double-iterator, map
Examples:
l = [1, 1, 2, 3, 5, 8]
evens = filter l as v { v % 2 is 0 } // [2, 8]
m = { "a": "foo", "b": "bar" }
matched_foo = filter m as _, v { v is "foo" } // { "a": "foo" }