fixes KT-2091 allowing fold() and foldRight() to take different types of initial value and return the same typed result
This commit is contained in:
@@ -142,7 +142,7 @@ public inline fun <T> Iterable<T>.forEach(operation: (T) -> Unit) : Unit = for (
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
|
||||
public inline fun <T,R> Iterable<T>.fold(initial: R, operation: (R, T) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -153,7 +153,7 @@ public inline fun <T> Iterable<T>.fold(initial: T, operation: (T, T) -> T): T {
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <T,R> Iterable<T>.foldRight(initial: R, operation: (T, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user