std.iter

Lazy iterator constructors.

Importuse std.iter

Types

struct Iterator#

A lazy, single-pass sequence of values (Iterator<T>).

Produced by iter() on arrays, dictionaries, and ranges, and by the std.iter constructors (empty, once, repeat, from_fn). Driven one value at a time by next() or a for loop; adapters such as map, filter, take_while, flat_map, and chain stay lazy until a consumer (collect, fold, sum, count, the loop itself) pulls values through.

use std.iter

fn main() {
  println([1, 2, 3].iter().map(|n| n * 2).collect())
  for value in iter.repeat("ab").take(2) {
    println(value)
  }
  println(iter.once(1).chain([2, 3].iter()).sum())
  println([1, 2, 3, 4].iter().filter(|n| n % 2 == 0).count())
}

Functions

fn empty<T>() -> Iterator<T>#
fn once<T>(value: T) -> Iterator<T>#
fn repeat<T>(value: T) -> Iterator<T>#
fn from_fn<T>(next: fn() -> Optional<T>) -> Iterator<T>#