@@ -46,7 +46,7 @@ public <R> R fold(final F<Normal<A>, R> n,
4646 // The monadic bind constructs a new Codense whose subcomputation is still `sub`, and Kleisli-composes the
4747 // continuations.
4848 public <B > Trampoline <B > bind (final F <A , Trampoline <B >> f ) {
49- return codense (sub , o -> suspend (P . lazy (( ) -> cont .f (o ).bind (f ) )));
49+ return codense (sub , o -> suspend (( ) -> cont .f (o ).bind (f )));
5050 }
5151
5252 // The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result
@@ -126,6 +126,16 @@ public static <A> Trampoline<A> pure(final A a) {
126126 return new Pure <>(a );
127127 }
128128
129+ /**
130+ * Suspends the given computation in a thunk.
131+ *
132+ * @param a A trampoline suspended in a thunk.
133+ * @return A trampoline whose next step runs the given thunk.
134+ */
135+ public static <A > Trampoline <A > suspend (final F0 <Trampoline <A >> a ) {
136+ return new Suspend <>(P .lazy (a ));
137+ }
138+
129139 /**
130140 * Suspends the given computation in a thunk.
131141 *
@@ -136,6 +146,7 @@ public static <A> Trampoline<A> suspend(final P1<Trampoline<A>> a) {
136146 return new Suspend <>(a );
137147 }
138148
149+
139150 /**
140151 * @return The first-class version of `suspend`.
141152 */
@@ -255,15 +266,15 @@ public final <B, C> Trampoline<C> zipWith(final Trampoline<B> b, final F2<A, B,
255266 final Either <P1 <Trampoline <B >>, B > eb = b .resume ();
256267 for (final P1 <Trampoline <A >> x : ea .left ()) {
257268 for (final P1 <Trampoline <B >> y : eb .left ()) {
258- return suspend (x .bind (y , F2Functions .curry ((ta , tb ) -> suspend (P . lazy (( ) -> ta .zipWith (tb , f ) )))));
269+ return suspend (x .bind (y , F2Functions .curry ((ta , tb ) -> suspend (( ) -> ta .zipWith (tb , f )))));
259270 }
260271 for (final B y : eb .right ()) {
261272 return suspend (x .map (ta -> ta .map (F2Functions .f (F2Functions .flip (f ), y ))));
262273 }
263274 }
264275 for (final A x : ea .right ()) {
265276 for (final B y : eb .right ()) {
266- return suspend (P . lazy (( ) -> pure (f .f (x , y ) )));
277+ return suspend (( ) -> pure (f .f (x , y )));
267278 }
268279 for (final P1 <Trampoline <B >> y : eb .left ()) {
269280 return suspend (y .map (liftM2 (F2Functions .curry (f )).f (pure (x ))));
0 commit comments