stdlib: Add Comparator((T, T) -> Int) function

This commit is contained in:
Ilya Matveev
2017-02-27 14:35:02 +03:00
committed by ilmat192
parent 1cbfa73f67
commit 135025ff8d
@@ -4,6 +4,11 @@ interface Comparator<T> {
fun compare(a: T, b: T): Int
}
fun <T> Comparator(function: (a: T, b: T) -> Int): Comparator<T> {
return object: Comparator<T> {
override fun compare(a: T, b: T) = function(a, b)
}
}
/**
* Compares two values using the specified functions [selectors] to calculate the result of the comparison.
* The functions are called sequentially, receive the given values [a] and [b] and return [Comparable]