Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phadej/trampa
Trampolines, to emulate tail-recursion.
https://github.com/phadej/trampa
Last synced: 2 months ago
JSON representation
Trampolines, to emulate tail-recursion.
- Host: GitHub
- URL: https://github.com/phadej/trampa
- Owner: phadej
- License: mit
- Created: 2015-07-14T08:04:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-31T16:02:14.000Z (about 6 years ago)
- Last Synced: 2024-10-11T21:08:51.257Z (3 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trampa
Trampolines, to emulate tail-call recursion.
[![Build Status](https://secure.travis-ci.org/phadej/trampa.svg?branch=master)](http://travis-ci.org/phadej/trampa)
[![NPM version](https://badge.fury.io/js/trampa.svg)](http://badge.fury.io/js/trampa)
[![Dependency Status](https://david-dm.org/phadej/trampa.svg)](https://david-dm.org/trampa/trampa)
[![devDependency Status](https://david-dm.org/phadej/trampa/dev-status.svg)](https://david-dm.org/trampa/trampa#info=devDependencies)
[![Code Climate](https://img.shields.io/codeclimate/github/phadej/trampa.svg)](https://codeclimate.com/github/phadej/trampa)## Synopsis
```js
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!
```## 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.0** — *2015-07-14* — Initial release