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
use crate::boolean::Boolean;
use std::marker::PhantomData;
pub trait Functor<Input> {
type Output;
}
pub type ApplyFunctor<Func, Input> = <Func as Functor<Input>>::Output;
pub trait Predicate<Input>
where
Self: Functor<Input>,
Self::Output: Boolean,
{
}
pub struct Compose<Lhs, Rhs> {
_phantom: PhantomData<(Lhs, Rhs)>,
}
impl<Input, Lhs, Rhs> Functor<Input> for Compose<Lhs, Rhs>
where
Lhs: Functor<ApplyFunctor<Rhs, Input>>,
Rhs: Functor<Input>,
{
type Output = ApplyFunctor<Lhs, ApplyFunctor<Rhs, Input>>;
}
pub struct IdentityFunctor {}
impl<Input> Functor<Input> for IdentityFunctor {
type Output = Input;
}
pub struct LeftComposeFunctor<Lhs, Func> {
_phantom: PhantomData<(Lhs, Func)>,
}
impl<Lhs, Rhs, Func> Functor<Rhs> for LeftComposeFunctor<Lhs, Func>
where
Func: Functor<(Lhs, Rhs)>,
{
type Output = ApplyFunctor<Func, (Lhs, Rhs)>;
}
pub struct RightComposeFunctor<Rhs, Func> {
_phantom: PhantomData<(Rhs, Func)>,
}
impl<Lhs, Rhs, Func> Functor<Lhs> for RightComposeFunctor<Rhs, Func>
where
Func: Functor<(Lhs, Rhs)>,
{
type Output = ApplyFunctor<Func, (Lhs, Rhs)>;
}