Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

sorted

If elements in a List implements the Comparable interface, you can call the method sorted to return a sorted List (in nature order).

Note: Pair in Kotin does not implement the Comparable interface!!!

[2, 3, 5, 9]
[(5, 7), (5, 3), (1, 2), (2, 3), (1, 9)]
error: type parameter bound for T in fun <T : Comparable<T>> Iterable<T>.sorted(): List<T>
 is not satisfied: inferred type Pair<Int, Int> is not a subtype of Comparable<Pair<Int, Int>>
listPairs.sorted()
          ^

sortedBy

[(1, 2), (1, 9), (2, 3), (5, 7), (5, 3)]

sortedWith

[(1, 2), (1, 9), (2, 3), (5, 3), (5, 7)]