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:
@@ -151,7 +151,7 @@ public inline fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit = for (ele
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun <T> Array<T>.fold(initial: T, operation: (T, T) -> T): T {
|
||||
public inline fun <T,R> Array<T>.fold(initial: R, operation: (R, T) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun <T> Array<T>.fold(initial: T, operation: (T, T) -> T): T {
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun <T> Array<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <T,R> Array<T>.foldRight(initial: R, operation: (T, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun BooleanArray.forEach(operation: (Boolean) -> Unit) : Unit = fo
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun BooleanArray.fold(initial: Boolean, operation: (Boolean, Boolean) -> Boolean): Boolean {
|
||||
public inline fun <R> BooleanArray.fold(initial: R, operation: (R, Boolean) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun BooleanArray.fold(initial: Boolean, operation: (Boolean, Boole
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun BooleanArray.foldRight(initial: Boolean, operation: (Boolean, Boolean) -> Boolean): Boolean = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> BooleanArray.foldRight(initial: R, operation: (Boolean, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun ByteArray.forEach(operation: (Byte) -> Unit) : Unit = for (ele
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun ByteArray.fold(initial: Byte, operation: (Byte, Byte) -> Byte): Byte {
|
||||
public inline fun <R> ByteArray.fold(initial: R, operation: (R, Byte) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun ByteArray.fold(initial: Byte, operation: (Byte, Byte) -> Byte)
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun ByteArray.foldRight(initial: Byte, operation: (Byte, Byte) -> Byte): Byte = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> ByteArray.foldRight(initial: R, operation: (Byte, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun CharArray.forEach(operation: (Char) -> Unit) : Unit = for (ele
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun CharArray.fold(initial: Char, operation: (Char, Char) -> Char): Char {
|
||||
public inline fun <R> CharArray.fold(initial: R, operation: (R, Char) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun CharArray.fold(initial: Char, operation: (Char, Char) -> Char)
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun CharArray.foldRight(initial: Char, operation: (Char, Char) -> Char): Char = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> CharArray.foldRight(initial: R, operation: (Char, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun DoubleArray.forEach(operation: (Double) -> Unit) : Unit = for
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun DoubleArray.fold(initial: Double, operation: (Double, Double) -> Double): Double {
|
||||
public inline fun <R> DoubleArray.fold(initial: R, operation: (R, Double) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun DoubleArray.fold(initial: Double, operation: (Double, Double)
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun DoubleArray.foldRight(initial: Double, operation: (Double, Double) -> Double): Double = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> DoubleArray.foldRight(initial: R, operation: (Double, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun FloatArray.forEach(operation: (Float) -> Unit) : Unit = for (e
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun FloatArray.fold(initial: Float, operation: (Float, Float) -> Float): Float {
|
||||
public inline fun <R> FloatArray.fold(initial: R, operation: (R, Float) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun FloatArray.fold(initial: Float, operation: (Float, Float) -> F
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun FloatArray.foldRight(initial: Float, operation: (Float, Float) -> Float): Float = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> FloatArray.foldRight(initial: R, operation: (Float, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun IntArray.forEach(operation: (Int) -> Unit) : Unit = for (eleme
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun IntArray.fold(initial: Int, operation: (Int, Int) -> Int): Int {
|
||||
public inline fun <R> IntArray.fold(initial: R, operation: (R, Int) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun IntArray.fold(initial: Int, operation: (Int, Int) -> Int): Int
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun IntArray.foldRight(initial: Int, operation: (Int, Int) -> Int): Int = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> IntArray.foldRight(initial: R, operation: (Int, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -150,7 +150,7 @@ public inline fun <T> Iterator<T>.forEach(operation: (T) -> Unit) : Unit = for (
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.fold(initial: T, operation: (T, T) -> T): T {
|
||||
public inline fun <T,R> Iterator<T>.fold(initial: R, operation: (R, T) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -161,7 +161,7 @@ public inline fun <T> Iterator<T>.fold(initial: T, operation: (T, T) -> T): T {
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun <T> Iterator<T>.foldRight(initial: T, operation: (T, T) -> T): T = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <T,R> Iterator<T>.foldRight(initial: R, operation: (T, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun LongArray.forEach(operation: (Long) -> Unit) : Unit = for (ele
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun LongArray.fold(initial: Long, operation: (Long, Long) -> Long): Long {
|
||||
public inline fun <R> LongArray.fold(initial: R, operation: (R, Long) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun LongArray.fold(initial: Long, operation: (Long, Long) -> Long)
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun LongArray.foldRight(initial: Long, operation: (Long, Long) -> Long): Long = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> LongArray.foldRight(initial: R, operation: (Long, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,7 @@ public inline fun ShortArray.forEach(operation: (Short) -> Unit) : Unit = for (e
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt fold
|
||||
*/
|
||||
public inline fun ShortArray.fold(initial: Short, operation: (Short, Short) -> Short): Short {
|
||||
public inline fun <R> ShortArray.fold(initial: R, operation: (R, Short) -> R): R {
|
||||
var answer = initial
|
||||
for (element in this) answer = operation(answer, element)
|
||||
return answer
|
||||
@@ -162,7 +162,7 @@ public inline fun ShortArray.fold(initial: Short, operation: (Short, Short) -> S
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt foldRight
|
||||
*/
|
||||
public inline fun ShortArray.foldRight(initial: Short, operation: (Short, Short) -> Short): Short = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
public inline fun <R> ShortArray.foldRight(initial: R, operation: (Short, R) -> R): R = reverse().fold(initial, {x, y -> operation(y, x)})
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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