Guest User

Untitled

a guest
Jun 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. from functools import partial
  2.  
  3. class Infix(object):
  4. def __init__(self, func):
  5. self.func = func
  6. def __or__(self, other):
  7. return self.func(other)
  8. def __ror__(self, other):
  9. return Infix(partial(self.func, other))
  10. def __call__(self, v1, v2):
  11. return self.func(v1, v2)
  12.  
  13. @Infix
  14. def o(f,g):
  15. return lambda x: f(g(x))
  16.  
  17. # Example of use (composition with |o|)
  18. #
  19. # >> f = lambda x: x*3
  20. # >> g = lambda x: x-15
  21. # >> h = f |o| g
Add Comment
Please, Sign In to add comment