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:
James Strachan
2012-09-21 16:31:04 +01:00
parent e129b43a7c
commit be44702145
12 changed files with 41 additions and 22 deletions
+19
View File
@@ -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)