Crate map_for [] [src]

This is a Rust macro that implements for comprehensions similar to Scala's. This allows to chain calls to map, flat_map and filter in a very clean and concise manner.


let l = map_for!{
   x <- 0..10;
   y = x/2;
   if (y%2) == 0;
   z <- 0..1;
   => y+z };

Will be expanded to:

let l = (0..10).map (move |x| { let y = x / 2; (x, y) })
   .filter (move |params| { let (x, y) = *params; (y%2) == 0 })
   .flat_map (move |params| {
      let (x, y) = params;
      (0..1).map (move |z| { y + z }) });



Scala-like for comprehension similar to those described in The main difference is that since rust does not have partial functions, we do not support general patterns in the left-hand sides, but only single identifiers and list of identifiers (that will match a tuple).



This trait creates a filter method for Option so that it can be filtered on when used in the map_for macro.


This trait creates a flat_map method for Option (equivalent to Option::and_then) so that it can be used in the map_for macro.