A simple Maybe (Option) type for Python 3 inspired by Rust, fully type annotated.
Latest release:
sh
$ pip install rustedpy-maybe
Latest GitHub master
branch version:
sh
$ pip install git+https://github.com/rustedpy/maybe
Experimental. API subject to change.
The idea is that a possible value can be either Some(value)
or Nothing()
, with a way to differentiate between the two. Some
and Nothing
are both classes encapsulating a possible value.
Example usage,
Python
from maybe import Nothing, Some
o = Some('yay') n = Nothing() assert o.unwrap_or_else(str.upper) == 'yay' assert n.unwrap_or_else(lambda: 'default') == 'default'
MIT License