data iter
Lazy synchronous sequence, source for for (§3.8).
Example:
fn main() io {
let squares = [1, 2, 3, 4].iter().map(x => x * x).filter(x => x > 1).collect()
print("{squares}")
}Output
[4, 9, 16]
@builtin("iter") pub(api) data iter<T>Complexity. adapters are lazy; consuming the sequence is O(n).
Since. 1.0.0-beta
Methods
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> FA lazy sequence of f(x) for every element x. |
filter | (p: fn(T) -> bool F escaping) -> iter<T> FA lazy sequence of the elements for which p is true. |
flatMap | (f: fn(T) -> iter<U> F escaping) -> iter<U> FA 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> FThe elements up to (not including) the first one for which p is false. |
skipWhile | (p: fn(T) -> bool F escaping) -> iter<T> FThe 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> FCalls 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>> FGroups by key in order of first appearance (a barrier |
sortBy | (key: fn(T) -> K F escaping) -> iter<T> FStable ascending sort by key (a barrier |
sortByDesc | (key: fn(T) -> K F escaping) -> iter<T> FStable descending sort by key. |
collect | () -> List<T>Materializes the sequence into a list. |
toList | () -> List<T>The same as collect(). |
count | () -> usizeNumber of elements (pulls them all). |
isEmpty | () -> booltrue 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 FCombines the elements with f, starting from start |
forEach | (f: fn(T) F)Calls f for every element. |
any | (p: fn(T) -> bool F) -> bool Ftrue if some element satisfies p; stops at the first one. |
all | (p: fn(T) -> bool F) -> bool Ftrue 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? FFirst element satisfying p; stops there. |
min | () -> T? where T: OrdThe smallest element, or none for an empty sequence. |
max | () -> T? where T: OrdThe largest element, or none for an empty sequence. |
sum | () -> i64Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> i64Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> i32Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> i32Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> i16Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> i16Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> i8Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> i8Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> isizeSum of the elements (pulls them all); panics on overflow like +. |
product | () -> isizeProduct of the elements (pulls them all); panics on overflow like *. |
sum | () -> i128Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> i128Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> u64Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> u64Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> u32Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> u32Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> u16Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> u16Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> u8Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> u8Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> usizeSum of the elements (pulls them all); panics on overflow like +. |
product | () -> usizeProduct of the elements (pulls them all); panics on overflow like *. |
sum | () -> u128Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> u128Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> f64Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> f64Product of the elements (pulls them all); panics on overflow like *. |
sum | () -> f32Sum of the elements (pulls them all); panics on overflow like +. |
product | () -> f32Product of the elements (pulls them all); panics on overflow like *. |
Defined in: std/core/types.oxl:375
See also
- std.core
- iter.next
- iter.iter
- iter.map
- iter.filter
- iter.flatMap
- iter.take
- iter.skip
- iter.takeWhile
- iter.skipWhile
- iter.enumerate
- iter.zip
- iter.chain
- iter.inspect
- iter.chunks
- iter.windows
- iter.groupBy
- iter.sortBy
- iter.sortByDesc
- iter.collect
- iter.toList
- iter.count
- iter.isEmpty
- iter.first
- iter.last
- iter.fold
- iter.forEach
- iter.any
- iter.all
- iter.find
- iter.min
- iter.max
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product
- iter.sum
- iter.product