reduce

Full name: taxi.stdlib.reduce

Signature

declare extension function <T,A> reduce(collection: T[], callback: (T,A) -> A):A

Description

Reduces a collection to a single value by applying a combining function to each element and the accumulated result.

Unlike fold, there is no initial value — the first element of the collection is used as the starting accumulator.

// Sum a list of integers
find {
   total: Int = numbers.reduce((Int, Int) -> Int + Int)
}
Next
Welcome to Taxi