Scoop API

scoop:scoop.std:0.1.0

src/sequences/random.scoop

Selected production source · src/sequences/random.scoop

1package scoop.sequences
3import scoop.random.Random
4import scoop.collections.random
5import scoop.collections.randomOrNone
6import scoop.collections.shuffled
8/**
9 * Consumes this sequence. Selects one element using the supplied random source; empty input throws
10 * NoSuchElementException.
11 */
12public fun <T> Sequence<T>.random(random: Random): T = terminalInput<T>().random<T>(random)
13/**
14 * Consumes this sequence. Selects one element using the supplied random source, or returns None
15 * for empty input.
16 */
17public fun <T> Sequence<T>.randomOrNone(random: Random): T? = terminalInput<T>().randomOrNone<T>(random)
18/**
19 * Evaluation is deferred until iteration. Copies the elements into a randomly permuted traversal
20 * using the supplied random source. Each traversal materializes the complete input before yielding
21 * results.
22 */
23public fun <T> Sequence<T>.shuffled(random: Random): Sequence<T> =
24 FactorySequence<T> { terminalInput<T>().shuffled<T>(random).iterator() }