Skip to content

Instantly share code, notes, and snippets.

@feymartynov
Created February 28, 2019 20:52
Show Gist options
  • Save feymartynov/c25f264f9f223fcb0d9d0d326a756fd6 to your computer and use it in GitHub Desktop.
Save feymartynov/c25f264f9f223fcb0d9d0d326a756fd6 to your computer and use it in GitHub Desktop.
cat operator in python
class Infix:
def __init__(self, function):
self.function = function
def __rxor__(self, other):
return Infix(lambda x, self=self, other=other: self.function(other, x))
def __xor__(self, other):
return self.function(other)
def __call__(self, value1, value2):
return self.function(value1, value2)
_=Infix(lambda x, y: x * y)
print 2 ^_^ 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment