6
6
import com .jnape .palatable .lambda .adt .hlist .HList ;
7
7
import com .jnape .palatable .lambda .adt .hlist .Tuple5 ;
8
8
import com .jnape .palatable .lambda .functions .Fn1 ;
9
+ import com .jnape .palatable .lambda .functions .recursion .RecursiveResult ;
9
10
import com .jnape .palatable .lambda .functions .specialized .Pure ;
10
11
import com .jnape .palatable .lambda .functor .Applicative ;
11
12
import com .jnape .palatable .lambda .functor .Bifunctor ;
12
13
import com .jnape .palatable .lambda .functor .builtin .Lazy ;
13
14
import com .jnape .palatable .lambda .monad .Monad ;
15
+ import com .jnape .palatable .lambda .monad .MonadRec ;
14
16
import com .jnape .palatable .lambda .traversable .Traversable ;
15
17
16
18
import java .util .Objects ;
17
19
18
20
import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into5 .into5 ;
21
+ import static com .jnape .palatable .lambda .functions .recursion .RecursiveResult .terminate ;
22
+ import static com .jnape .palatable .lambda .functions .recursion .Trampoline .trampoline ;
19
23
import static com .jnape .palatable .lambda .functor .builtin .Lazy .lazy ;
20
24
21
25
/**
31
35
*/
32
36
public abstract class Choice5 <A , B , C , D , E > implements
33
37
CoProduct5 <A , B , C , D , E , Choice5 <A , B , C , D , E >>,
34
- Monad <E , Choice5 <A , B , C , D , ?>>,
38
+ MonadRec <E , Choice5 <A , B , C , D , ?>>,
35
39
Bifunctor <D , E , Choice5 <A , B , C , ?, ?>>,
36
40
Traversable <E , Choice5 <A , B , C , D , ?>> {
37
41
@@ -70,7 +74,7 @@ public Choice4<A, B, C, D> converge(Fn1<? super E, ? extends CoProduct4<A, B, C,
70
74
*/
71
75
@ Override
72
76
public <F > Choice5 <A , B , C , D , F > fmap (Fn1 <? super E , ? extends F > fn ) {
73
- return Monad .super .<F >fmap (fn ).coerce ();
77
+ return MonadRec .super .<F >fmap (fn ).coerce ();
74
78
}
75
79
76
80
/**
@@ -111,7 +115,7 @@ public <F> Choice5<A, B, C, D, F> pure(F f) {
111
115
*/
112
116
@ Override
113
117
public <F > Choice5 <A , B , C , D , F > zip (Applicative <Fn1 <? super E , ? extends F >, Choice5 <A , B , C , D , ?>> appFn ) {
114
- return Monad .super .zip (appFn ).coerce ();
118
+ return MonadRec .super .zip (appFn ).coerce ();
115
119
}
116
120
117
121
/**
@@ -132,15 +136,15 @@ public <F> Lazy<Choice5<A, B, C, D, F>> lazyZip(
132
136
*/
133
137
@ Override
134
138
public <F > Choice5 <A , B , C , D , F > discardL (Applicative <F , Choice5 <A , B , C , D , ?>> appB ) {
135
- return Monad .super .discardL (appB ).coerce ();
139
+ return MonadRec .super .discardL (appB ).coerce ();
136
140
}
137
141
138
142
/**
139
143
* {@inheritDoc}
140
144
*/
141
145
@ Override
142
146
public <F > Choice5 <A , B , C , D , E > discardR (Applicative <F , Choice5 <A , B , C , D , ?>> appB ) {
143
- return Monad .super .discardR (appB ).coerce ();
147
+ return MonadRec .super .discardR (appB ).coerce ();
144
148
}
145
149
146
150
/**
@@ -151,6 +155,23 @@ public <F> Choice5<A, B, C, D, F> flatMap(Fn1<? super E, ? extends Monad<F, Choi
151
155
return match (Choice5 ::a , Choice5 ::b , Choice5 ::c , Choice5 ::d , e -> f .apply (e ).coerce ());
152
156
}
153
157
158
+ /**
159
+ * {@inheritDoc}
160
+ */
161
+ @ Override
162
+ public <F > Choice5 <A , B , C , D , F > trampolineM (Fn1 <? super E , ? extends MonadRec <RecursiveResult <E , F >, Choice5 <A , B , C , D , ?>>> fn ) {
163
+ return match (Choice5 ::a ,
164
+ Choice5 ::b ,
165
+ Choice5 ::c ,
166
+ Choice5 ::d ,
167
+ trampoline (e -> fn .apply (e ).<Choice5 <A , B , C , D , RecursiveResult <E , F >>>coerce ().match (
168
+ a -> terminate (Choice5 .a (a )),
169
+ b -> terminate (Choice5 .b (b )),
170
+ c -> terminate (Choice5 .c (c )),
171
+ d -> terminate (Choice5 .d (d )),
172
+ eRec -> eRec .fmap (Choice5 ::e ))));
173
+ }
174
+
154
175
/**
155
176
* {@inheritDoc}
156
177
*/
0 commit comments