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
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
continuationmonad-0.0.2.tar.gz
(12.2 kB
view hashes)
Built Distribution
Close
Hashes for continuationmonad-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b860835c8f195072abf914aa2f8f47ee40f94015f560f0f7c3ed9771261e9b8c |
|
MD5 | 001ae2d847d52548c68395951d333a4d |
|
BLAKE2b-256 | 193f3741b907394877d3781bb30840970dc63478159e8bc84de28d0a9659600a |