Make Comparator fun interface in Common and JS
This commit is contained in:
@@ -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<kotlin.Throwable> { get; }
|
||||
|
||||
public inline fun <T> Comparator(crossinline comparison: (a: T, b: T) -> kotlin.Int): kotlin.Comparator<T>
|
||||
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun TODO(): kotlin.Nothing
|
||||
|
||||
@@ -1023,7 +1021,7 @@ public interface Comparable<in T> {
|
||||
public abstract operator fun compareTo(other: T): kotlin.Int
|
||||
}
|
||||
|
||||
public interface Comparator<T> {
|
||||
public fun interface Comparator<T> {
|
||||
@kotlin.js.JsName(name = "compare")
|
||||
public abstract fun compare(a: T, b: T): kotlin.Int
|
||||
}
|
||||
|
||||
@@ -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<kotlin.Throwable> { get; }
|
||||
|
||||
public inline fun <T> Comparator(crossinline comparison: (a: T, b: T) -> kotlin.Int): kotlin.Comparator<T>
|
||||
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun TODO(): kotlin.Nothing
|
||||
|
||||
@@ -995,7 +993,7 @@ public interface Comparable<in T> {
|
||||
public abstract operator fun compareTo(other: T): kotlin.Int
|
||||
}
|
||||
|
||||
public interface Comparator<T> {
|
||||
public fun interface Comparator<T> {
|
||||
@kotlin.js.JsName(name = "compare")
|
||||
public abstract fun compare(a: T, b: T): kotlin.Int
|
||||
}
|
||||
|
||||
@@ -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<T> {
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
@@ -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<T> {
|
||||
/**
|
||||
* 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 <T> Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T>
|
||||
|
||||
// From kotlin.kt
|
||||
|
||||
|
||||
|
||||
// From numbers.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<T> {
|
||||
public actual fun interface Comparator<T> {
|
||||
@JsName("compare")
|
||||
actual fun compare(a: T, b: T): Int
|
||||
}
|
||||
|
||||
public actual inline fun <T> Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator<T> = object : Comparator<T> {
|
||||
override fun compare(a: T, b: T): Int = comparison(a, b)
|
||||
public actual fun compare(a: T, b: T): Int
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user