Last active
January 7, 2022 22:49
-
-
Save taddeimania/308ef82a450729fa2e89 to your computer and use it in GitHub Desktop.
Proposal for Maybe type in python (True OR False)
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
import ast | |
import random | |
class MaybeType(type): | |
def __repr__(cls): | |
return str(bool(random.randint(0, 1))) | |
def __nonzero__(cls): | |
return ast.literal_eval(repr(cls)) | |
class Maybe(object): | |
__metaclass__ = MaybeType | |
>>> Maybe | |
True | |
>>> Maybe | |
True | |
>>> Maybe | |
False | |
>>> bool(Maybe) | |
False | |
>>> bool(Maybe) | |
True | |
>>> True = Maybe # import chaos | |
>>> True | |
True | |
>>> True | |
True | |
>>> True | |
False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment