allDistinctBy

inline fun <T, K> Sequence<T>.allDistinctBy(selector: (T) -> K): Boolean(source)

Returns true if all values produced by applying the given selector function to the elements in the sequence are distinct from each other.

Returns true for an empty sequence.

The selector values are compared using structural equality (==). The operation returns false as soon as a duplicate selector value is found.

For selector values of floating-point types (Double, Float), NaN is considered equal to NaN, and -0.0 is considered not equal to 0.0, consistent with Double.equals and Float.equals.

The operation is terminal.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(sequenceOf<String>().allDistinctBy { it.length }) // true
println(sequenceOf("apple").allDistinctBy { it.length }) // true

println(sequenceOf("apple", "mango", "peach").allDistinctBy { it.length }) // false
println(sequenceOf("apple", "mango", "peach").allDistinctBy { it }) // true 
   //sampleEnd
}