None
Project description
Eff
Eff is a Python library to work with algebraic effects.
Algbraic effects are all side-effects of a piece of code, like reading a user input, writing a text on the screen, doing network requests, reading a file etc. Eff allows to easily handle such effects making the code cleaner and testing easier.
Features:
- Easy to understand. You don't need to read long scientific papers to understand how to use the library and what it does.
- Easy to integrate. If you decided to add a logger into a function, changes will be minimal, no need to pass the logger down through the whole call stack.
- Fast. The classic approach for handling algebraic effects is using coroutines or exceptions. This library uses global shared state instead which doesn't require to unwrap the whole call stack at runtime.
- Type-safe. Effect handlers container is just a class. Annotate effect handlers type to make their usage type-safe.
Installation
python3 -m pip install --user eff
Usage
from io import StringIO
from typing import Callable
import eff
class Eff(eff.ects):
show: Callable
# Use global effects manager in a function.
def greet(username: str) -> None:
Eff.show(f'Hello, {username}!')
# Provide actual side-effects handlers
# for the project prod entry point.
def main() -> None:
with Eff(show=print):
greet('World')
# Mock side-effects in tests.
def test_greet() -> None:
stream = StringIO()
with Eff(show=stream.write):
greet('World')
stream.seek(0)
assert stream.read() == 'Hello, World!'
if __name__ == '__main__':
main()
Further reading
You don't have to read it but it's a good reading for better understanding of the motivation behind the library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
eff-1.0.0.tar.gz
(4.0 kB
view details)
Built Distribution
eff-1.0.0-py3-none-any.whl
(4.1 kB
view details)
File details
Details for the file eff-1.0.0.tar.gz
.
File metadata
- Download URL: eff-1.0.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: DepHell/0.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2d8698c8c3fc056235ddc86e48046f8294a44d8f78d93306ef75c4127b4652f |
|
MD5 | 07b3c0b99537b597df62cd4bd1b15cc4 |
|
BLAKE2b-256 | 1e760d137c6919eedb06d2dc1e5dc69903218eeb2085b6b060ab8f06b265cb4e |
File details
Details for the file eff-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: eff-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: DepHell/0.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad5e686eaf58e292c2231a152cde31cf4ee780d4906c1b8a116d5cfbec5cbd94 |
|
MD5 | 4ee369e05cdab8440461b6df0eb6887d |
|
BLAKE2b-256 | a11ace172efccb099e8604c646b77a1ba190adcc33ae48db01f98c4fb7fd2ae9 |