Skip to content

Commit 1bae388

Browse files
committed
improve lazify support in some function composition utilities
1 parent 24ad34b commit 1bae388

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

unpythonic/fun.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -687,15 +687,14 @@ def andf(*fs): # Racket: conjoin
687687
assert andf(lambda x: isinstance(x, int), lambda x: x % 2 == 0)(42) is True
688688
assert andf(lambda x: isinstance(x, int), lambda x: x % 2 == 0)(43) is False
689689
"""
690+
@passthrough_lazy_args
690691
def conjoined(*args, **kwargs):
691692
b = True
692693
for f in fs:
693694
b = b and maybe_force_args(f, *args, **kwargs)
694695
if not b:
695696
return False
696697
return b
697-
if all(islazy(f) for f in fs):
698-
conjoined = passthrough_lazy_args(conjoined)
699698
return conjoined
700699

701700
def orf(*fs): # Racket: disjoin
@@ -715,15 +714,14 @@ def orf(*fs): # Racket: disjoin
715714
assert orf(isstr, iseven)("foo") is True
716715
assert orf(isstr, iseven)(None) is False # neither condition holds
717716
"""
717+
@passthrough_lazy_args
718718
def disjoined(*args, **kwargs):
719719
b = False
720720
for f in fs:
721721
b = b or maybe_force_args(f, *args, **kwargs)
722722
if b:
723723
return b
724724
return False
725-
if all(islazy(f) for f in fs):
726-
disjoined = passthrough_lazy_args(disjoined)
727725
return disjoined
728726

729727
def _make_compose1(direction):
@@ -769,8 +767,7 @@ def compose1(fs):
769767
# - if fs is empty, we output None
770768
# - if fs contains only one item, we output it as-is
771769
composed = reducel(compose1_two, fs) # op(elt, acc)
772-
if all(islazy(f) for f in fs):
773-
composed = passthrough_lazy_args(composed)
770+
composed = passthrough_lazy_args(composed)
774771
return composed
775772
return compose1
776773

@@ -858,8 +855,7 @@ def compose(fs):
858855
"""
859856
fs = force(fs)
860857
composed = reducel(compose_two, fs) # op(elt, acc)
861-
if all(islazy(f) for f in fs):
862-
composed = passthrough_lazy_args(composed)
858+
composed = passthrough_lazy_args(composed)
863859
return composed
864860
return compose
865861

0 commit comments

Comments
 (0)