January 2018
Intermediate to advanced
434 pages
14h 1m
English
The sortedByDescending works a bit like sortedBy. Internally, both use the sortedWith function:
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T> { return sortedWith(compareByDescending(selector))}
The following is the implementation of compareByDescending:
@kotlin.internal.InlineOnlypublic inline fun <T> compareByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T> = Comparator { a, b -> compareValuesBy(b, a, selector) }
Note that just the order of variables is reversed to produce the descending order.
Read now
Unlock full access