std/core/functions
std/core/src/functions.trb
Names for the three closure shapes that signatures take most: a question about one value, an effect on one value and a conversion of one value into another.
Each is an alias, so it is transparent: any closure or function of the shape fits, and the alias adds no type of its
own. A closure without parameters has no name here, because () => Value is already as short as one.
alias Predicate
type Predicate<Value> = (value: Value) => Bool
A closure that answers a yes-or-no question about one value: what filter, find, any and takeWhile take.
Examples
fn countWhere(numbers: List<Int>, predicate: Predicate<Int>): Int {
numbers.filter(predicate).count()
}
alias Action
type Action<Value> = (value: Value) => Void
A closure called for its effect on one value, with nothing to return: what forEach takes.
Examples
fn visit(names: List<String>, action: Action<String>) {
names.forEach action
}
alias Transform
type Transform<Input, Output> = (value: Input) => Output
A closure that turns one value into another: what map takes, and the key of sorted and groupBy.
Examples
fn labels(numbers: List<Int>, transform: Transform<Int, String>): List<String> {
numbers.map(transform).toList()
}