Provide unzip method for Iterables, Arrays and Sequences of pairs.

#KT-5793 Fixed
This commit is contained in:
Ilya Gorbunov
2015-07-14 16:23:32 +03:00
parent f604eef2fe
commit da3ec891d0
3 changed files with 65 additions and 2 deletions
@@ -621,6 +621,19 @@ class CollectionTest {
assertEquals(e, 5)
}
test fun unzipList() {
val list = listOf(1 to 'a', 2 to 'b', 3 to 'c')
val (ints, chars) = list.unzip()
assertEquals(listOf(1, 2, 3), ints)
assertEquals(listOf('a', 'b', 'c'), chars)
}
test fun unzipArray() {
val array = arrayOf(1 to 'a', 2 to 'b', 3 to 'c')
val (ints, chars) = array.unzip()
assertEquals(listOf(1, 2, 3), ints)
assertEquals(listOf('a', 'b', 'c'), chars)
}
test fun specialLists() {
compare(arrayListOf<Int>(), listOf<Int>()) { listBehavior() }