Iter[A: A]¶
Wrapper class containing methods to modify iterators.
Implements¶
- Iterator[A] ref
Constructors¶
create¶
Parameters¶
- iter: Iterator[A] ref
Returns¶
- Iter[A] ref^
maybe¶
Parameters¶
- value: (A | None val)
Returns¶
- Iter[A] ref^
chain¶
Take an iterator of iterators and return an Iter containing the items of the first one, then the second one, and so on.
Example¶
let xs = [as I64: 1; 2].values()
let ys = [as I64: 3; 4].values()
Iter[I64].chain([xs; ys].values())
1 2 3 4
Parameters¶
Returns¶
- Iter[A] ref^
repeat_value¶
Create an iterator that returns the given value forever.
Example¶
7 7 7 7 7 7 7 7 7 ...
Parameters¶
- value: A
Returns¶
- Iter[A] ref^
Public Functions¶
has_next¶
Returns¶
- Bool val
next¶
Returns¶
- A ?
next_or¶
Return the next value, or the given default.
Example¶
42
Parameters¶
- default: A
Returns¶
- A
map_stateful[B: B]¶
Allows stateful transformation of each element from the iterator, similar
to map
.
Parameters¶
- f: {ref(A!): B ?}[A, B] ref
Returns¶
- Iter[B] ref^
filter_stateful¶
Allows filtering of elements based on a stateful adapter, similar to
filter
.
Parameters¶
- f: {ref(A!): Bool ?}[A] ref
Returns¶
- Iter[A!] ref^
filter_map_stateful[B: B]¶
Allows stateful modification to the stream of elements from an iterator,
similar to filter_map
.
Parameters¶
- f: {ref(A!): (B^ | None) ?}[A, B] ref
Returns¶
- Iter[B] ref^
all¶
Return false if at least one value of the iterator fails to match the
predicate f
. This method short-circuits at the first value where the
predicate returns false, otherwise true is returned.
Examples¶
true
false
Parameters¶
- f: {(A!): Bool ?}[A] box
Returns¶
- Bool val
any¶
Return true if at least one value of the iterator matches the predicate
f
. This method short-circuits at the first value where the predicate
returns true, otherwise false is returned.
Examples¶
false
true
Parameters¶
- f: {(A!): Bool ?}[A] box
Returns¶
- Bool val
collect[optional B: Seq[A!] ref]¶
Push each value from the iterator into the collection coll
.
Example¶
[1, 2, 3]
Parameters¶
- coll: B
Returns¶
- B^
count¶
Return the number of values in the iterator.
Example¶
3
Returns¶
- USize val
cycle¶
Repeatedly cycle through the values from the iterator.
WARNING: The values returned by the original iterator are cached, so the input iterator should be finite.
Example¶
1 2 3 1 2 3 1 2 3 ...
Returns¶
- Iter[A!] ref^
dedup[optional H: HashFunction[A] val]¶
Return an iterator that removes duplicates from consecutive identical
elements. Equality is determined by the HashFunction H
.
Example¶
1 2 3 2
Returns¶
- Iter[A!] ref^
enum[optional B: (Real[B] val & (I8 val | I16 val | I32 val | I64 val | I128 val | ILong val | ISize val | U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val | F32 val | F64 val))]¶
An iterator which yields the current iteration count as well as the next value from the iterator.
Example¶
(0, 1) (1, 2) (2, 3)
fun ref enum[optional B: (Real[B] val & (I8 val | I16 val | I32 val |
I64 val | I128 val | ILong val |
ISize val | U8 val | U16 val |
U32 val | U64 val | U128 val |
ULong val | USize val | F32 val |
F64 val))]()
: Iter[(B , A)] ref^
Returns¶
- Iter[(B , A)] ref^
filter¶
Return an iterator that only returns items that match the predicate f
.
Example¶
2 4 6
Parameters¶
- f: {(A!): Bool ?}[A] box
Returns¶
- Iter[A!] ref^
find¶
Return the nth value in the iterator that satisfies the predicate f
.
Examples¶
2
4
Parameters¶
- f: {(A!): Bool ?}[A] box
- n: USize val = 1
Returns¶
- A! ?
filter_map[B: B]¶
Return an iterator which applies f
to each element. If None
is
returned, then the iterator will try again by applying f
to the next
element. Otherwise, the value of type B
is returned.
Example¶
Iter[I64]([as I64: 1; -2; 4; 7; -5])
.filter_map[USize](
{(i: I64): (USize | None) => if i >= 0 then i.usize() end })
1 4 7
Parameters¶
- f: {(A!): (B^ | None) ?}[A, B] box
Returns¶
- Iter[B] ref^
flat_map[B: B]¶
Return an iterator over the values of the iterators produced from the application of the given function.
Example¶
a l p h a b e t a g a m m a
Parameters¶
- f: {(A!): Iterator[B] ?}[A, B] box
Returns¶
- Iter[B] ref^
fold[B: B]¶
Apply a function to every element, producing an accumulated value.
Example¶
6
Parameters¶
- acc: B
- f: {(B, A!): B^}[A, B] box
Returns¶
- B^
fold_partial[B: B]¶
A partial version of fold
.
Parameters¶
- acc: B
- f: {(B, A!): B^ ?}[A, B] box
Returns¶
- B^ ?
interleave¶
Return an iterator that alternates the values of the original iterator and the other until both run out.
Example¶
0 4 1 5 2 3
Parameters¶
- other: Iterator[A] ref
Returns¶
- Iter[A!] ref
interleave_shortest¶
Return an iterator that alternates the values of the original iterator and the other until one of them runs out.
Example¶
0 4 1 5 2
Parameters¶
- other: Iterator[A] ref
Returns¶
- Iter[A!] ref
intersperse¶
Return an iterator that yields the value after every n
elements of the
original iterator.
Example¶
0 8 1 8 2
Parameters¶
- value: A
- n: USize val = 1
Returns¶
- Iter[A!] ref
last¶
Return the last value of the iterator.
Example¶
3
Returns¶
- A ?
map[B: B]¶
Return an iterator where each item's value is the application of the given function to the value in the original iterator.
Example¶
1 4 9
Parameters¶
- f: {(A!): B ?}[A, B] box
Returns¶
- Iter[B] ref^
nth¶
Return the nth value of the iterator.
Example¶
2
Parameters¶
- n: USize val
Returns¶
- A ?
run¶
Iterate through the values of the iterator without a for loop. The
function on_error
will be called if the iterator's has_next
method
returns true but its next
method throws an error.
Example¶
Parameters¶
- on_error: {ref()}[A] ref = lambda
Returns¶
- None val
skip¶
Skip the first n values of the iterator.
Example¶
4 5 6
false
Parameters¶
- n: USize val
Returns¶
- Iter[A] ref^
skip_while¶
Skip values of the iterator while the predicate f
returns true.
Example¶
4 5 6
Parameters¶
- f: {(A!): Bool ?}[A] box
Returns¶
- Iter[A!] ref^
step_by¶
Return an iterator that yields every n
th element of the
original iterator. n == 0 is treated like n == 1 rather than an error.
Example¶
1 3 5 7 9
Parameters¶
- n: USize val = 1
Returns¶
- Iter[A!] ref
take¶
Return an iterator for the first n elements.
Example¶
1 2 3
Parameters¶
- n: USize val
Returns¶
- Iter[A] ref^
take_while¶
Return an iterator that returns values while the predicate f
returns
true. This iterator short-circuits the first time that f
returns false or
raises an error.
Example¶
1 2 3
Parameters¶
- f: {(A!): Bool ?}[A] box
Returns¶
- Iter[A!] ref^
unique[optional H: HashFunction[A] val]¶
Return an iterator that filters out elements that have already been
produced. Uniqueness is determined by the HashFunction H
.
Example¶
1 2 3 4
Returns¶
- Iter[A!] ref^
zip[B: B]¶
Zip two iterators together so that each call to next() results in a tuple with the next value of the first iterator and the next value of the second iterator. The number of items returned is the minimum of the number of items returned by the two iterators.
Example¶
(1, 3) (2, 4)
Parameters¶
- i2: Iterator[B] ref
Returns¶
- Iter[(A , B)] ref^
zip2[B: B, C: C]¶
Zip three iterators together so that each call to next() results in a tuple with the next value of the first iterator, the next value of the second iterator, and the value of the third iterator. The number of items returned is the minimum of the number of items returned by the three iterators.
Parameters¶
Returns¶
- Iter[(A , B , C)] ref^
zip3[B: B, C: C, D: D]¶
Zip four iterators together so that each call to next() results in a tuple with the next value of each of the iterators. The number of items returned is the minimum of the number of items returned by the iterators.
fun ref zip3[B: B, C: C, D: D](
i2: Iterator[B] ref,
i3: Iterator[C] ref,
i4: Iterator[D] ref)
: Iter[(A , B , C , D)] ref^
Parameters¶
Returns¶
- Iter[(A , B , C , D)] ref^
zip4[B: B, C: C, D: D, E: E]¶
Zip five iterators together so that each call to next() results in a tuple with the next value of each of the iterators. The number of items returned is the minimum of the number of items returned by the iterators.
fun ref zip4[B: B, C: C, D: D, E: E](
i2: Iterator[B] ref,
i3: Iterator[C] ref,
i4: Iterator[D] ref,
i5: Iterator[E] ref)
: Iter[(A , B , C , D , E)] ref^
Parameters¶
Returns¶
- Iter[(A , B , C , D , E)] ref^