kotlin.comparisons.compareBy

compareBy

fun <T> compareBy(
    vararg selectors: (T) -> Comparable<*>?
): Comparator<T>

Creates a comparator using the sequence of functions to calculate a result of comparison. The functions are called sequentially, receive the given values a and b and return Comparable objects. As soon as the Comparable instances returned by a function for a and b values do not compare as equal, the result of that comparison is returned from the Comparator.

inline fun <T> compareBy(
    crossinline selector: (T) -> Comparable<*>?
): Comparator<T>

Creates a comparator using the function to transform value to a Comparable instance for comparison.

inline fun <T, K> compareBy(
    comparator: Comparator<in K>, 
    crossinline selector: (T) -> K
): Comparator<T>

Platform and version requirements: JVM

inline fun <T, K> compareBy(
    comparator: Comparator<in K>, 
    crossinline selector: (T) -> K
): Comparator<T>

Platform and version requirements: JS

Creates a comparator using the selector function to transform values being compared and then applying the specified comparator to compare transformed values.

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.comparisons/compare-by.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部