Created
March 24, 2020 14:09
-
-
Save Torvaney/6e7382057422bd4ba1b9af0cd501ac7b to your computer and use it in GitHub Desktop.
This file contains 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 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