scoop:scoop.std:0.1.0
src/sequences/sorting.scoop
Selected production source · src/sequences/sorting.scoop
1
package scoop.sequences3
import scoop.collections.sortedWith4
import scoop.collections.sortedBy5
import scoop.comparisons.Comparator6
import scoop.comparisons.naturalOrder7
import scoop.comparisons.reverseOrder9
/**10
* Evaluation is deferred until iteration. Creates a lazy sequence that materializes a stable11
* sorted copy using the supplied comparator. Each traversal materializes the complete input before12
* yielding results.13
*/14
public fun <T> Sequence<T>.sortedWith(comparator: Comparator<T>): Sequence<T> =15
FactorySequence<T> { terminalInput<T>().sortedWith<T>(comparator).iterator() }17
/**18
* Evaluation is deferred until iteration. Creates a lazy sequence that materializes a stable copy19
* in natural ascending order. Each traversal materializes the complete input before yielding20
* results.21
*/22
public fun <T : Compare<T>> Sequence<T>.sorted(): Sequence<T> = sortedWith<T>(naturalOrder<T>())23
/**24
* Evaluation is deferred until iteration. Creates a lazy sequence that materializes a stable copy25
* in natural descending order. Each traversal materializes the complete input before yielding26
* results.27
*/28
public fun <T : Compare<T>> Sequence<T>.sortedDescending(): Sequence<T> = sortedWith<T>(reverseOrder<T>())30
/**31
* Evaluation is deferred until iteration. Creates a lazy sequence that materializes a stable copy32
* ordered by the selector's natural key order. Each traversal materializes the complete input33
* before yielding results.34
*/35
public fun <T, K : Compare<K>> Sequence<T>.sortedBy(selector: (T) -> K): Sequence<T> =36
FactorySequence<T> { terminalInput<T>().sortedBy<T, K>(selector).iterator() }