6
6
import com .jnape .palatable .lambda .adt .hlist .HList ;
7
7
import com .jnape .palatable .lambda .adt .hlist .Tuple4 ;
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 .Functor ;
13
14
import com .jnape .palatable .lambda .functor .builtin .Lazy ;
14
15
import com .jnape .palatable .lambda .monad .Monad ;
16
+ import com .jnape .palatable .lambda .monad .MonadRec ;
15
17
import com .jnape .palatable .lambda .traversable .Traversable ;
16
18
17
19
import java .util .Objects ;
18
20
19
21
import static com .jnape .palatable .lambda .functions .builtin .fn2 .Into4 .into4 ;
22
+ import static com .jnape .palatable .lambda .functions .recursion .RecursiveResult .terminate ;
23
+ import static com .jnape .palatable .lambda .functions .recursion .Trampoline .trampoline ;
20
24
import static com .jnape .palatable .lambda .functor .builtin .Lazy .lazy ;
21
25
22
26
/**
31
35
*/
32
36
public abstract class Choice4 <A , B , C , D > implements
33
37
CoProduct4 <A , B , C , D , Choice4 <A , B , C , D >>,
34
- Monad <D , Choice4 <A , B , C , ?>>,
38
+ MonadRec <D , Choice4 <A , B , C , ?>>,
35
39
Bifunctor <C , D , Choice4 <A , B , ?, ?>>,
36
40
Traversable <D , Choice4 <A , B , C , ?>> {
37
41
@@ -70,7 +74,7 @@ public Choice3<A, B, C> converge(Fn1<? super D, ? extends CoProduct3<A, B, C, ?>
70
74
*/
71
75
@ Override
72
76
public final <E > Choice4 <A , B , C , E > fmap (Fn1 <? super D , ? extends E > fn ) {
73
- return Monad .super .<E >fmap (fn ).coerce ();
77
+ return MonadRec .super .<E >fmap (fn ).coerce ();
74
78
}
75
79
76
80
/**
@@ -108,7 +112,7 @@ public <E> Choice4<A, B, C, E> pure(E e) {
108
112
*/
109
113
@ Override
110
114
public <E > Choice4 <A , B , C , E > zip (Applicative <Fn1 <? super D , ? extends E >, Choice4 <A , B , C , ?>> appFn ) {
111
- return Monad .super .zip (appFn ).coerce ();
115
+ return MonadRec .super .zip (appFn ).coerce ();
112
116
}
113
117
114
118
/**
@@ -128,15 +132,15 @@ public <E> Lazy<Choice4<A, B, C, E>> lazyZip(
128
132
*/
129
133
@ Override
130
134
public <E > Choice4 <A , B , C , E > discardL (Applicative <E , Choice4 <A , B , C , ?>> appB ) {
131
- return Monad .super .discardL (appB ).coerce ();
135
+ return MonadRec .super .discardL (appB ).coerce ();
132
136
}
133
137
134
138
/**
135
139
* {@inheritDoc}
136
140
*/
137
141
@ Override
138
142
public <E > Choice4 <A , B , C , D > discardR (Applicative <E , Choice4 <A , B , C , ?>> appB ) {
139
- return Monad .super .discardR (appB ).coerce ();
143
+ return MonadRec .super .discardR (appB ).coerce ();
140
144
}
141
145
142
146
/**
@@ -161,6 +165,19 @@ AppTrav extends Applicative<TravB, App>> AppTrav traverse(Fn1<? super D, ? exten
161
165
d -> fn .apply (d ).<Choice4 <A , B , C , E >>fmap (Choice4 ::d ).<TravB >fmap (Functor ::coerce ).coerce ());
162
166
}
163
167
168
+ @ Override
169
+ public <E > Choice4 <A , B , C , E > trampolineM (
170
+ Fn1 <? super D , ? extends MonadRec <RecursiveResult <D , E >, Choice4 <A , B , C , ?>>> fn ) {
171
+ return match (Choice4 ::a ,
172
+ Choice4 ::b ,
173
+ Choice4 ::c ,
174
+ trampoline (d -> fn .apply (d ).<Choice4 <A , B , C , RecursiveResult <D , E >>>coerce ()
175
+ .match (a -> terminate (a (a )),
176
+ b -> terminate (b (b )),
177
+ c -> terminate (c (c )),
178
+ dOrE -> dOrE .fmap (Choice4 ::d ))));
179
+ }
180
+
164
181
/**
165
182
* Static factory method for wrapping a value of type <code>A</code> in a {@link Choice4}.
166
183
*
0 commit comments