Add sortBy method for interables

This commit is contained in:
Alexander Zolotov
2012-06-24 17:56:46 +04:00
parent 72ef07acef
commit 019962b654
2 changed files with 24 additions and 0 deletions
+11
View File
@@ -445,6 +445,17 @@ class CollectionTest {
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
}
test fun sortBy() {
expect(arrayList("two" to 2, "three" to 3)) {
arrayList("three" to 3, "two" to 2).sortBy { it._2 }
}
expect(arrayList("three" to 3, "two" to 2)) {
arrayList("three" to 3, "two" to 2).sortBy { it._1 }
}
expect(arrayList("two" to 2, "three" to 3)) {
arrayList("three" to 3, "two" to 2).sortBy { it._1.length }
}
}
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
private val collection = collection