Decorate-sort-undecorate idiom: Difference between revisions

Content added Content deleted
Line 596: Line 596:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Kotlin already has a `sortedWith` function that takes a custom comparator, so there is no need to write such a function; however, one is shown here as a code example.
Kotlin already has a `sortedBy` function that can sort using a key extractor directly, so there is no need to decorate/undecorate. Nevertheless, the code example below shows how to decorate, sort and undecorate.

<syntaxhighlight lang="kotlin">
<syntaxhighlight lang="kotlin">
fun main() {
fun main() {