functorial
Functional-programming concepts for Python: typeclasses (Functor, Applicative,
Monad, Foldable, Traversable, Alternative, ...), standard FP data types
(Maybe, Either, List, Dict, NTuple, trees, IO, Reader, Writer,
State), and a profunctor-based optics library (lenses, prisms, traversals,
folds, isos, and their indexed variants).
This is an evolving, educational project — the API is still settling and not everything on the roadmap is implemented yet. Feedback and issues are welcome.
Installation
pip install functorial
# or
uv add functorial
Requires Python 3.12+.
Quick taste
from functorial.maybe import Some, Nothing
from functorial.optics.lens import lens
from functorial.optics.getter import view
from functorial.optics.setter import over
# Maybe: a Functor/Applicative/Monad/Traversable
Some(3).map(lambda x: x + 1) # Some(4)
Nothing().map(lambda x: x + 1) # Nothing()
# Optics: compose lenses with @, act on them with view/over
fst = lens(lambda s: s[0], lambda s, b: (b, s[1]))
snd = lens(lambda s: s[1], lambda s, b: (s[0], b))
view(fst)((1, 2)) # 1
over(fst @ snd, str)(((1, 2), 3)) # ((1, '2'), 3)
Development
uv sync
uv run pytest
License
MIT — see LICENSE.
Release files for functorial 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| functorial-0.1.1.tar.gz | 95.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| functorial-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 204.8 kB
Release files / functorial-0.1.1.tar.gz
| Download URL | functorial-0.1.1.tar.gz |
|---|---|
| Size | 95.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51d1b798ce792beea93b564a7d65c987595563a1d28d07ba60f15073251b2a36
|
|
BLAKE2b-256 checksum How to use checksums |
e12b7b9dc15cbdc6ed65bc6b2d3a165a6a6ae59a405a3f5122404f5a1b655054
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / functorial-0.1.1-py3-none-any.whl
| Download URL | functorial-0.1.1-py3-none-any.whl |
|---|---|
| Size | 109.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe2d57b0b11ab630340d77163c5b757067d7d8b9de89256659709ca97f6ac6f3
|
|
BLAKE2b-256 checksum How to use checksums |
8aa139f9bf226385706af5932dc850c6ce458a8b9fa1fa4e16d01064cbf248e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|