Skip to content

Instantly share code, notes, and snippets.



Last active Jun 28, 2020
What would you like to do?
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