ekampf / pymaybe

A Python implementation of the Maybe pattern
BSD 3-Clause "New" or "Revised" License
208 stars 6 forks source link

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

Open nyanpasu64 opened 5 years ago

nyanpasu64 commented 5 years ago

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.

akazukin5151 commented 4 years ago

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?

georgipopovhs commented 2 months ago

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