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

Uploaded Source

Built Distribution

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

Uploaded Python 3

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