[−][src]Crate monadic
Haskell style "monadic" macro where monad sources should be expressions implementing IntoIterator
Each step monad expression is flat_mapped with the rest into a lazy FlatMap expression which implements IntoIterator
let xs = monadic!{ x <- 1..5; y <- 1..x; guard y < x; let z = y - 1; Some((x,z)) }.collect::<Vec<(i32,i32)>>(); println!("result: {:?}", xs); // test: fn it_works() { let xs = (1..5).collect::<Vec<i32>>(); // expected let zs = (&xs).into_iter().filter(|&v| v < &4).map(|v| v*2).collect::<Vec<i32>>(); // monadic let ys = monadic!{ v <- &xs; guard v < &4; Some( v * 2) }.collect::<Vec<i32>>(); assert_eq!(ys, zs); }
Macros
monadic | converting monadic blocs of IntoIterator's as monads à la Haskell |