From a3056bea1a5682e1bc3ba405350fe04c7e249533 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 27 Aug 2015 21:31:38 +0300 Subject: [PATCH] Accept in-projection of Comparator as a parameter. --- libraries/stdlib/src/kotlin/util/Ordering.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/stdlib/src/kotlin/util/Ordering.kt b/libraries/stdlib/src/kotlin/util/Ordering.kt index 1eb2443cca1..a3fac9a4cbe 100644 --- a/libraries/stdlib/src/kotlin/util/Ordering.kt +++ b/libraries/stdlib/src/kotlin/util/Ordering.kt @@ -73,7 +73,7 @@ public inline fun compareValuesBy(a: T, b: T, selector: (T) -> Comparable<*> * The function is applied to the given values [a] and [b] and return objects of type K which are then being * compared with the given [comparator]. */ -public inline fun compareValuesBy(a: T, b: T, comparator: Comparator, selector: (T) -> K): Int { +public inline fun compareValuesBy(a: T, b: T, comparator: Comparator, selector: (T) -> K): Int { return comparator.compare(selector(a), selector(b)) } @@ -129,7 +129,7 @@ inline public fun compareBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) se * Creates a comparator using the [selector] function to transform values being compared and then applying * the specified [comparator] to compare transformed values. */ -inline public fun compareBy(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { +inline public fun compareBy(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, comparator, selector) } @@ -150,7 +150,7 @@ inline public fun compareByDescending(inlineOptions(InlineOption.ONLY_LOCAL_ * * Note that an order of [comparator] is reversed by this wrapper. */ -inline public fun compareByDescending(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { +inline public fun compareByDescending(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, comparator, selector) } @@ -173,7 +173,7 @@ inline public fun Comparator.thenBy(inlineOptions(InlineOption.ONLY_LOCAL * Creates a comparator comparing values after the primary comparator defined them equal. It uses * the [selector] function to transform values and then compares them with the given [comparator]. */ -inline public fun Comparator.thenBy(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { +inline public fun Comparator.thenBy(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { val previousCompare = this@thenBy.compare(a, b) @@ -199,7 +199,7 @@ inline public fun Comparator.thenByDescending(inlineOptions(InlineOption. * Creates a descending comparator comparing values after the primary comparator defined them equal. It uses * the [selector] function to transform values and then compares them with the given [comparator]. */ -inline public fun Comparator.thenByDescending(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { +inline public fun Comparator.thenByDescending(comparator: Comparator, inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> K): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { val previousCompare = this@thenByDescending.compare(a, b) @@ -234,7 +234,7 @@ inline public fun Comparator.thenComparator(inlineOptions(InlineOption.ON * Combines this comparator and the given [comparator] such that the latter is applied only * when the former considered values equal. */ -public fun Comparator.then(comparator: Comparator): Comparator { +public fun Comparator.then(comparator: Comparator): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { val previousCompare = this@then.compare(a, b) @@ -247,7 +247,7 @@ public fun Comparator.then(comparator: Comparator): Comparator { * Combines this comparator and the given [comparator] such that the latter is applied only * when the former considered values equal. */ -public fun Comparator.thenDescending(comparator: Comparator): Comparator { +public fun Comparator.thenDescending(comparator: Comparator): Comparator { return object : Comparator { public override fun compare(a: T, b: T): Int { val previousCompare = this@thenDescending.compare(a, b) @@ -261,7 +261,7 @@ public fun Comparator.thenDescending(comparator: Comparator): Comparat * Extends the given [comparator] of non-nullable values to a comparator of nullable values * considering `null` value less than any other value. */ -public fun nullsFirst(comparator: Comparator): Comparator { +public fun nullsFirst(comparator: Comparator): Comparator { return object: Comparator { override fun compare(a: T?, b: T?): Int { if (a === b) return 0 @@ -291,7 +291,7 @@ public fun > nullsFirst(): Comparator { * Extends the given [comparator] of non-nullable values to a comparator of nullable values * considering `null` value greater than any other value. */ -public fun nullsLast(comparator: Comparator): Comparator { +public fun nullsLast(comparator: Comparator): Comparator { return object: Comparator { override fun compare(a: T?, b: T?): Int { if (a === b) return 0