From 135025ff8d1078431f61800521970b909db21e03 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 27 Feb 2017 14:35:02 +0300 Subject: [PATCH] stdlib: Add Comparator((T, T) -> Int) function --- runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt b/runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt index d0144d9e2ec..ca60cf17cbc 100644 --- a/runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt +++ b/runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt @@ -4,6 +4,11 @@ interface Comparator { fun compare(a: T, b: T): Int } +fun Comparator(function: (a: T, b: T) -> Int): Comparator { + return object: Comparator { + 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]