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, listfilter list as idx, value { condition } // Double-iterator, list filter map as key { condition } // Single-iterator, mapfilter 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" }
Map Expression
map
is a quantifier
expression that
returns a list, regardless of the input collection type. Each element within the
input collection is evaluted according to the map expression body and appended
to the result.
l = [1, 2]r = map l as v { v % 2 } // [false, true] m = { "a": "foo", "b": "bar" }r = map m as k, v { v } // ["foo", "bar"]