isSortedBy

fun <T, R : Comparable<R>> List<T>.isSortedBy(selector: (T) -> R, ascending: Boolean = true, ignoreCase: Boolean = true): Boolean

Checks if the list is sorted according to the specified selector function.

This function determines if the elements in the list are in the specified order when transformed by the given selector function. The order is determined by the natural order of the Comparable type R returned by the selector.

Return

true if the list is sorted according to the selector function in the specified order, false otherwise.

Parameters

selector

A function that extracts a comparable value from an element.

ascending

Determines the order of sorting. If true (default), checks for ascending order. If false, checks for descending order.

ignoreCase

For String comparisons, determines whether the comparison should be case-insensitive. Default is true. Has no effect on non-String comparisons.

Throws

if the selector function returns values that are not mutually comparable.