Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ariebovenberg/cans
Simple, functional, composable containers
https://github.com/ariebovenberg/cans
functional-programming maybe-monad mypy pattern-matching python
Last synced: about 1 month ago
JSON representation
Simple, functional, composable containers
- Host: GitHub
- URL: https://github.com/ariebovenberg/cans
- Owner: ariebovenberg
- License: mit
- Created: 2021-04-04T11:13:26.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-07T07:46:21.000Z (about 2 years ago)
- Last Synced: 2024-08-09T10:29:06.103Z (3 months ago)
- Topics: functional-programming, maybe-monad, mypy, pattern-matching, python
- Language: Python
- Homepage: https://cans.rtfd.io
- Size: 90.8 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
🥫 Cans
=======.. image:: https://img.shields.io/pypi/v/cans.svg?style=flat-square
:target: https://pypi.python.org/pypi/cans.. image:: https://img.shields.io/pypi/l/cans.svg?style=flat-square
:target: https://pypi.python.org/pypi/cans.. image:: https://img.shields.io/pypi/pyversions/cans.svg?style=flat-square
:target: https://pypi.python.org/pypi/cans.. image:: https://img.shields.io/readthedocs/cans.svg?style=flat-square
:target: http://cans.readthedocs.io/.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square
:target: https://github.com/psf/blackSimple, 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
----------.. code-block:: python3
>>> 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