pymaybe
pymaybe copied to clipboard
Not composable: maybe([None])[0].is_none()
- Kubuntu 18.04 x64
- Anaconda 3.6,
pip install pymaybe
-
maybe([None])[0].is_none()
is True. -
maybe([None])[0].get()
raises Exception, despite[None][0]
is None. -
maybe({'a': None})['a'].get()
raises Exception, despite{'a': None}['a']
is None.
https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/
Despite being a maybe "implementation", this library fails to distinguish a missing element from a deliberate None value.
Just change this to return Nothing()
https://github.com/ekampf/pymaybe/blob/f755600f5478b6b595e2100417b39a7bc3de2c6f/pymaybe/init.py#L23-L24
Seems like you're supposed to use the or_else()
method instead of get()
, but then why provide a get()
method anyway?
There is a similar issue also with obj.member = None; maybe(obj).member.get()
.
I think the root cause is maybe(None).get()
raises.
To me it's more logical to have maybe(None).get() == None
.
This can be done if we update the code to have maybe(None) == Something(None)
.