Skip to main content

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


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 details)

Uploaded Source

Built Distribution

simple_eff-0.0.1a2-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file simple-eff-0.0.1a2.tar.gz.

File metadata

  • Download URL: simple-eff-0.0.1a2.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Darwin/21.4.0

File hashes

Hashes for simple-eff-0.0.1a2.tar.gz
Algorithm Hash digest
SHA256 48f48d03ee35a34bb59a1e2384657499b6285e86c986c5618bb3b817216e0884
MD5 416e04f44d60fc5a9343a394b9eac4e2
BLAKE2b-256 72a16cdf1989dfb437182923a86849ccadb5a0334525073bf9ca592784e754b3

See more details on using hashes here.

File details

Details for the file simple_eff-0.0.1a2-py3-none-any.whl.

File metadata

  • Download URL: simple_eff-0.0.1a2-py3-none-any.whl
  • Upload date:
  • Size: 2.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Darwin/21.4.0

File hashes

Hashes for simple_eff-0.0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 203fb6c11f4746aed7c57f3d7c9cd112aec6df43fc511e841d347c5e9099dddb
MD5 6b70c15c120a63b940ac56d800febb66
BLAKE2b-256 c28db42e96ee313837264514cc1e2453b6b41e9205469c6e441803abd226ffe7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page