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
// use super::applicative::Applicative;
// use super::functor::Functor;
// use super::functor::Functor;
// ! Not useful until the HKT family is implemented
// pub trait Monad: Functor {
// type Pure<A_>: Monad<HktArg1 = A_>;
// type M<B_>: Monad<HktArg1 = B_>;
// type Bind<B_, Mf_>: Monad<HktArg1 = B_>
// where
// Mf_: Fn(Self::HktArg1) -> Self::M<B_> + Clone;
// fn pure<A>(a: A) -> Self::Pure<A>;
// fn bind<B, Mf_>(self, mf: Mf_) -> Self::Bind<B, Mf_>
// where
// Mf_: Fn(Self::HktArg1) -> Self::M<B> + Clone;
// }
// #[cfg(test)]
// mod tests {
// use super::*;
// impl<T> Monad for Option<T> {
// fn and_then<B, F>(self, f: F) -> Self::Of<B>
// where
// F: Fn(T) -> Self::Of<B>,
// {
// match self {
// Some(x) => f(x),
// None => None,
// }
// }
// }
// #[test]
// fn test_option_monad() {
// assert_eq!(None.and_then(|x: i32| Some(x + 1)), None);
// assert_eq!(Some(1).and_then(|x: i32| Some(x + 1)), Some(2));
// assert_eq!(None::<i32>.then(None::<i32>), None);
// assert_eq!(None::<i32>.then(Some(1)), None);
// assert_eq!(Some(1).then(None::<i32>), None);
// assert_eq!(Some(1).then(Some(2)), Some(2));
// }
// }