Skip to content

Instantly share code, notes, and snippets.

@Torvaney
Created March 24, 2020 14:09
Show Gist options
  • Save Torvaney/6e7382057422bd4ba1b9af0cd501ac7b to your computer and use it in GitHub Desktop.
Save Torvaney/6e7382057422bd4ba1b9af0cd501ac7b to your computer and use it in GitHub Desktop.
class Just:
def __init__(self, value):
self.value = value
def __repr__(self):
return f'Just({self.value.__repr__()})'
def __eq__(self, other):
if isinstance(other, Just):
return self.value == other.value
return False
def map(self, f):
if self.value is None:
return Nothing()
if f(self.value) is None:
return Nothing()
return Just(f(self.value))
class Nothing:
def __repr__(self):
return 'Nothing'
def __eq__(self, other):
if isinstance(other, Nothing):
return True
return False
def map(self, f):
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment