diff --git a/libraries/stdlib/src/kotlin/util/Ordering.kt b/libraries/stdlib/src/kotlin/util/Ordering.kt index d43432e0b1f..249bdd97a78 100644 --- a/libraries/stdlib/src/kotlin/util/Ordering.kt +++ b/libraries/stdlib/src/kotlin/util/Ordering.kt @@ -252,16 +252,7 @@ public fun nullsFirst(comparator: Comparator): Comparator { * Provides a comparator of nullable [Comparable] values * considering `null` value less than any other value. */ -public fun > nullsFirst(): Comparator { - return object: Comparator { - override fun compare(a: T?, b: T?): Int { - if (a === b) return 0 - if (a == null) return -1 - if (b == null) return 1 - return a.compareTo(b) - } - } -} +public fun > nullsFirst(): Comparator = nullsFirst(naturalOrder()) /** * Extends the given [comparator] of non-nullable values to a comparator of nullable values @@ -282,16 +273,7 @@ public fun nullsLast(comparator: Comparator): Comparator { * Provides a comparator of nullable [Comparable] values * considering `null` value greater than any other value. */ -public fun > nullsLast(): Comparator { - return object: Comparator { - override fun compare(a: T?, b: T?): Int { - if (a === b) return 0 - if (a == null) return 1 - if (b == null) return -1 - return a.compareTo(b) - } - } -} +public fun > nullsLast(): Comparator = nullsLast(naturalOrder()) /** * Returns a comparator that compares [Comparable] objects in natural order.