#[mixable] Iter[T]
Abstract type for iterators, whose instances have the methods below. Built-in
iterators are Iter; a class that only implements (next)
is not.
Iter is not constructible directly. See
Classes for defining custom iterators.
Inherits from: Iterable[T]
Implements: BaseIter[T], Spread[T]
Methods
(iter)() -> Iter[T]
Returns this iterator.
(next)() -> T
Returns the next value, raising IterStop once exhausted.
(spread)() -> Spread[T]
Spreads the remaining items positionally.
all … -> Bool
Consumes the iterator and tests whether every value is truthy, or satisfies
pred, as Iterable.all does.
Parameters
| Name | Type | Description |
|---|---|---|
pred? |
((T) -> Value) |
any … -> Bool
Consumes the iterator and tests whether any value is truthy, or satisfies
pred, as Iterable.any does.
Parameters
| Name | Type | Description |
|---|---|---|
pred? |
((T) -> Value) |
chain[*Us] *values -> Iter[Union[T, ...Us]]
Returns an iterator that yields this iterator's values followed by those of each additional iterable.
Parameters
| Name | Type | Description |
|---|---|---|
*values |
...Iterable[Us] |
chomp() -> Iter[Str] overload 1 of 2
Returns an iterator with one trailing line terminator removed from each
value, as Iterable.chomp does.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Iter[Str] |
Receiver. |
chomp() -> Iter[Bin] overload 2 of 2
Returns an iterator with one trailing line terminator removed from each
value, as Iterable.chomp does.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Iter[Bin] |
Receiver. |
count() -> Int
Consumes the iterator and returns the number of values it yielded.
crimp … -> Iter[Str] overload 1 of 2
Returns an iterator with a line terminator appended to each value, as
Iterable.crimp does.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Iter[Str] |
Receiver. |
terminator? |
(Str | Bin) |
crimp … -> Iter[Bin] overload 2 of 2
Returns an iterator with a line terminator appended to each value, as
Iterable.crimp does.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Iter[Bin] |
Receiver. |
terminator? |
(Str | Bin) |
enumerate() -> Iter[Tuple[Int, T]]
Returns an iterator of (index, value) tuples, counting from 0.
filter pred -> Iter[T]
Returns an iterator of the values for which pred is truthy.
Parameters
| Name | Type | Description |
|---|---|---|
pred |
((T, <Value, >Value) -> Value) |
find[D = T] pred … -> (T | D)
Consumes values up to and including the first for which pred is truthy,
and returns it, as Iterable.find does.
Parameters
| Name | Type | Description |
|---|---|---|
pred |
((T) -> Value) |
|
:default? |
D |
|
:else? |
(() -> D) |
fold[A] init func -> A
Consumes the iterator, accumulating a value as
Iterable.fold does.
Parameters
| Name | Type | Description |
|---|---|---|
init |
A |
|
func |
((A, T) -> A) |
iter() -> Iter[T]
Returns this iterator.
kv[K, V]() -> Spread[K, V]
Adapts the remaining elements for keyed spreading.
Each element must unpack into exactly two values without being consumed. Spreading consumes the source. The adapter does not support iteration.
Parameters
| Name | Type | Description |
|---|---|---|
self |
Iter[Unpack[{K, V}]] |
Receiver. |
map[U] func -> Iter[U]
Returns an iterator that maps each value through func.
Parameters
| Name | Type | Description |
|---|---|---|
func |
((T, <Value, >Value) -> U) |
max[D = T] … -> (T | D)
Consumes the iterator and returns the largest value, as
Iterable.max does.
Parameters
| Name | Type | Description |
|---|---|---|
:default? |
D |
min[D = T] … -> (T | D)
Consumes the iterator and returns the smallest value, as
Iterable.min does.
Parameters
| Name | Type | Description |
|---|---|---|
:default? |
D |
next[D = T] … -> (T | D)
Returns the next value from the iterator.
Parameters
| Name | Type | Description |
|---|---|---|
:default? |
D |
|
:else? |
(() -> D) |
Errors
Raises IterStop when exhausted and there is no default
or else.
skip n -> Iter[T]
Returns an iterator that discards the first n values, then yields the
rest, as Iterable.skip does.
Parameters
| Name | Type | Description |
|---|---|---|
n |
Int |
take n -> Iter[T]
Returns an iterator that yields at most n values, as
Iterable.take does.
Parameters
| Name | Type | Description |
|---|---|---|
n |
Int |
zip[*Us] *values -> Iter[Tuple[T, ...Us]]
Returns an iterator of tuples across this iterator and the additional iterables, which stops at the end of the shortest.
Parameters
| Name | Type | Description |
|---|---|---|
*values |
...Iterable[Us] |