Generalize zip(..) to merge(..) { t1, t2 -> ... }, add merge for maps.
This commit is contained in:
committed by
Andrey Breslav
parent
f94b79fac3
commit
65da4cb2fb
@@ -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 }
|
||||
|
||||
@@ -53,7 +53,7 @@ class MapTest {
|
||||
assertEquals(map.size(), 1)
|
||||
assertEquals("James", map["name"])
|
||||
}
|
||||
|
||||
|
||||
test fun iterate() {
|
||||
val map = TreeMap<String, String>()
|
||||
map["beverage"] = "beer"
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user