fold

inline fun <T, R> Array<out T>.fold(initial: R, operation: (acc: R, T) -> R): R(source)
inline fun <R> ByteArray.fold(initial: R, operation: (acc: R, Byte) -> R): R(source)
inline fun <R> ShortArray.fold(initial: R, operation: (acc: R, Short) -> R): R(source)
inline fun <R> IntArray.fold(initial: R, operation: (acc: R, Int) -> R): R(source)
inline fun <R> LongArray.fold(initial: R, operation: (acc: R, Long) -> R): R(source)
inline fun <R> FloatArray.fold(initial: R, operation: (acc: R, Float) -> R): R(source)
inline fun <R> DoubleArray.fold(initial: R, operation: (acc: R, Double) -> R): R(source)
inline fun <R> BooleanArray.fold(initial: R, operation: (acc: R, Boolean) -> R): R(source)
inline fun <R> CharArray.fold(initial: R, operation: (acc: R, Char) -> R): R(source)

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

Returns the specified initial value if the array is empty.

Since Kotlin

1.0

Parameters

operation

function that takes current accumulator value and an element, and calculates the next accumulator value.


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

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

Returns the specified initial value if the collection is empty.

Since Kotlin

1.0

Parameters

operation

function that takes current accumulator value and an element, and calculates the next accumulator value.