A namedtuple-style library for defining immutable sum types in Python.
We only ever need one None
, ()
, etc. After this update, variants with no payload (i.e. Nothing
from Maybe[A]
) can behave that way: we do Maybe.Nothing
(access the singleton immutable value) instead of Maybe.Nothing()
(create a new instance). This is enabled with the new constants
option:
class Maybe(sumtype, constants=True):
def Just(val): ...
Nothing = … # new syntax
or by inheriting from sumtype.future.sumtype
instead of sumtype.sumtype
(This will be the default behavior after 1.0).
Note: it isn't currently guaranteed that there only ever exists one Maybe.Nothing
- currently, _replace()
, .__copy__()
etc. will produce another instance, so you shouldn't rely on the is
operator. This may or may not change in the future.
Fixed code-block indentation in the README, because it looked bad on PyPI
Fixed typo in README
Added missing typeguard
dependency to setup.py
Added field typechecking based on annotations (see README)