Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Last active April 26, 2021 20:54
Show Gist options
  • Save samueleresca/cfab5d1f200148a1e292a595f5779595 to your computer and use it in GitHub Desktop.
Save samueleresca/cfab5d1f200148a1e292a595f5779595 to your computer and use it in GitHub Desktop.
"""
Original code available at: https://github.com/mwhittaker/quoracle
"""
class Expr(Generic[T]):
def __add__(self, rhs: 'Expr[T]') -> 'Expr[T]':
def _or(lhs: Expr[T], rhs: Expr[T]) -> 'Or[T]':
if isinstance(lhs, Or) and isinstance(rhs, Or):
return Or(lhs.es + rhs.es)
elif isinstance(lhs, Or):
return Or(lhs.es + [rhs])
elif isinstance(rhs, Or):
return Or([lhs] + rhs.es)
else:
return Or([lhs, rhs])
return _or(self, rhs)
def __mul__(self, rhs: 'Expr[T]') -> 'Expr[T]':
def _and(lhs: Expr[T], rhs: Expr[T]) -> 'And[T]':
if isinstance(lhs, And) and isinstance(rhs, And):
return And(lhs.es + rhs.es)
elif isinstance(lhs, And):
return And(lhs.es + [rhs])
elif isinstance(rhs, And):
return And([lhs] + rhs.es)
else:
return And([lhs, rhs])
return _and(self, rhs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment