What’s the right name for this function? It’s like...
# naming
s
What’s the right name for this function? It’s like
fold
, but the
operation
is allowed to return
null
, in which case the whole thing exits early with a
null
return value.
Copy code
private inline fun <T, R> Iterable<T>.fold2(initial: R, operation: (acc: R, T) -> R?): R? =
    fold<T, R?>(initial) { acc, element -> operation(acc ?: return null, element) }