Skip to content

Instantly share code, notes, and snippets.

@lbolla
Created May 25, 2016 13: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 lbolla/e7396c77e63b4c168cce27002f588494 to your computer and use it in GitHub Desktop.
Save lbolla/e7396c77e63b4c168cce27002f588494 to your computer and use it in GitHub Desktop.
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 P(x, f):
return f(x)
def inc(x):
return x + 1
def dec(x):
return x - 1
def square(x):
return x ** 2
print 5 |P| inc |P| dec |P| square
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment