Last active
April 26, 2021 20:54
-
-
Save samueleresca/cfab5d1f200148a1e292a595f5779595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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