Make Comparator fun interface in Common and JS
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user