All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.io.github.lyxnx.util.collection.Collections.kt Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
@file:JvmName("CollectionsJvmKt")

package io.github.lyxnx.util

import java.text.Collator
import java.util.Locale

/**
 * Returns all elements sorted by the given [selector] in the order defined by the given [locale], using the [default][Locale.getDefault]
 * if null
 *
 * Eg: `a < ą < b`
 */
@JvmSynthetic
public inline fun  Iterable.sortedByLocaleAware(
    locale: Locale? = null,
    crossinline selector: (T) -> String
): List {
    val c = Collator.getInstance(locale ?: Locale.getDefault())
    return sortedWith { s1, s2 ->
        c.compare(selector(s1), selector(s2))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy