Sam
01/20/2023, 11:42 AMfold, but the operation is allowed to return null, in which case the whole thing exits early with a null return value.
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) }