fold
Full name: taxi.stdlib.fold
Signature
declare extension function <T,A> fold(collection: T[], initial: A, callback: (T,A) -> A):ADescription
Iterates over a collection, combining elements with an accumulator to produce a single result.
Unlike reduce, fold starts with an explicit initial value as the accumulator.
// Compute a weighted sum
model Entry {
weight: Weight inherits Int
score: Score inherits Int
}
type WeightedTotal by (Entry[]) -> Entry[].fold(0, (Entry, Int) -> Int + (Weight * Score))