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.4
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.4.tar.gz | 128.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| functorial-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 240.1 kB
Release files / functorial-0.1.4.tar.gz
| Download URL | functorial-0.1.4.tar.gz |
|---|---|
| Size | 128.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
544a01ba4991a34ce628c8ef38ab90830fc0e002f4dece335b144887394ad9f5
|
|
BLAKE2b-256 checksum How to use checksums |
12b0ef653296223762b10551655840605b88a22c64adb1f0583f28cf945c112f
|
| 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.4-py3-none-any.whl
| Download URL | functorial-0.1.4-py3-none-any.whl |
|---|---|
| Size | 112.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9643dfa78ba3bb9df09cddcf949c2cbe93b58a12ee6dab211b2df84a2c677d93
|
|
BLAKE2b-256 checksum How to use checksums |
04369bc8f7f9eab9c0e5612cd404adf6e689760607ab5e926311b62d96302006
|
| 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}
|