Skip to content

Instantly share code, notes, and snippets.

@fengb
Last active October 24, 2017 19:31
Show Gist options
  • Save fengb/26f980d676bd313346828ea065c9e672 to your computer and use it in GitHub Desktop.
Save fengb/26f980d676bd313346828ea065c9e672 to your computer and use it in GitHub Desktop.
from functools import partial
class l(object):
def __init__(self, func, *args, **kwargs):
self.func = func
self.args = args
self.kwargs = kwargs
def __ror__(self, lhs):
return self.func(lhs, *args, **kwargs)
"""
Example usage:
>>> import pipe
>>> [1, 2, 3] |pipe.r(filter, lambda x: x % 2) |pipe.r(map, lambda x: x**2)
[1, 9]
"""
class r(object):
def __init__(self, func, *args, **kwargs):
self.func = partial(func, *args, **kwargs)
def __ror__(self, lhs):
return self.func(lhs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment