Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import partial
- class Infix(object):
- def __init__(self, func):
- self.func = func
- def __or__(self, other):
- return self.func(other)
- def __ror__(self, other):
- return Infix(partial(self.func, other))
- def __call__(self, v1, v2):
- return self.func(v1, v2)
- @Infix
- def o(f,g):
- return lambda x: f(g(x))
- # Example of use (composition with |o|)
- #
- # >> f = lambda x: x*3
- # >> g = lambda x: x-15
- # >> h = f |o| g
Add Comment
Please, Sign In to add comment