OxL Справочник OxL
РусскийEnglish

data iter

Lazy synchronous sequence, source for for (§3.8).

Example:

oxl✓ проверяется в CI
fn main() io {
  let squares = [1, 2, 3, 4].iter().map(x => x * x).filter(x => x > 1).collect()
  print("{squares}")
}
Вывод
[4, 9, 16]
@builtin("iter") pub(api) data iter<T>

Сложность. adapters are lazy; consuming the sequence is O(n).

С версии. 1.0.0-beta

Методы

next() -> T?
Next element or none when the sequence is exhausted.
iter() -> iter<T>
An iterator is its own iter() (so it satisfies Iterable<T>).
map(f: fn(T) -> U F escaping) -> iter<U> F
A lazy sequence of f(x) for every element x.
filter(p: fn(T) -> bool F escaping) -> iter<T> F
A lazy sequence of the elements for which p is true.
flatMap(f: fn(T) -> iter<U> F escaping) -> iter<U> F
A lazy sequence of all elements of the sequences f(x) returns, in order.
take(n: I) -> iter<T>
The first n elements; the element after them is never pulled.
skip(n: I) -> iter<T>
A sequence without the first n elements (a negative n counts as 0).
takeWhile(p: fn(T) -> bool F escaping) -> iter<T> F
The elements up to (not including) the first one for which p is false.
skipWhile(p: fn(T) -> bool F escaping) -> iter<T> F
The elements from the first one for which p is false on.
enumerate() -> iter<(usize, T)>
Pairs (index, element) with the index counting from 0.
zip(other: iter<U>) -> iter<(T, U)>
Pairs of elements of self and other; ends with the shorter sequence.
chain(other: iter<T>) -> iter<T>
All elements of self, then all elements of other.
inspect(f: fn(T) F escaping) -> iter<T> F
Calls f on a copy of every element as it passes (debugging aid).
chunks(n: I) -> iter<List<T>>
Consecutive groups of n elements (the last one may be shorter).
windows(n: I) -> iter<List<T>>
Sliding windows of n consecutive elements (none if there are fewer than n).
groupBy(key: fn(T) -> K F escaping) -> iter<Group<K, T>> F
Groups by key in order of first appearance (a barrier
sortBy(key: fn(T) -> K F escaping) -> iter<T> F
Stable ascending sort by key (a barrier
sortByDesc(key: fn(T) -> K F escaping) -> iter<T> F
Stable descending sort by key.
collect() -> List<T>
Materializes the sequence into a list.
toList() -> List<T>
The same as collect().
count() -> usize
Number of elements (pulls them all).
isEmpty() -> bool
true if the sequence has no elements (consumes the iterator).
first() -> T?
First element or none; later elements are not pulled.
last() -> T?
Last element or none (pulls them all).
fold(start: A, f: fn(A, T) -> A F) -> A F
Combines the elements with f, starting from start
forEach(f: fn(T) F)
Calls f for every element.
any(p: fn(T) -> bool F) -> bool F
true if some element satisfies p; stops at the first one.
all(p: fn(T) -> bool F) -> bool F
true if every element satisfies p (also for an empty sequence); stops at the first element that does not.
find(p: fn(T) -> bool F) -> T? F
First element satisfying p; stops there.
min() -> T? where T: Ord
The smallest element, or none for an empty sequence.
max() -> T? where T: Ord
The largest element, or none for an empty sequence.
sum() -> i64
Sum of the elements (pulls them all); panics on overflow like +.
product() -> i64
Product of the elements (pulls them all); panics on overflow like *.
sum() -> i32
Sum of the elements (pulls them all); panics on overflow like +.
product() -> i32
Product of the elements (pulls them all); panics on overflow like *.
sum() -> i16
Sum of the elements (pulls them all); panics on overflow like +.
product() -> i16
Product of the elements (pulls them all); panics on overflow like *.
sum() -> i8
Sum of the elements (pulls them all); panics on overflow like +.
product() -> i8
Product of the elements (pulls them all); panics on overflow like *.
sum() -> isize
Sum of the elements (pulls them all); panics on overflow like +.
product() -> isize
Product of the elements (pulls them all); panics on overflow like *.
sum() -> i128
Sum of the elements (pulls them all); panics on overflow like +.
product() -> i128
Product of the elements (pulls them all); panics on overflow like *.
sum() -> u64
Sum of the elements (pulls them all); panics on overflow like +.
product() -> u64
Product of the elements (pulls them all); panics on overflow like *.
sum() -> u32
Sum of the elements (pulls them all); panics on overflow like +.
product() -> u32
Product of the elements (pulls them all); panics on overflow like *.
sum() -> u16
Sum of the elements (pulls them all); panics on overflow like +.
product() -> u16
Product of the elements (pulls them all); panics on overflow like *.
sum() -> u8
Sum of the elements (pulls them all); panics on overflow like +.
product() -> u8
Product of the elements (pulls them all); panics on overflow like *.
sum() -> usize
Sum of the elements (pulls them all); panics on overflow like +.
product() -> usize
Product of the elements (pulls them all); panics on overflow like *.
sum() -> u128
Sum of the elements (pulls them all); panics on overflow like +.
product() -> u128
Product of the elements (pulls them all); panics on overflow like *.
sum() -> f64
Sum of the elements (pulls them all); panics on overflow like +.
product() -> f64
Product of the elements (pulls them all); panics on overflow like *.
sum() -> f32
Sum of the elements (pulls them all); panics on overflow like +.
product() -> f32
Product of the elements (pulls them all); panics on overflow like *.

Определено в: std/core/types.oxl:375

См. также