isSortedByDescending

inline fun <T, R : Comparable<R>> Array<out T>.isSortedByDescending(selector: (T) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


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

val values = arrayOf("aaa", "bb", "c")
println(values.isSortedByDescending { it.length }) // true
println(values.isSortedByDescending { it }) // false
println(arrayOf("b", "a").isSortedByDescending { if (it == "a") null else it }) // true
println(arrayOf("aaa", "bb", null).isSortedByDescending { it?.length }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> ByteArray.isSortedByDescending(selector: (Byte) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(byteArrayOf().isSortedByDescending { it * it }) // true
println(byteArrayOf(5).isSortedByDescending { it * it }) // true

val values = byteArrayOf(5, -4, 3, -2, 1)
println(values.isSortedByDescending { it * it }) // true
println(values.isSortedByDescending { abs(it.toInt()) }) // true
println(values.isSortedByDescending { it }) // false
println(byteArrayOf(2, 1).isSortedByDescending { if (it.toInt() == 1) null else it }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> ShortArray.isSortedByDescending(selector: (Short) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(shortArrayOf().isSortedByDescending { it * it }) // true
println(shortArrayOf(5).isSortedByDescending { it * it }) // true

val values = shortArrayOf(5, -4, 3, -2, 1)
println(values.isSortedByDescending { it * it }) // true
println(values.isSortedByDescending { abs(it.toInt()) }) // true
println(values.isSortedByDescending { it }) // false
println(shortArrayOf(2, 1).isSortedByDescending { if (it.toInt() == 1) null else it }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> IntArray.isSortedByDescending(selector: (Int) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(intArrayOf().isSortedByDescending { it * it }) // true
println(intArrayOf(5).isSortedByDescending { it * it }) // true

val values = intArrayOf(5, -4, 3, -2, 1)
println(values.isSortedByDescending { it * it }) // true
println(values.isSortedByDescending { abs(it) }) // true
println(values.isSortedByDescending { it }) // false
println(intArrayOf(2, 1).isSortedByDescending { if (it == 1) null else it }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> LongArray.isSortedByDescending(selector: (Long) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(longArrayOf().isSortedByDescending { it * it }) // true
println(longArrayOf(5L).isSortedByDescending { it * it }) // true

val values = longArrayOf(5L, -4L, 3L, -2L, 1L)
println(values.isSortedByDescending { it * it }) // true
println(values.isSortedByDescending { abs(it) }) // true
println(values.isSortedByDescending { it }) // false
println(longArrayOf(2L, 1L).isSortedByDescending { if (it == 1L) null else it }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> FloatArray.isSortedByDescending(selector: (Float) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(floatArrayOf().isSortedByDescending { it * it }) // true
println(floatArrayOf(2.0f).isSortedByDescending { it * it }) // true

val values = floatArrayOf(2.0f, -1.5f, 1.0f, -0.5f)
println(values.isSortedByDescending { it * it }) // true
println(values.isSortedByDescending { abs(it) }) // true
println(values.isSortedByDescending { it }) // false
println(floatArrayOf(2.5f, 1.0f).isSortedByDescending { if (it == 1.0f) null else it }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> DoubleArray.isSortedByDescending(selector: (Double) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(doubleArrayOf().isSortedByDescending { it * it }) // true
println(doubleArrayOf(2.0).isSortedByDescending { it * it }) // true

val values = doubleArrayOf(2.0, -1.5, 1.0, -0.5)
println(values.isSortedByDescending { it * it }) // true
println(values.isSortedByDescending { abs(it) }) // true
println(values.isSortedByDescending { it }) // false
println(doubleArrayOf(2.5, 1.0).isSortedByDescending { if (it == 1.0) null else it }) // true 
   //sampleEnd
}

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(booleanArrayOf().isSortedByDescending { it.compareTo(false) }) // true
println(booleanArrayOf(true).isSortedByDescending { it.compareTo(false) }) // true

val values = booleanArrayOf(true, false, false)
println(values.isSortedByDescending { it.compareTo(false) }) // true
println(values.isSortedByDescending { it }) // true
println(values.isSortedByDescending { !it }) // false
println(booleanArrayOf(true, false).isSortedByDescending { if (it == false) null else it }) // true 
   //sampleEnd
}

inline fun <R : Comparable<R>> CharArray.isSortedByDescending(selector: (Char) -> R?): Boolean(source)

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(charArrayOf().isSortedByDescending { it.uppercaseChar() }) // true
println(charArrayOf('C').isSortedByDescending { it.uppercaseChar() }) // true

val values = charArrayOf('C', 'b', 'A')
println(values.isSortedByDescending { it.uppercaseChar() }) // true
println(values.isSortedByDescending { it.lowercaseChar() }) // true
println(values.isSortedByDescending { it }) // false
println(charArrayOf('b', 'a').isSortedByDescending { if (it == 'a') null else it }) // true 
   //sampleEnd
}

inline fun <T, R : Comparable<R>> Iterable<T>.isSortedByDescending(selector: (T) -> R?): Boolean(source)

Returns true if each element in the collection yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the collection has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the collection is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Note that the result depends on the iteration order of the collection. The iteration order of some Iterable implementations may be unstable (change from one invocation to the next), in which case this function may return inconsistent results.

Since Kotlin

2.4

Samples


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

val values = listOf("aaa", "bb", "c")
println(values.isSortedByDescending { it.length }) // true
println(values.isSortedByDescending { it }) // false
println(listOf("b", "a").isSortedByDescending { if (it == "a") null else it }) // true
println(listOf("aaa", "bb", null).isSortedByDescending { it?.length }) // true 
   //sampleEnd
}

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


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

val values = uintArrayOf(2u, 4u, 1u, 3u)
println(values.isSortedByDescending { it % 3u }) // true
println(values.isSortedByDescending { it }) // false
println(uintArrayOf(2u, 1u).isSortedByDescending { if (it == 1u) null else it }) // true 
   //sampleEnd
}

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


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

val values = ulongArrayOf(2uL, 4uL, 1uL, 3uL)
println(values.isSortedByDescending { it % 3uL }) // true
println(values.isSortedByDescending { it }) // false
println(ulongArrayOf(2uL, 1uL).isSortedByDescending { if (it == 1uL) null else it }) // true 
   //sampleEnd
}

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


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

val values = ubyteArrayOf(2u, 4u, 1u, 3u)
println(values.isSortedByDescending { it.toUInt() % 3u }) // true
println(values.isSortedByDescending { it }) // false
println(ubyteArrayOf(2u, 1u).isSortedByDescending { if (it.toUInt() == 1u) null else it }) // true 
   //sampleEnd
}

Returns true if each element in the array yields a selector value that is greater than or equal to the selector value of the following element according to the natural sort order of the selector values.

Returns true if the array has fewer than two elements.

The selector values of adjacent elements are compared sequentially using compareValues, and the array is considered sorted in descending order if for each pair of adjacent elements the selector value of the preceding element is not less than that of the following one.

If the selector returns null for an element, the null value is treated as less than any non-null value.

Since Kotlin

2.4

Samples


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

val values = ushortArrayOf(2u, 4u, 1u, 3u)
println(values.isSortedByDescending { it.toUInt() % 3u }) // true
println(values.isSortedByDescending { it }) // false
println(ushortArrayOf(2u, 1u).isSortedByDescending { if (it.toUInt() == 1u) null else it }) // true 
   //sampleEnd
}