Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chinesedfan/recursion-executor
Run recursive functions without stack overflow.
https://github.com/chinesedfan/recursion-executor
generator recurison
Last synced: 8 days ago
JSON representation
Run recursive functions without stack overflow.
- Host: GitHub
- URL: https://github.com/chinesedfan/recursion-executor
- Owner: chinesedfan
- Created: 2023-10-23T06:11:38.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-28T04:38:36.000Z (about 1 year ago)
- Last Synced: 2024-10-29T12:56:22.065Z (3 months ago)
- Topics: generator, recurison
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# recursion-executor
Run recursive functions without stack overflow.
## executor(gf, initArgs)
- `gf` {Generator Function} - the recursive function to be run
- `initArgs` {Array} - arguments list for the recursive function## Example
This package will use generator function to simulate the recursion process, so rewrite the recursion function a bit at the beginning.
```js
const executor = require('recursion-executor')function* add(n) {
if (n <= 1) return 1
// use `yield` whenever calling itself recursively
// as well as `const a = add(n - 1)`
const a = yield [n - 1]
return n + a
}
executor(add, [1e5])
```