scoop:scoop.std:0.1.0
src/sequences/terminal_reduce.scoop
Selected production source · src/sequences/terminal_reduce.scoop
1
package scoop.sequences3
import scoop.collections.*5
/**6
* Consumes this sequence. Runs the action for each element in iteration order.7
*/8
public fun <T> Sequence<T>.forEach(action: (T) -> Unit): Unit =9
terminalInput<T>().forEach<T>(action)11
/**12
* Consumes this sequence. Runs the action with each element and its zero-based Long index.13
*/14
public fun <T> Sequence<T>.forEachIndexed(action: (Long, T) -> Unit): Unit =15
terminalInput<T>().forEachIndexed<T>(action)17
/**18
* Consumes this sequence. Accumulates left to right from the supplied initial value, which is19
* returned for empty input.20
*/21
public fun <T, R> Sequence<T>.fold(initial: R, operation: (R, T) -> R): R =22
terminalInput<T>().fold<T, R>(initial, operation)24
/**25
* Consumes this sequence. Accumulates left to right from the first element; empty input throws26
* NoSuchElementException.27
*/28
public fun <T> Sequence<T>.reduce(operation: (T, T) -> T): T =29
terminalInput<T>().reduce<T>(operation)31
/**32
* Consumes this sequence. Accumulates left to right from the first element, or returns None for33
* empty input.34
*/35
public fun <T> Sequence<T>.reduceOrNone(operation: (T, T) -> T): T? =36
terminalInput<T>().reduceOrNone<T>(operation)38
/**39
* Consumes this sequence. Returns whether every element satisfies the predicate; true for empty40
* input.41
*/42
public fun <T> Sequence<T>.all(predicate: (T) -> Boolean): Boolean =43
terminalInput<T>().all<T>(predicate)45
/**46
* Consumes this sequence. Returns two lists: matching elements first and nonmatching elements47
* second, each retaining source order.48
*/49
public fun <T> Sequence<T>.partition(predicate: (T) -> Boolean): (List<T>, List<T>) =50
terminalInput<T>().partition<T>(predicate)52
/**53
* Consumes this sequence. Returns an independent list in reverse iteration order.54
*/55
public fun <T> Sequence<T>.reversed(): List<T> =56
terminalInput<T>().reversed<T>()58
/**59
* Consumes this sequence. Counts eligible elements, applying the predicate when supplied.60
*/61
public fun <T> Sequence<T>.count(): Long =62
terminalInput<T>().count<T>()64
/**65
* Consumes this sequence. Counts eligible elements, applying the predicate when supplied.66
*/67
public fun <T> Sequence<T>.count(predicate: (T) -> Boolean): Long =68
terminalInput<T>().count<T>(predicate)70
/**71
* Consumes this sequence. Returns whether any eligible element exists, applying the predicate when72
* supplied and stopping at the first match.73
*/74
public fun <T> Sequence<T>.any(): Boolean =75
terminalInput<T>().any<T>()77
/**78
* Consumes this sequence. Returns whether any eligible element exists, applying the predicate when79
* supplied and stopping at the first match.80
*/81
public fun <T> Sequence<T>.any(predicate: (T) -> Boolean): Boolean =82
terminalInput<T>().any<T>(predicate)84
/**85
* Consumes this sequence. Returns whether no eligible element exists, applying the predicate when86
* supplied and stopping at the first match.87
*/88
public fun <T> Sequence<T>.none(): Boolean =89
terminalInput<T>().none<T>()91
/**92
* Consumes this sequence. Returns whether no eligible element exists, applying the predicate when93
* supplied and stopping at the first match.94
*/95
public fun <T> Sequence<T>.none(predicate: (T) -> Boolean): Boolean =96
terminalInput<T>().none<T>(predicate)