A Python implementation of a Maybe type that represents potentially missing values
Project description
maybedata
This is a package that implements a Maybe data type in Python that represents values that might or might not exist.
It is implemented as a class hierarchy with an abstract base class Maybe
. This class is not constructible, but can be called to construct members of its subclasses, Just
and Nothing
.
All methods are documented, feel free to call help()
on the classes!
Call Maybe(value)
or Just(value)
to create a value that is present.
Call Maybe()
or Nothing()
to create a missing value.
Check maybe.present
to find out if a value is present.
Access maybe.value
to get the value if it is present.
Call maybe.assume_present()
to raise an exception if the value is not present.
Call maybe.get(default)
to get the value or a default value.
Maybe
and Just
are generic classes if you use type hinting.
Just
and Nothing
support pattern matching.
Maybe
, Just
, and Nothing
support len()
, bool()
, hash()
, iter()
, in
, and ==
.
The method maybe.alternatively()
can be expressed using |
.
The method maybe.then()
can be expressed using >>
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file maybedata-0.8.tar.gz
.
File metadata
- Download URL: maybedata-0.8.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 406a23dd10a02b24c2a143284bb1a82830570bb565c37fc45cd9021abdae0adf |
|
MD5 | 8b16cd3a05ab07f3d5b73f25234c5657 |
|
BLAKE2b-256 | 312af5bf0b108d48f363a908ec926452dc7b634f85020f3d20a4cd194b06ebb2 |
File details
Details for the file maybedata-0.8-py3-none-any.whl
.
File metadata
- Download URL: maybedata-0.8-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd49c748ff185a24255f203bfcee38bf2839b10a67487308b7a544b55231f05 |
|
MD5 | 93dc14f5c06497d0f5420c98db0b5e8b |
|
BLAKE2b-256 | 641f844ff83384bb9ce27f4f2e1c31881b45001df5013b77993f5ddb62fb5a16 |