monadic/
lib.rs

1//!
2//! Haskell style block macros "mdo"
3//! where monad sources should be expressions of type instances of IntoIterator.
4//!
5//! Each monad expression is flat_mapped (`into_iter().flat_map( lambda)`) 
6//! with the lambda expression having the monad result variable as argument and the rest as its body,
7//! into a lazy FlatMap expression that is also an instance of IntoIterator, and can be collected into any instance of FromIterator.
8//!
9//! To use "mdo" (module `monad`) you must import the traits Bind and Monad defined there.
10//!
11//! There are transitive implementation relations for some structures to be instances of IntoIterator:
12//!
13//! All iterators implement IntoIterator where into_iter() returns the self iterator structure
14//! as [documented](https://doc.rust-lang.org/stable/core/iter/#for-loops-and-intoiterator) 
15//!
16//! Iterator and IntoIterator trait imports are [predefined](https://doc.rust-lang.org/std/prelude/index.html#prelude-contents)
17//!
18//! There are also Reader, Writer and State monads in their respective modules with their own macros.
19//!
20//! ```no_run
21//! # #[macro_use] extern crate monadic;
22//! use num::Integer;
23//! use monadic::{mdo, monad::{Bind, Monad}};
24//!
25//! # fn main() {
26//!    // available in examples/comprehension.rs
27//!
28//!    let xs = mdo!{ 
29//!
30//!            x <- 1..7;
31//!            y <- 1..x;
32//!            guard (&y).is_odd() ;
33//!            let z = match x.is_even() { 
34//!                        true => &y + 1,
35//!                        _ => &y - 1,
36//!                    };
37//!            pure (x, z)
38//!            
39//!    }.collect::<Vec<(i32,i32)>>();
40//!    
41//!    println!("result: {:?}", xs); 
42//!
43//!    // now with container and item references, available in examples/comprehension2.rs
44//!
45//!    let ys = mdo!{ 
46//!    
47//!        &x <- &vec![1,2,3,4];  // with item refs (&x) in the lambda argument position
48//!        guard x.is_odd() ;
49//!        let z = x + 1 ;
50//!        pure (x, z)
51//!        
52//!    }.collect::<Vec<(i32,i32)>>();
53//!    
54//!    println!("result: {:?}", ys); 
55//! # }
56//! ```
57
58pub mod monad;
59pub mod mio;
60
61#[cfg(feature="reader")]
62pub mod reader;
63
64#[cfg(feature="reader_trans")]
65pub mod reader_trans;
66
67#[cfg(feature="writer")]
68pub mod writer;
69
70#[cfg(feature="writer_trans")]
71pub mod writer_trans;
72
73
74#[cfg(feature="state")]
75pub mod state;
76
77#[cfg(feature="state_trans")]
78pub mod state_trans;
79
80#[cfg(any(feature="writer", feature="writer_trans"))]
81pub mod util;
82
83#[cfg(any(feature="writer", feature="writer_trans"))]
84pub mod monoid;