Skip to content

Instantly share code, notes, and snippets.

@adrianparvino
Created August 30, 2018 12:35
Show Gist options
  • Save adrianparvino/3c4fccfc37c0db85485f24e925388fa3 to your computer and use it in GitHub Desktop.
Save adrianparvino/3c4fccfc37c0db85485f24e925388fa3 to your computer and use it in GitHub Desktop.
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