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
@@ -73,6 +73,13 @@ public class StreamTest {
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(3).drop(4).joinToString(limit = 10))
}
test
fun merge() {
expect(listOf("ab", "bc", "cd")) {
streamOf("a", "b", "c").merge(streamOf("b", "c", "d")) { a, b -> a + b }.toList()
}
}
test fun toStringJoinsNoMoreThanTheFirstTenElements() {
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().joinToString(limit = 10))
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.joinToString(limit = 10))