Skip to content

List

Filter

Filter(list: any[], predicate: (any) -> boolean) -> any[]

The items of list for which predicate holds, in order.

output big = Filter([4, 8, 15, 16], item => item > 10)
big
[15,16]

Map

Map(list: any[], transform: (any) -> any) -> any[]

Each item of list passed through transform.

output doubled = Map([1, 2, 3], item => item * 2)
doubled
[2,4,6]

Find

Find(list: any[], predicate: (any) -> boolean) -> any

The first item of list for which predicate holds, or null.

output first = Find([4, 8, 15, 16], item => item > 10)
first
15

Every

Every(list: any[], predicate: (any) -> boolean) -> boolean

True when predicate holds for every item of list.

output allBig = Every([15, 16, 23], item => item > 10)
allBig
true

Some

Some(list: any[], predicate: (any) -> boolean) -> boolean

True when predicate holds for at least one item of list.

output anyBig = Some([4, 8, 15], item => item > 10)
anyBig
true

Reduce

Reduce(list: any[], initial: any, reducer: (any, any) -> any) -> any

Folds list into one value, left to right, starting from initial.

output total = Reduce([1, 2, 3], 0, (acc, item) => acc + item)
total
6
let scores = [4, 8, 15, 16, 23]
output best = Reduce(scores, 0, (acc, item) => If(item > acc, item, acc))
best
23