1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//!
//! 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..
//!
//! ```
//! # #[macro_use] extern crate monadic;
//!
//! # fn main() {
//! let xs = monadic!{
//! x <- 1..5;
//! y <- 1..x;
//! guard y < x;
//! let z = y - 1;
//! Option::pure((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;
//! Option::pure( v * 2)
//! }.collect::<Vec<i32>>();
//!
//! assert_eq!(ys, zs);
//! }
//! ```
pub use Monad; //reexporting Monad
/// converting monadic blocs of IntoIterator's as monads à la Haskell
///
/// You can use:
/// * ```Option::pure( return_expresion)``` to return an expression value
/// * ```v <- monadic_expression``` to use the monad result
/// * ```_ <- monadic_expression``` to ignore the monad result
/// * ```let z = expression``` to combine monad results
/// * ```guard boolean_expression``` to filter results
///