Skip to main content

A library that encapsulates callback functions within a continuation monad, utilizing a trampoline scheduler to enable stack-safe computations.

Project description

Continuation-Monad

A Python library that encapsulates callback functions within a continuation monad, utilizing a trampoline scheduler to enable stack-safe computations.

Installation

You can install Continuation-Monad using pip:

pip install continuationmonad

Example

import continuationmonad


def count_down(count: int):
    print(f'{count=}')

    if count == 0:
        return continuationmonad.from_(count)
    
    else:
        # schedule recursive call on the trampoline
        return continuationmonad.tail_rec(lambda: count_down(count - 1))

trampoline = continuationmonad.init_main_trampoline()

def action():
    def on_next(_, value: int):
        print(f'{value=}')
        return trampoline.stop()

    continuation = count_down(5)
    return continuation.subscribe(trampoline, on_next)

trampoline.run(action)

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

continuationmonad-0.0.2.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

continuationmonad-0.0.2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file continuationmonad-0.0.2.tar.gz.

File metadata

  • Download URL: continuationmonad-0.0.2.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for continuationmonad-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2085f39ee1058e77d4caf2d9e1e4eefa1811c005af6b2d47b4bd7c371d9f8214
MD5 40d7bc395c1d710d76a66a60af226c2e
BLAKE2b-256 e1f7aa02a799493c2488bab1a59aa00766f0e54546679d66c47a1d0e684981a4

See more details on using hashes here.

Provenance

File details

Details for the file continuationmonad-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for continuationmonad-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b860835c8f195072abf914aa2f8f47ee40f94015f560f0f7c3ed9771261e9b8c
MD5 001ae2d847d52548c68395951d333a4d
BLAKE2b-256 193f3741b907394877d3781bb30840970dc63478159e8bc84de28d0a9659600a

See more details on using hashes here.

Provenance

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