0.1.0 • Published 7 months ago

recursion-executor v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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.

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])
0.1.0

7 months ago