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
use super::op_closure;
use super::super::traits::action;
use std::fmt::Debug;

use action::MonoidAction;
use op_closure::OpClosure;

#[derive(Clone, Copy, Debug, Default)]
pub struct OpClosureOnOpClosure<T, OpT, IdT, U, OpU, IdU, Act>
where
    OpT: Fn(T, T) -> T,
    IdT: Fn() -> T,
    OpU: Fn(U, U) -> U,
    IdU: Fn() -> U,
    Act: Fn(T, U) -> T,
{
    operator: OpClosure<U, OpU, IdU>,
    operand: OpClosure<T, OpT, IdT>,
    act: Act,
}

impl<T, OpT, IdT, U, OpU, IdU, Act> MonoidAction
    for OpClosureOnOpClosure<T, OpT, IdT, U, OpU, IdU, Act>
where
    T: Eq + Sized,
    OpT: Fn(T, T) -> T,
    IdT: Fn() -> T,
    U: Eq + Sized,
    OpU: Fn(U, U) -> U,
    IdU: Fn() -> U,
    Act: Fn(T, U) -> T,
{
    type Operand = OpClosure<T, OpT, IdT>;
    type Operator = OpClosure<U, OpU, IdU>;
    fn operand(&self) -> &Self::Operand { &self.operand }
    fn operator(&self) -> &Self::Operator { &self.operator }
    fn act(&self, x: T, op: U) -> T { (self.act)(x, op) }
}

impl<T, OpT, IdT, U, OpU, IdU, Act>
    OpClosureOnOpClosure<T, OpT, IdT, U, OpU, IdU, Act>
where
    T: Eq + Sized,
    OpT: Fn(T, T) -> T,
    IdT: Fn() -> T,
    U: Eq + Sized,
    OpU: Fn(U, U) -> U,
    IdU: Fn() -> U,
    Act: Fn(T, U) -> T,
{
    pub fn new(
        operand: OpClosure<T, OpT, IdT>,
        operator: OpClosure<U, OpU, IdU>,
        act: Act,
    ) -> Self {
        Self { operand, operator, act }
    }
}