Expand description
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.
§Example:
let l = map_for!{
move;
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 }) });
Macros§
- Scala-like for comprehension similar to those described in https://stackoverflow.com/questions/3754089/scala-for-comprehension#3754568 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).
Traits§
- This trait creates a
filter
method forOption
so that it can be filtered on when used in themap_for
macro. - This trait creates a
flat_map
method forOption
(equivalent toOption::and_then
) so that it can be used in themap_for
macro.