rust-monadic
A macro to write Haskell style monadic code
for IntoIterator (iterables) as monads
Each step monad expression is flat_mapped with the rest into a lazy FlatMap expression which implements IntoIterator with lambdas as move closures capturing the environment and argument.
You can use:
Some( return_expresion)
to return an expression valuev <- monadic_expression
to use the monad result_ <- monadic_expression
to ignore the monad resultlet z = expression
to combine monad resultsguard boolean_expression
to filter results
Note: let, within the macro, introduces an expression, not a block.
Example: monadic comprehensions à la Haskell
// examples/comprehension.rs
use monadic::monadic;
use num::Integer;
fn main() {
let xs = monadic!{
x <- 1..7;
y <- 1..x;
guard (&y).is_odd() ;
let z = &y + 1 ;
Some((x, z))
}.collect::<Vec<(i32,i32)>>();
println!("result: {:?}", xs);
}