Skip to main content
https://img.shields.io/pypi/v/cans.svg?style=flat-square https://img.shields.io/pypi/l/cans.svg?style=flat-square https://img.shields.io/pypi/pyversions/cans.svg?style=flat-square https://img.shields.io/readthedocs/cans.svg?style=flat-square https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square

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

Metadata

Release files for cans 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cans 0.1.3
File Size Uploaded
cans-0.1.3.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cans 0.1.3
File Interpreter ABI Platform
cans-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / cans-0.1.3.tar.gz

Download URL cans-0.1.3.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
865983fc617f662518e0d163f6c9b71e7f8d4042e99b2b1b138f50a69bcc78f9
BLAKE2b-256 checksum
How to use checksums
481f0ff4ed5e9a312f6468fd8cb1b887f3930cf85522b0bd704b54606749e568
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.8.1 Darwin/20.3.0

Release files / cans-0.1.3-py3-none-any.whl

Download URL cans-0.1.3-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
161b7a71177f601b775ccc1429b7ad12624bd36462a9ffb9652fdb292226864f
BLAKE2b-256 checksum
How to use checksums
7cbec715e98b56bb5319be128ffd587e25c0117e5467f890b7fbc1affc1389aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.8.1 Darwin/20.3.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page