[][src]Crate monadic

Haskell style "monadic" macro where monad sources should be expressions of type instances of IntoIterator.

Each monad expression is flat_mapped with the lambda expression having the monad result variable as argument and the rest as its body, into a lazy FlatMap expression which can be collected into any instance of FromIterator..


   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