https://github.com/micheleriva/saferec
Easy and lightweight trampoline for your recursive functions.
https://github.com/micheleriva/saferec
Last synced: 6 months ago
JSON representation
Easy and lightweight trampoline for your recursive functions.
- Host: GitHub
- URL: https://github.com/micheleriva/saferec
- Owner: micheleriva
- License: unlicense
- Created: 2019-05-17T12:05:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-17T12:17:35.000Z (over 6 years ago)
- Last Synced: 2025-02-07T12:47:20.935Z (8 months ago)
- Language: JavaScript
- Size: 98.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
**SafeRec** is a simple but powerful trampoline which converts your recursive function into a fast and safe `while` loop.
You can read more about why you should adopt memory safe recursion [here](https://medium.com/openmindonline/js-monday-06-adopting-memory-safe-recursion-d26dcee409c9)# Installation
**Yarn**
```sh
yarn add saferec
```**NPM**
```sh
npm install saferec --save-dev
```# Usage
```js
import rec from "saferec"function factorial(num) {
return num === 0
? 1
: (num * factorial(num - 1));
}const result = rec(factorial(1000));
```# LICENSE
[The Unlicense](/LICENSE.md)