-
-
Save bofm/9dfcd4dfccbef46e90d92bc46e979fd7 to your computer and use it in GitHub Desktop.
f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
class F: | |
__slots__ = ('fns',) | |
def __init__(self, *fns): | |
self.fns = fns | |
def __call__(self, *args, **kwargs): | |
fns = iter(self.fns) | |
for f in fns: | |
res = f(*args, **kwargs) | |
for f in fns: | |
res = f(res) | |
return res | |
return F(partial(*args, **kwargs)) | |
def rcompose(self, *fns): | |
return F(*self.fns, *fns) | |
def compose(self, *fns): | |
return F(*reversed(fns), *self.fns) | |
c = comp = __lshift__ = compose | |
rc = rcomp = __rshift__ = rcompose | |
def __repr__(self): | |
return f'F{self.fns!r}' | |
f = F() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment