itertools::icompr!
[−]
[src]
macro_rules! icompr { ($r:expr, $x:pat, $J:expr, $pred:expr) => ( ($J).filter_map(|$x| if $pred { Some($r) } else { None }) ); ($r:expr, $x:pat, $J:expr) => ( ($J).filter_map(|$x| Some($r)) ); }
Deprecated: Will hopefully be replaced by a dedicated syntax extension that can offer real convenient python-like syntax.
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.
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>
let mut squares = icompr!(x * x, x, 1..100);