Skip to content

Instantly share code, notes, and snippets.

@bofm
Last active June 28, 2020 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bofm/9dfcd4dfccbef46e90d92bc46e979fd7 to your computer and use it in GitHub Desktop.
Save bofm/9dfcd4dfccbef46e90d92bc46e979fd7 to your computer and use it in GitHub Desktop.
f
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