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
#![feature(generic_associated_types)]
#![allow(incomplete_features)]

#[cfg(test)]
extern crate quickcheck;

#[cfg(test)]
#[macro_use(quickcheck)]
extern crate quickcheck_macros;

mod applicative;
mod apply;
mod bind;
mod empty;
mod foldable;
mod functor;
mod monad;
mod monoid;
mod pure;
mod semigroup;

pub use applicative::*;
pub use apply::*;
pub use bind::*;
pub use empty::*;
pub use foldable::*;
pub use functor::*;
pub use monad::*;
pub use monoid::*;
pub use pure::*;
pub use semigroup::*;

#[cfg(test)]
mod tests {
    use crate::{Apply, Bind, Foldable, Functor};

    #[test]
    fn it_works() {
        let v: Option<i32> = Some(10).bind(|x| Some(20).fmap(|y| x + y));
        println!("{:?}", v);
        let v2: Option<i32> = Some(10).ap(Some(|x: &i32| x + 20));
        println!("{:?}", v2);
        let vec = vec![1, 3, 5];
        let n: i32 = vec.fold_left(0, |x, y: &i32| x + y);
        println!("{:?}", n)
    }
}