Fix foldRight implementation for iterables
This commit is contained in:
@@ -195,13 +195,27 @@ class CollectionTest {
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldWithNonCommutativeOperation() {
|
||||
expect(1) {
|
||||
val numbers = arrayList(1, 2, 3)
|
||||
numbers.fold(7) {a, b -> a - b}
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldRight() {
|
||||
expect("4321") {
|
||||
expect("1234") {
|
||||
val numbers = arrayList(1, 2, 3, 4)
|
||||
numbers.map<Int, String>{it.toString()}.foldRight(""){ a, b -> a + b}
|
||||
}
|
||||
}
|
||||
|
||||
test fun foldRightWithNonCommutativeOperation() {
|
||||
expect(-5) {
|
||||
val numbers = arrayList(1, 2, 3)
|
||||
numbers.foldRight(7) {a, b -> a - b}
|
||||
}
|
||||
}
|
||||
|
||||
test fun groupBy() {
|
||||
val words = arrayList("a", "ab", "abc", "def", "abcd")
|
||||
val byLength = words.groupBy{ it.length }
|
||||
|
||||
Reference in New Issue
Block a user