assertSortedBy

fun <TKey : Comparable<TKey>, TValue> Sequence<TValue>.assertSortedBy(sortOrder: SortOrder = ASCENDING, keySelector: (TValue) -> TKey): SortedSequence<TKey, TValue>

Creates a SortedSequence from this sequence, asserting that elements are sorted by the given key selector.

Example:

val sequence = sequenceOf("az", "by", "cx").assertSortedBy { it.first() }
assertEquals(listOf("az", "by", "cx"), sequence.toList())

Return

A sorted sequence wrapper

Parameters

TKey

The type of keys in the sequence, must be comparable

TValue

The type of values in the sequence

sortOrder

The sort order to verify against (default: ASCENDING)

keySelector

Function that extracts the sorting key from each element