Provide distinctBy(keySelector) method for collections and sequences.

Implement distinct() and toMutableSet() for sequences.
Breaking change: distinct() now returns List instead of Set.

#KT-5834 Fixed
#KT-6063 Fixed
This commit is contained in:
Ilya Gorbunov
2015-04-27 16:36:53 +03:00
parent 46d91b2606
commit 6a3cb0eff8
5 changed files with 344 additions and 39 deletions
@@ -262,6 +262,16 @@ public class SequenceTest {
assertEquals(listOf(0, 1, 0, 1, 2), data.flatten().toList())
}
test fun distinct() {
val sequence = fibonacci().dropWhile { it < 10 }.take(20)
assertEquals(listOf(1, 2, 3, 0), sequence.map { it % 4 }.distinct().toList())
}
test fun distinctBy() {
val sequence = fibonacci().dropWhile { it < 10 }.take(20)
assertEquals(listOf(13, 34, 55, 144), sequence.distinctBy { it % 4 }.toList())
}
/*
test fun pairIterator() {