Robust, composable, functional containers
Project description
Simple, functional, composable containers like Maybe. Properly typed and supports pattern matching on Python 3.10+. Inspired by the containers in the Rust standard library.
Quickstart
>>> from cans import Just, Nothing, Maybe
>>> greeting: Maybe[str] = Just("Hello")
...
>>> def first(m: list[str]) -> Maybe[str]:
... return Just(m[0]) if m else Nothing()
...
>>> first(["howdy", "hi", "hello"]).map(str.title).unwrap()
"Howdy"
...
>>> # Python 3.10+ only
>>> match greeting:
... case Just(n):
... print(f"{greeting} world!")
... case Nothing():
... print("Hi world!")
Hello world!
Among the supported methods are flatmap, filter, zip, as well as the relevant collection APIs. See the documentation for a complete overview.
Todo
Other containers
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cans-0.1.3.tar.gz
(6.8 kB
view details)
Built Distribution
cans-0.1.3-py3-none-any.whl
(7.7 kB
view details)
File details
Details for the file cans-0.1.3.tar.gz
.
File metadata
- Download URL: cans-0.1.3.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.1 Darwin/20.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 865983fc617f662518e0d163f6c9b71e7f8d4042e99b2b1b138f50a69bcc78f9 |
|
MD5 | a555f4d8e5f6eae611f6d839bf784679 |
|
BLAKE2b-256 | 481f0ff4ed5e9a312f6468fd8cb1b887f3930cf85522b0bd704b54606749e568 |
File details
Details for the file cans-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: cans-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.1 Darwin/20.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 161b7a71177f601b775ccc1429b7ad12624bd36462a9ffb9652fdb292226864f |
|
MD5 | a48d59be5d5eeae958d3d1a9ef6945ce |
|
BLAKE2b-256 | 7cbec715e98b56bb5319be128ffd587e25c0117e5467f890b7fbc1affc1389aa |