fptools.maybe¶
Pythonic FP - Maybe Monad
- class pythonic_fp.fptools.maybe.MayBe¶
- class pythonic_fp.fptools.maybe.MayBe(value: D)
Maybe monad, data structure wrapping a potentially missing value.
Immutable semantics
can store any item of any type, including
None
can store any value of any type with one exception
immutable semantics, therefore made covariant
Warning
Hashability invalidated if contained value is not hashable.
- get() D | Never ¶
- get(alt: D) D
Return the contained value if it exists, otherwise an alternate value.
Warning
Unsafe method
get
. Will raiseValueError
if MayBe empty and an alt return value not given. Best practice is to first check the MayBe in a boolean context.- Raises:
ValueError – when an alternate value is not provided but needed