pymaybe icon indicating copy to clipboard operation
pymaybe copied to clipboard

Not composable: maybe([None])[0].is_none()

Open nyanpasu64 opened this issue 6 years ago • 2 comments

  • 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.

nyanpasu64 avatar Dec 09 '18 03:12 nyanpasu64

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?

akazukin5151 avatar Jun 01 '20 08:06 akazukin5151

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).

georgipopovhs avatar May 08 '24 07:05 georgipopovhs