itertools::icompr! [] [src]

macro_rules! icompr {
    ($r:expr, $x:pat, $J:expr, $pred:expr) => { ... };
    ($r:expr, $x:pat, $J:expr) => { ... };
}

icompr as in “iterator comprehension” allows creating a mapped iterator with simple syntax, similar to set builder notation, and directly inspired by Python. Supports an optional filter clause.

Syntax:

icompr!(<expression>, <pattern>, <iterator>)

or

icompr!(<expression>, <pattern>, <iterator>, <expression>)

Each element from the <iterator> expression is pattern matched with the <pattern>, and the bound names are used to express the mapped-to value.

Iterator element type is the type of <expression>

Example

let mut squares = icompr!(x * x, x, 1..100);

Note: A Python like syntax of <expression> for <pattern> in <iterator> is not possible with the stable macro rules since Rust 1.0.0-alpha.