distinctBy
inline fun <T, K> Array<out T>.distinctBy(
selector: (T) -> K
): List<T>
inline fun <K> ShortArray.distinctBy(
selector: (Short) -> K
): List<Short>
inline fun <K> FloatArray.distinctBy(
selector: (Float) -> K
): List<Float>
inline fun <K> DoubleArray.distinctBy(
selector: (Double) -> K
): List<Double>
inline fun <K> BooleanArray.distinctBy(
selector: (Boolean) -> K
): List<Boolean>
Returns a list containing only elements from the given array having distinct keys returned by the given selector function.
The elements in the resulting list are in the same order as they were in the source array.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
println(list.distinct()) // [a, A, b, B]
println(list.distinctBy { it.toUpperCase() }) // [a, b]
//sampleEnd
}
Returns a list containing only elements from the given collection having distinct keys returned by the given selector function.
The elements in the resulting list are in the same order as they were in the source collection.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
println(list.distinct()) // [a, A, b, B]
println(list.distinctBy { it.toUpperCase() }) // [a, b]
//sampleEnd
}