fix Iterable<T>.toSortedList

This commit is contained in:
Erokhin Stanislav
2013-05-30 17:09:31 +04:00
parent aa1998fa20
commit 0514ddc719
2 changed files with 11 additions and 1 deletions
@@ -75,3 +75,13 @@ public inline fun <T> Iterable<T>.sort(comparator: java.util.Comparator<T>) : Li
java.util.Collections.sort(list, comparator)
return list
}
public inline fun <T> Iterable<T>.sort(compare: (T, T) -> Int): List<T> {
return sort(
object : java.util.Comparator<T> {
public override fun compare(o1: T, o2: T): Int {
return compare.invoke(o1, o2)
}
}
)
}
+1 -1
View File
@@ -27,7 +27,7 @@ public inline fun <T> Collection<T>?.orEmpty() : Collection<T>
/** TODO these functions don't work when they generate the Array<T> versions when they are in JLIterables */
public inline fun <T: Comparable<T>> Iterable<T>.toSortedList() : List<T> = toCollection(ArrayList<T>()).sort()
public inline fun <T: Comparable<T>> Iterable<T>.toSortedList(comparator: java.util.Comparator<T>) : List<T> = toList().sort(comparator)
public inline fun <T> Iterable<T>.toSortedList(compare: (T, T) -> Int) : List<T> = toList().sort(compare)
// List APIs