fold

inline fun <K, V, R> Map<out K, V>.fold(initial: R, operation: (acc: R, Map.Entry<K, V>) -> R): R

Accumulates value starting with initial value and applying operation to current accumulator value and each entry of the map.

Returns the specified initial value if the map is empty.

Parameters

initial

initial value of the accumulation.

operation

function that takes current accumulator value and an entry of the map and calculates the next accumulator value.