phadej/trampa
Trampolines, to emulate tail-recursion.
{ "createdAt": "2015-07-14T08:04:12Z", "defaultBranch": "master", "description": "Trampolines, to emulate tail-recursion.", "fullName": "phadej/trampa", "homepage": null, "language": "JavaScript", "name": "trampa", "pushedAt": "2018-10-31T16:02:14Z", "stargazersCount": 14, "topics": [], "updatedAt": "2024-09-17T11:32:20Z", "url": "https://github.com/phadej/trampa"}trampa
Section titled “trampa”Trampolines, to emulate tail-call recursion.
Synopsis
Section titled “Synopsis”var trampa = require("trampa");
function loop(n, acc) { return n === 0 ? trampa.wrap(acc) : trampa.lazy(function () { return loop(n - 1, acc + 1); });}
loop(123456789, 0).run(); // doesn't cause stack overflow!-
isTrampoline(t: obj): bool— Returns, whethertis a trampolined object. -
wrap(t: Trampoline a | a): Trampoline a— Wraptinto trampoline, if it’s not already one. -
lazy(t : () -> Trampoline a | a)— Wrap lazy computation into trampoline. Useful when constructing computations. -
Trampoline.jump(f : a -> b | Trampoline b)— map or flatmap trampoline computation. Like.thenfor promises. -
Trampoline.run(): a— Run the trampoline synchronously resulting a value.
Changelog
Section titled “Changelog”- 1.0.0 — 2015-07-14 — Initial release