Last active
October 24, 2017 19:31
-
-
Save fengb/26f980d676bd313346828ea065c9e672 to your computer and use it in GitHub Desktop.
This file contains 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 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