A simple tiny algebraic effects library for Python
Project description
Simple Eff
A Simple Tiny (only <100 lines) Algebraic Effects Library for Python.
from simple_eff import Effect, eff
not_integer = Effect()
def parse_int(str):
try:
return int(str)
except:
return None
@eff
def sum_lines(s: str) -> int:
lines = s.split()
sum = 0
for line in lines:
match parse_int(line):
case None:
sum += yield not_integer.perform(line)
case num:
sum += num
return sum
def handle_notinteger(k, v):
print(f"Parse Error: {v} is not an integer.")
return k(0)
if __name__ == '__main__':
twelve = sum_lines("1\n2\nthree\n4\n5")
twelve.on(not_integer, handle_notinteger)
ret = twelve.run()
print(f"Sum: {ret}")
Acknowledgement
This library is ...
- inspired by effective-rust for the API design.
- heavily based on ruff for the implementation.
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
simple-eff-0.0.1a2.tar.gz
(2.2 kB
view hashes)
Built Distribution
Close
Hashes for simple_eff-0.0.1a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 203fb6c11f4746aed7c57f3d7c9cd112aec6df43fc511e841d347c5e9099dddb |
|
MD5 | 6b70c15c120a63b940ac56d800febb66 |
|
BLAKE2b-256 | c28db42e96ee313837264514cc1e2453b6b41e9205469c6e441803abd226ffe7 |