January 2018
Intermediate to advanced
434 pages
14h 1m
English
We have used the sortedWith function, which takes in a comparator. The comparator is provided by the compareBy function. The compareBy has an overload that takes multiple functions:
public fun <T> compareBy(vararg selectors: (T) -> Comparable<*>?):Comparator<T>
As you can see in the preceding code, vararg allows us to take multiple functions in its construct and returns a comparator, which feeds the sortedWith function.
Note that sorting with multiple fields works like sort by field 1, then by field 2, then by field 3, and so on.
Read now
Unlock full access