Decorate-sort-undecorate idiom: Difference between revisions
→{{header|Kotlin}}
Line 596:
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">
fun main() {
val list = listOf("Rosetta", "Code", "is", "a", "programming", "chrestomathy", "site")
println
}
/**
fun <T, C: Comparable<C>> sorted(list: Collection<T>, keyFn: (T) -> C): List<T> =▼
* Returns a sorted list using the Schwartzian Transform which guarantees minimal use of the
* key extractor function. Use when the key extractor function is an expensive operation.
.map { it to keyFn(it) }▼
*/
▲fun <T,
.sortedBy { it.second }
.map { it.first }
|