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:
@@ -135,6 +135,18 @@ class CollectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldWithDifferentTypes() {
|
||||
expect(7) {
|
||||
val numbers = arrayList("a", "ab", "abc")
|
||||
numbers.fold(1){ a, b -> a + b.size}
|
||||
}
|
||||
|
||||
expect("1234") {
|
||||
val numbers = arrayList(1, 2, 3, 4)
|
||||
numbers.fold(""){ a, b -> a + b}
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldWithNonCommutativeOperation() {
|
||||
expect(1) {
|
||||
val numbers = arrayList(1, 2, 3)
|
||||
@@ -149,6 +161,13 @@ class CollectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldRightWithDifferentTypes() {
|
||||
expect("1234") {
|
||||
val numbers = arrayList(1, 2, 3, 4)
|
||||
numbers.foldRight(""){ a, b -> "" + a + b}
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldRightWithNonCommutativeOperation() {
|
||||
expect(-5) {
|
||||
val numbers = arrayList(1, 2, 3)
|
||||
|
||||
Reference in New Issue
Block a user