Skip to main content

Robust, composable, functional containers

Project description

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

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 hashes)

Uploaded Source

Built Distribution

cans-0.1.3-py3-none-any.whl (7.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page