Created
August 30, 2018 12:35
-
-
Save adrianparvino/3c4fccfc37c0db85485f24e925388fa3 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
class Either(object): | |
pass | |
class Left(Either): | |
def __init__(self, v): self.v = v | |
def is_left(self): return True | |
def is_right(self): return False | |
def value(self): return self.v | |
class Right(Either): | |
def __init__(self, v): self.v = v | |
def is_left(self): return False | |
def is_right(self): return True | |
def value(self): return self.v | |
errval = Left("This value is unoccupied!") | |
goodval = Right(1) | |
def doSomething(val): | |
if val.is_left(): | |
print(val.value()) | |
exit() | |
print(val.value() + 1) | |
doSomething(goodval) | |
doSomething(errval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment