fold

inline fun <T, R> Iterable<T>.fold(initial: R, operation: (R, T) -> R): R(source)

Accumulates elements in iteration order, passing the current result and each element to operation. Returns initial unchanged when this iterable is empty.