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
@@ -5,8 +5,13 @@ import org.junit.Test as test
class SetOperationsTest {
test fun distinct() {
assertEquals(listOf(1, 3, 5), listOf(1, 3, 3, 1, 5, 1, 3).distinct().toList())
assertTrue(listOf<Int>().distinct().none())
assertEquals(listOf(1, 3, 5), listOf(1, 3, 3, 1, 5, 1, 3).distinct())
assertTrue(listOf<Int>().distinct().isEmpty())
}
test fun distinctBy() {
assertEquals(listOf("some", "cat", "do"), arrayOf("some", "case", "cat", "do", "dog", "it").distinctBy { it.length() })
assertTrue(charArrayOf().distinctBy { it }.isEmpty())
}
test fun union() {