https://kotlinlang.org logo
#stdlib
Title
# stdlib
n

nkiesel

07/17/2020, 8:07 PM
Should there be standard support to sort lists of Strings locale-dependant? Something like
fun Iterable<String>.sortedWith(collator: Collator) = this.map { collator.getCollationKey(it) }.sorted().map { it.sourceString }
i

ilya.gorbunov

07/17/2020, 10:36 PM
Since
Collator
implements
Comparator
, why not just standard
list.sortWith(collator)
? Is it an optimization for large lists?
n

nkiesel

07/19/2020, 6:07 AM
Yes, collator documentation says that for sorting lists where items must be compared multiple times, converting to CollationKey is more efficient. Caveat: I did not measure what the break-even point for this is.
6 Views