|
2 | 2 |
|
3 | 3 | namespace neither { |
4 | 4 |
|
5 | | -template<class L, class R> |
6 | | -constexpr bool hasValue(Either<L,R> const& e) { |
7 | | - return e; |
8 | | -} |
| 5 | + template<class L, class R> |
| 6 | + constexpr bool hasValue(Either<L,R> const& e) { |
| 7 | + return e; |
| 8 | + } |
9 | 9 |
|
10 | 10 |
|
11 | | -template<class T> |
12 | | -constexpr bool hasValue(Maybe<T> const& m) { |
13 | | - return m; |
14 | | -} |
| 11 | + template<class T> |
| 12 | + constexpr bool hasValue(Maybe<T> const& m) { |
| 13 | + return m; |
| 14 | + } |
15 | 15 |
|
16 | | -template<class T> |
17 | | -constexpr bool hasValue(T) { |
18 | | - return true; |
19 | | -} |
| 16 | + template<class T> |
| 17 | + constexpr bool hasValue(T) { |
| 18 | + return true; |
| 19 | + } |
20 | 20 |
|
21 | 21 |
|
22 | 22 |
|
23 | | -template<class L, class R> |
24 | | -constexpr R unpack(Either<L, R> const& e) { |
25 | | - return e.rightValue; |
26 | | -} |
27 | | - |
| 23 | + template<class L, class R> |
| 24 | + constexpr R unpack(Either<L, R> const& e) { |
| 25 | + return e.rightValue; |
| 26 | + } |
28 | 27 |
|
29 | | -template<class T> |
30 | | -constexpr T unpack(Maybe<T> const& m) { |
31 | | - return m.value; |
32 | | -} |
33 | 28 |
|
34 | | -template<class T> |
35 | | -constexpr T unpack(T const& x) { |
36 | | - return x; |
37 | | -} |
| 29 | + template<class T> |
| 30 | + constexpr T unpack(Maybe<T> const& m) { |
| 31 | + return m.value; |
| 32 | + } |
38 | 33 |
|
39 | | -constexpr auto allTrue(bool x=true, bool y=true) { |
40 | | - return x && y; |
41 | | -} |
| 34 | + template<class T> |
| 35 | + constexpr T unpack(T const& x) { |
| 36 | + return x; |
| 37 | + } |
42 | 38 |
|
| 39 | + constexpr auto allTrue(bool x=true, bool y=true) { |
| 40 | + return x && y; |
| 41 | + } |
43 | 42 |
|
44 | | -template<class X, class...Xs> |
45 | | -auto allTrue(X x, Xs...xs) { |
46 | | - return allTrue(x, allTrue(xs...)); |
47 | | -} |
48 | 43 |
|
49 | | -template<class F> |
50 | | -auto lift(F const& f) { |
51 | | - return [f](auto...x) -> decltype(maybe(f(unpack(x)...))) { |
52 | | - if ( allTrue(hasValue(x)...) ) { |
53 | | - return f(unpack(x)...); |
54 | | - } |
| 44 | + template<class X, class...Xs> |
| 45 | + auto allTrue(X x, Xs...xs) { |
| 46 | + return allTrue(x, allTrue(xs...)); |
| 47 | + } |
55 | 48 |
|
56 | | - return maybe(); |
57 | | - }; |
58 | | -} |
| 49 | + template<class F> |
| 50 | + auto lift(F const& f) { |
| 51 | + return [f](auto...x) -> decltype(maybe(f(unpack(x)...))) { |
| 52 | + if ( allTrue(hasValue(x)...) ) { |
| 53 | + return f(unpack(x)...); |
| 54 | + } |
59 | 55 |
|
| 56 | + return maybe(); |
| 57 | + }; |
| 58 | + } |
60 | 59 |
|
61 | 60 | } |
0 commit comments