@@ -166,7 +166,10 @@ def pipe1(value0, *bodys):
166166 # def x(loop, update, acc):
167167 # return loop(update(acc))
168168 # return x
169- x = value0
169+
170+ # This is forced when it is passed to an eager body (or when a lazy body uses it),
171+ # but we force it here just for symmetry with the multi-arg version of `pipe`.
172+ x = force1 (value0 )
170173 for update in bodys :
171174 update = force1 (update )
172175 x = maybe_force_args (update , x )
@@ -268,7 +271,12 @@ def nextfibo(state):
268271 v = self ._x
269272 for g in self ._funcs :
270273 v = maybe_force_args (g , v )
271- return v
274+ # In `unpythonic`, return values are never implicitly lazy.
275+ # The final result here is a return value.
276+ #
277+ # It is legal to pipe the initial value immediately to `exitpipe`;
278+ # in that case, in a `with lazify` block, it will be a promise.
279+ return force (v )
272280 # just pass on the reference to the original x.
273281 cls = self .__class__
274282 return cls (x = self ._x , _funcs = self ._funcs + (force1 (f ),))
@@ -323,7 +331,10 @@ def pipe(values0, *bodys):
323331 lambda x, y, s: Values(x + y, s))
324332 assert (a, b) == (13, "got foo")
325333 """
326- xs = values0
334+ # We must force `values0` to analyze it, because we treat `Values` objects separately.
335+ # Otherwise, in a `with lazify` block, the lazified `Values` object will get passed as
336+ # one argument to the first body - not what we want.
337+ xs = force1 (values0 )
327338 n = len (bodys )
328339 for k , update in enumerate (bodys ):
329340 islast = (k == n - 1 )
@@ -457,13 +468,20 @@ def __or__(self, f):
457468 vs = self ._xs
458469 for g in self ._funcs :
459470 if isinstance (vs , Values ):
460- vs = g ( * vs .rets , ** vs .kwrets )
471+ vs = maybe_force_args ( g , * vs .rets , ** vs .kwrets )
461472 else :
462- vs = g ( vs )
473+ vs = maybe_force_args ( g , vs )
463474 if isinstance (vs , Values ):
464- return vs if vs .kwrets or len (vs .rets ) > 1 else vs [0 ]
475+ ret = vs if vs .kwrets or len (vs .rets ) > 1 else vs [0 ]
465476 else :
466- return vs
477+ ret = vs
478+ # In `unpythonic`, return values are never implicitly lazy.
479+ # The final result here is a return value.
480+ #
481+ # It is legal to pipe the initial value immediately to `exitpipe`;
482+ # in that case, in a `with lazify` block, it will be a promise
483+ # (or a `Values` of several promises).
484+ return force (ret )
467485 # just pass on the references to the original xs.
468486 cls = self .__class__
469487 return cls (* self ._xs .rets , _funcs = self ._funcs + (force1 (f ),), ** self ._xs .kwrets )
0 commit comments