Encapsulation and decorators made easy.
Project description
Would you rather write
or ...
... 🤔 ?
The encapsulation library
Introducing: the From class.
For maintainable data pipelines.
- Adds new syntactic sugar to python!
- Cleanly abstract side-effects without interrupting control flow
- Elegant decorators included
- Decorate any function with
@to(From)to make it monadic - Explicit function composition
- Currently implemented: Maybe
- Coming soon: Result, IO
Installation
pip install -e encapsulation
Getting started
Get started by
from encapsulation.base import Maybe
Maybe("a") + "b" # outputs <Maybe val=(ab)>
Maybe(None) * 2 # outputs <Nothing val=(None)>
Easy to use decorators that elevate functions to return wrapped values instead:
from encapsulation.base import Maybe, to
def add1(n: int):
return n + 1
@to(Maybe)
def test(s: int):
return s
test(1) << add1 & print << add1 # prints '2', while returning Maybe(3)
You can chain computations using compose(). For example
from encapsulation.base import Just, compose
@to(Just[int])
def add2(s: int):
return s + 2
compose(Just(1), add2, add2) # equals Just(5)
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
encapsulation-0.2.1.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file encapsulation-0.2.1.tar.gz.
File metadata
- Download URL: encapsulation-0.2.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96d8f89cbb024851208ae260cb8ea15e03868d04ac234d8a3bae12f50fd8169f
|
|
| MD5 |
3cfbc4e9c579fa37605fc6be792ab9bb
|
|
| BLAKE2b-256 |
c701535e20c4efd317ca20965b90af958596d39fc9fbd6f0a5cdc60be919a0d2
|
File details
Details for the file encapsulation-0.2.1-py3-none-any.whl.
File metadata
- Download URL: encapsulation-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e355a47af2e0518a58df556147713bb867a93eddd72d716ecbab17c42b8024b4
|
|
| MD5 |
fa29eb9c72be6873d75e24d4e2814e66
|
|
| BLAKE2b-256 |
2b9bd9489c9bd31ac3bd564ff4e62b597d5bfd5058bf63855e4cfa6c54d7071e
|