Generalize zip(..) to merge(..) { t1, t2 -> ... }, add merge for maps.

This commit is contained in:
Ilya Ryzhenkov
2014-06-09 14:23:35 +04:00
committed by Andrey Breslav
parent f94b79fac3
commit 65da4cb2fb
6 changed files with 413 additions and 176 deletions
@@ -120,6 +120,20 @@ class CollectionTest {
}
}
test
fun merge() {
expect(listOf("ab", "bc", "cd")) {
listOf("a", "b", "c").merge(listOf("b", "c", "d")) { a, b -> a + b }
}
}
test
fun zip() {
expect(listOf("a" to "b", "b" to "c", "c" to "d")) {
listOf("a", "b", "c").zip(listOf("b", "c", "d"))
}
}
test fun partition() {
val data = arrayListOf("foo", "bar", "something", "xyz")
val pair = data.partition { it.size == 3 }