Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    trampapublic

    trampa

    Trampolines, to emulate tail-call recursion.

    Build Status NPM version Dependency Status devDependency Status Code Climate

    Synopsis

    var trampa = require("trampa");
     
    function loop(n, acc) {
      return n === 0 ? trampa.wrap(acc) : trampa.lazy(function () {
        return loop(- 1, acc + 1);
      });
    }
     
    loop(123456789, 0).run(); // doesn't cause stack overflow! 

    API

    • isTrampoline(t: obj): bool — Returns, whether t is a trampolined object.

    • wrap(t: Trampoline a | a): Trampoline a — Wrap t into 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 .then for promises.

    • Trampoline.run(): a — Run the trampoline synchronously resulting a value.

    Changelog

    • 1.0.02015-07-14 — Initial release

    install

    npm i trampa

    Downloadsweekly downloads

    16,432

    version

    1.0.0

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar