diff --git a/libraries/stdlib/api/js-v1/kotlin.kt b/libraries/stdlib/api/js-v1/kotlin.kt index f5a5811f8e5..d4694457b87 100644 --- a/libraries/stdlib/api/js-v1/kotlin.kt +++ b/libraries/stdlib/api/js-v1/kotlin.kt @@ -5,8 +5,6 @@ public val kotlin.reflect.KProperty0<*>.isInitialized: kotlin.Boolean { get; } @kotlin.SinceKotlin(version = "1.4") public val kotlin.Throwable.suppressedExceptions: kotlin.collections.List { get; } -public inline fun Comparator(crossinline comparison: (a: T, b: T) -> kotlin.Int): kotlin.Comparator - @kotlin.internal.InlineOnly public inline fun TODO(): kotlin.Nothing @@ -1023,7 +1021,7 @@ public interface Comparable { public abstract operator fun compareTo(other: T): kotlin.Int } -public interface Comparator { +public fun interface Comparator { @kotlin.js.JsName(name = "compare") public abstract fun compare(a: T, b: T): kotlin.Int } diff --git a/libraries/stdlib/api/js/kotlin.kt b/libraries/stdlib/api/js/kotlin.kt index 9f929c15df9..c043aeebf82 100644 --- a/libraries/stdlib/api/js/kotlin.kt +++ b/libraries/stdlib/api/js/kotlin.kt @@ -5,8 +5,6 @@ public val kotlin.reflect.KProperty0<*>.isInitialized: kotlin.Boolean { get; } @kotlin.SinceKotlin(version = "1.4") public val kotlin.Throwable.suppressedExceptions: kotlin.collections.List { get; } -public inline fun Comparator(crossinline comparison: (a: T, b: T) -> kotlin.Int): kotlin.Comparator - @kotlin.internal.InlineOnly public inline fun TODO(): kotlin.Nothing @@ -995,7 +993,7 @@ public interface Comparable { public abstract operator fun compareTo(other: T): kotlin.Int } -public interface Comparator { +public fun interface Comparator { @kotlin.js.JsName(name = "compare") public abstract fun compare(a: T, b: T): kotlin.Int } diff --git a/libraries/stdlib/common/src/kotlin/Comparator.kt b/libraries/stdlib/common/src/kotlin/Comparator.kt new file mode 100644 index 00000000000..6b4c935ee7f --- /dev/null +++ b/libraries/stdlib/common/src/kotlin/Comparator.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin + +/** + * Provides a comparison function for imposing a total ordering between instances of the type [T]. + */ +public expect fun interface Comparator { + /** + * Compares its two arguments for order. Returns zero if the arguments are equal, + * a negative number if the first argument is less than the second, or a positive number + * if the first argument is greater than the second. + */ + public fun compare(a: T, b: T): Int +} \ No newline at end of file diff --git a/libraries/stdlib/common/src/kotlin/KotlinH.kt b/libraries/stdlib/common/src/kotlin/KotlinH.kt index e6406f4dcd2..18da30e810c 100644 --- a/libraries/stdlib/common/src/kotlin/KotlinH.kt +++ b/libraries/stdlib/common/src/kotlin/KotlinH.kt @@ -1,43 +1,10 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package kotlin -import kotlin.annotation.AnnotationTarget.FIELD -import kotlin.annotation.AnnotationTarget.PROPERTY - - -/** - * Provides a comparison function for imposing a total ordering between instances of the type [T]. - */ -expect interface Comparator { - /** - * Compares its two arguments for order. Returns zero if the arguments are equal, - * a negative number if the first argument is less than the second, or a positive number - * if the first argument is greater than the second. - */ - fun compare(a: T, b: T): Int -} - -/** - * Creates a [Comparator] with the provided [comparison] function. - * - * @param comparison function that compares its two arguments for order. - * Must return zero if the arguments are equal, a negative number - * if the first argument is less than the second, or a positive number - * if the first argument is greater than the second. - * - * @return [Comparator] object with the provided implementation of the comparison function. - */ -// TODO: Satisfied with SAM-constructor for Comparator interface in JVM -@Suppress("NO_ACTUAL_FOR_EXPECT") -expect inline fun Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator - -// From kotlin.kt - - // From numbers.kt diff --git a/libraries/stdlib/js/src/kotlin/Comparator.kt b/libraries/stdlib/js/src/kotlin/Comparator.kt index d13b3d7ba00..01213f46a64 100644 --- a/libraries/stdlib/js/src/kotlin/Comparator.kt +++ b/libraries/stdlib/js/src/kotlin/Comparator.kt @@ -1,16 +1,12 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package kotlin -public actual interface Comparator { +public actual fun interface Comparator { @JsName("compare") - actual fun compare(a: T, b: T): Int -} - -public actual inline fun Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator = object : Comparator { - override fun compare(a: T, b: T): Int = comparison(a, b) + public actual fun compare(a: T, b: T): Int }