path_iter/
boolean.rs

1
2use crate::*;
3
4/// Logical NOT.
5#[derive(Clone)]
6pub struct Not;
7
8/// Logical AND.
9#[derive(Clone)]
10pub struct And;
11
12/// Logical OR.
13#[derive(Clone)]
14pub struct Or;
15
16/// Logical EQ.
17#[derive(Clone)]
18pub struct Eqb;
19
20/// Logical XOR.
21#[derive(Clone)]
22pub struct Xor;
23
24/// Logical IMPLY.
25#[derive(Clone)]
26pub struct Imply;
27
28/// A boolean unary function that returns `false`.
29#[derive(Clone)]
30pub struct False1;
31
32/// A boolean unary function that returns `true`.
33#[derive(Clone)]
34pub struct True1;
35
36/// Returns the argument of a boolean unary function.
37#[derive(Clone)]
38pub struct Idb;
39
40
41/// Returns the first argument of a boolean binary function.
42#[derive(Clone)]
43pub struct Fstb;
44
45/// Returns the second argument of a boolean binary function.
46#[derive(Clone)]
47pub struct Sndb;
48
49impl PApp for And {
50    type Arg = bool;
51    type Ret = Either<Idb, False1>;
52    fn papp(self, b: bool) -> Self::Ret {
53        if b {Either::Left(Idb)}
54        else {Either::Right(False1)}
55    }
56}
57
58impl PApp for Or {
59    type Arg = bool;
60    type Ret = Either<True1, Idb>;
61    fn papp(self, b: bool) -> Self::Ret {
62        if b {Either::Left(True1)}
63        else {Either::Right(Idb)}
64    }
65}
66
67impl PApp for Xor {
68    type Arg = bool;
69    type Ret = Either<Not, Idb>;
70    fn papp(self, b: bool) -> Self::Ret {
71        if b {Either::Left(Not)}
72        else {Either::Right(Idb)}
73    }
74}
75
76impl PApp for Imply {
77    type Arg = bool;
78    type Ret = Either<Idb, True1>;
79    fn papp(self, b: bool) -> Self::Ret {
80        if b {Either::Left(Idb)}
81        else {Either::Right(True1)}
82    }
83}
84
85impl PApp for Eqb {
86    type Arg = bool;
87    type Ret = Either<Idb, Not>;
88    fn papp(self, b: bool) -> Self::Ret {
89        if b {Either::Left(Idb)}
90        else {Either::Right(Not)}
91    }
92}
93
94impl PApp for Fstb {
95    type Arg = bool;
96    type Ret = Item<bool>;
97    fn papp(self, b: bool) -> Self::Ret {item(b)}
98}
99
100impl PApp for Sndb {
101    type Arg = bool;
102    type Ret = Idb;
103    fn papp(self, _: bool) -> Self::Ret {Idb}
104}
105
106impl HigherIntoIterator<Item<bool>> for False1 {
107    type Item = bool;
108    type IntoIter = std::vec::IntoIter<bool>;
109    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
110        match arg.inner() {
111            false => vec![false, true].into_iter(),
112            true => vec![].into_iter()
113        }
114    }
115}
116
117impl HigherIntoIterator<Item<bool>> for True1 {
118    type Item = bool;
119    type IntoIter = std::vec::IntoIter<bool>;
120    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
121        False1.hinto_iter(item(!arg.inner()))
122    }
123}
124
125impl HigherIntoIterator<Item<bool>> for Idb {
126    type Item = bool;
127    type IntoIter = <Option<bool> as IntoIterator>::IntoIter;
128    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
129        arg.into_iter()
130    }
131}
132
133impl HigherIntoIterator<Item<bool>> for Not {
134    type Item = bool;
135    type IntoIter = <Option<bool> as IntoIterator>::IntoIter;
136    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
137        item(!arg.inner()).into_iter()
138    }
139}
140
141impl HigherIntoIterator<Item<bool>> for And {
142    type Item = (bool, bool);
143    type IntoIter = std::vec::IntoIter<(bool, bool)>;
144    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
145        match arg.inner() {
146            false => vec![
147                (false, false),
148                (false, true),
149                (true, false)
150            ].into_iter(),
151            true => vec![
152                (true, true)
153            ].into_iter()
154        }
155    }
156}
157
158impl HigherIntoIterator<Item<bool>> for Or {
159    type Item = (bool, bool);
160    type IntoIter = std::vec::IntoIter<(bool, bool)>;
161    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
162        match arg.inner() {
163            false => vec![
164                (false, false),
165            ].into_iter(),
166            true => vec![
167                (false, true),
168                (true, false),
169                (true, true),
170            ].into_iter()
171        }
172    }
173}
174
175impl HigherIntoIterator<Item<bool>> for Eqb {
176    type Item = (bool, bool);
177    type IntoIter = std::vec::IntoIter<(bool, bool)>;
178    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
179        match arg.inner() {
180            false => vec![
181                (false, true),
182                (true, false)
183            ].into_iter(),
184            true => vec![
185                (false, false),
186                (true, true)
187            ].into_iter()
188        }
189    }
190}
191
192impl HigherIntoIterator<Item<bool>> for Xor {
193    type Item = (bool, bool);
194    type IntoIter = std::vec::IntoIter<(bool, bool)>;
195    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
196        Eqb.hinto_iter(item(!arg.inner()))
197    }
198}
199
200impl HigherIntoIterator<Item<bool>> for Imply {
201    type Item = (bool, bool);
202    type IntoIter = std::vec::IntoIter<(bool, bool)>;
203    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
204        match arg.inner() {
205            false => vec![
206                (true, false)
207            ].into_iter(),
208            true => vec![
209                (false, false),
210                (false, true),
211                (true, true),
212            ].into_iter()
213        }
214    }
215}
216
217impl HigherIntoIterator<Item<bool>> for Fstb {
218    type Item = (bool, bool);
219    type IntoIter = std::vec::IntoIter<(bool, bool)>;
220    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
221        match arg.inner() {
222            false => vec![
223                (false, false),
224                (false, true)
225            ].into_iter(),
226            true => vec![
227                (true, false),
228                (true, true)
229            ].into_iter()
230        }
231    }
232}
233
234impl HigherIntoIterator<Item<bool>> for Sndb {
235    type Item = (bool, bool);
236    type IntoIter = std::vec::IntoIter<(bool, bool)>;
237    fn hinto_iter(self, arg: Item<bool>) -> Self::IntoIter {
238        match arg.inner() {
239            false => vec![
240                (false, false),
241                (true, false)
242            ].into_iter(),
243            true => vec![
244                (false, true),
245                (true, false)
246            ].into_iter()
247        }
248    }
249}