isSortedByDescending
Returns true if each element in the sequence 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 sequence has fewer than two elements.
The selector values of adjacent elements are compared sequentially using compareValues, and the sequence 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 sequence. The iteration order of some Sequence implementations may be unstable (change from one invocation to the next), in which case this function may return inconsistent results.
The operation is terminal.
Since Kotlin
2.4Samples
fun main() {
//sampleStart
println(sequenceOf<String>().isSortedByDescending { it.length }) // true
println(sequenceOf("aaa").isSortedByDescending { it.length }) // true
println(sequenceOf("aaa", "bb", "c").isSortedByDescending { it.length }) // true
println(sequenceOf("aaa", "bb", "c").isSortedByDescending { it }) // false
println(sequenceOf("b", "a").isSortedByDescending { if (it == "a") null else it }) // true
println(sequenceOf("aaa", "bb", null).isSortedByDescending { it?.length }) // true
//sampleEnd
}