Scoop API

scoop:scoop.std:0.1.0

src/sequences/terminal_find.scoop

Selected production source · src/sequences/terminal_find.scoop

1package scoop.sequences
3import scoop.collections.*
5/**
6 * Consumes this sequence. Returns the first eligible element in iteration order, applying the
7 * predicate when supplied; absence throws NoSuchElementException.
8 */
9public fun <T> Sequence<T>.first(): T =
10 terminalInput<T>().first<T>()
12/**
13 * Consumes this sequence. Returns the first eligible element in iteration order, applying the
14 * predicate when supplied; absence throws NoSuchElementException.
15 */
16public fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T =
17 terminalInput<T>().first<T>(predicate)
19/**
20 * Consumes this sequence. Returns the first eligible element in iteration order, applying the
21 * predicate when supplied, or None.
22 */
23public fun <T> Sequence<T>.firstOrNone(): T? =
24 terminalInput<T>().firstOrNone<T>()
26/**
27 * Consumes this sequence. Returns the first eligible element in iteration order, applying the
28 * predicate when supplied, or None.
29 */
30public fun <T> Sequence<T>.firstOrNone(predicate: (T) -> Boolean): T? =
31 terminalInput<T>().firstOrNone<T>(predicate)
33/**
34 * Consumes this sequence. Returns the last eligible element after traversal, applying the
35 * predicate when supplied; absence throws NoSuchElementException.
36 */
37public fun <T> Sequence<T>.last(): T =
38 terminalInput<T>().last<T>()
40/**
41 * Consumes this sequence. Returns the last eligible element after traversal, applying the
42 * predicate when supplied; absence throws NoSuchElementException.
43 */
44public fun <T> Sequence<T>.last(predicate: (T) -> Boolean): T =
45 terminalInput<T>().last<T>(predicate)
47/**
48 * Consumes this sequence. Returns the last eligible element after traversal, applying the
49 * predicate when supplied, or None.
50 */
51public fun <T> Sequence<T>.lastOrNone(): T? =
52 terminalInput<T>().lastOrNone<T>()
54/**
55 * Consumes this sequence. Returns the last eligible element after traversal, applying the
56 * predicate when supplied, or None.
57 */
58public fun <T> Sequence<T>.lastOrNone(predicate: (T) -> Boolean): T? =
59 terminalInput<T>().lastOrNone<T>(predicate)
61/**
62 * Consumes this sequence. Requires exactly one eligible element. No match throws
63 * NoSuchElementException; multiple matches throw IllegalArgumentException.
64 */
65public fun <T> Sequence<T>.single(): T =
66 terminalInput<T>().single<T>()
68/**
69 * Consumes this sequence. Requires exactly one eligible element. No match throws
70 * NoSuchElementException; multiple matches throw IllegalArgumentException.
71 */
72public fun <T> Sequence<T>.single(predicate: (T) -> Boolean): T =
73 terminalInput<T>().single<T>(predicate)
75/**
76 * Consumes this sequence. Returns the sole eligible element, or None for zero or multiple matches.
77 */
78public fun <T> Sequence<T>.singleOrNone(): T? =
79 terminalInput<T>().singleOrNone<T>()
81/**
82 * Consumes this sequence. Returns the sole eligible element, or None for zero or multiple matches.
83 */
84public fun <T> Sequence<T>.singleOrNone(predicate: (T) -> Boolean): T? =
85 terminalInput<T>().singleOrNone<T>(predicate)
87/**
88 * Consumes this sequence. Returns the first element satisfying the predicate, or None.
89 */
90public fun <T> Sequence<T>.find(predicate: (T) -> Boolean): T? =
91 terminalInput<T>().find<T>(predicate)
93/**
94 * Consumes this sequence. Returns the element at a zero-based iteration index; an out-of-range
95 * index throws IndexOutOfBoundsException.
96 */
97public fun <T> Sequence<T>.elementAt(index: Long): T =
98 terminalInput<T>().elementAt<T>(index)
100/**
101 * Consumes this sequence. Returns the element at a zero-based iteration index, or None for a
102 * negative or out-of-range index.
103 */
104public fun <T> Sequence<T>.elementAtOrNone(index: Long): T? =
105 terminalInput<T>().elementAtOrNone<T>(index)
107/**
108 * Consumes this sequence. Returns the first equal element's zero-based iteration index, or -1 if
109 * absent.
110 */
111public fun <T : Equals<T>> Sequence<T>.indexOf(element: T): Long =
112 terminalInput<T>().indexOf<T>(element)
114/**
115 * Consumes this sequence. Stops at the first equal element and reports whether one exists.
116 */
117public operator fun <T : Equals<T>> Sequence<T>.contains(element: T): Boolean =
118 terminalInput<T>().contains<T>(element)