allDistinctBy

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

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


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

val values = arrayOf("apple", "mango", "peach")
println(values.allDistinctBy { it.length }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(byteArrayOf().allDistinctBy { it * it }) // true
println(byteArrayOf(1).allDistinctBy { it * it }) // true

val values = byteArrayOf(1, -1, 2)
println(values.allDistinctBy { it * it }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(shortArrayOf().allDistinctBy { it * it }) // true
println(shortArrayOf(1).allDistinctBy { it * it }) // true

val values = shortArrayOf(1, -1, 2)
println(values.allDistinctBy { it * it }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(intArrayOf().allDistinctBy { it * it }) // true
println(intArrayOf(1).allDistinctBy { it * it }) // true

val values = intArrayOf(1, -1, 2)
println(values.allDistinctBy { it * it }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(longArrayOf().allDistinctBy { it * it }) // true
println(longArrayOf(1L).allDistinctBy { it * it }) // true

val values = longArrayOf(1L, -1L, 2L)
println(values.allDistinctBy { it * it }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(floatArrayOf().allDistinctBy { it * it }) // true
println(floatArrayOf(1.0f).allDistinctBy { it * it }) // true

val values = floatArrayOf(1.0f, -1.0f, 2.0f)
println(values.allDistinctBy { it * it }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(doubleArrayOf().allDistinctBy { it * it }) // true
println(doubleArrayOf(1.0).allDistinctBy { it * it }) // true

val values = doubleArrayOf(1.0, -1.0, 2.0)
println(values.allDistinctBy { it * it }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(booleanArrayOf().allDistinctBy { if (it) 1 else 0 }) // true
println(booleanArrayOf(true).allDistinctBy { if (it) 1 else 0 }) // true

val values = booleanArrayOf(true, false)
println(values.allDistinctBy { if (it) 1 else 0 }) // true
println(values.allDistinctBy { 0 }) // false 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(charArrayOf().allDistinctBy { it.uppercaseChar() }) // true
println(charArrayOf('a').allDistinctBy { it.uppercaseChar() }) // true

val values = charArrayOf('a', 'A', 'b')
println(values.allDistinctBy { it.uppercaseChar() }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

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

Returns true for an empty collection.

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.

Since Kotlin

2.4

Samples


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

val values = listOf("apple", "mango", "peach")
println(values.allDistinctBy { it.length }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(uintArrayOf().allDistinctBy { it % 2u }) // true
println(uintArrayOf(1u).allDistinctBy { it % 2u }) // true

val values = uintArrayOf(1u, 3u, 2u)
println(values.allDistinctBy { it % 2u }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(ulongArrayOf().allDistinctBy { it % 2uL }) // true
println(ulongArrayOf(1uL).allDistinctBy { it % 2uL }) // true

val values = ulongArrayOf(1uL, 3uL, 2uL)
println(values.allDistinctBy { it % 2uL }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(ubyteArrayOf().allDistinctBy { it.toUInt() % 2u }) // true
println(ubyteArrayOf(1u).allDistinctBy { it.toUInt() % 2u }) // true

val values = ubyteArrayOf(1u, 3u, 2u)
println(values.allDistinctBy { it.toUInt() % 2u }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}

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

Returns true for an empty array.

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.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(ushortArrayOf().allDistinctBy { it.toUInt() % 2u }) // true
println(ushortArrayOf(1u).allDistinctBy { it.toUInt() % 2u }) // true

val values = ushortArrayOf(1u, 3u, 2u)
println(values.allDistinctBy { it.toUInt() % 2u }) // false
println(values.allDistinctBy { it }) // true 
   //sampleEnd
}