Skip to content

Instantly share code, notes, and snippets.

@RonnyPfannschmidt
Last active August 13, 2016 10:12
Show Gist options
  • Save RonnyPfannschmidt/809d37809eca426643c252dccd2e706e to your computer and use it in GitHub Desktop.
Save RonnyPfannschmidt/809d37809eca426643c252dccd2e706e to your computer and use it in GitHub Desktop.
@tagged
class Maybe(object):
@construct
def Nothing(self):
pass
@construct
def Just(self, data: int):
pass
Maybe = attr.union('Maybe')
@Maybe.register
@attr.s
class Nothing(object):
def map(self, func):
return self
@Maybe.register
@attr.s
class Just(object):
data = attr.ib()
def map(self, func):
return Just(func(self.data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment