Infinistack 🎩✨🐇
Infinite recursion in JS without stack overflow errors!
Based on magic, abuse of exceptions and the work of @razimantv.
If you need this package to make your code work, then my advice would be to rethink your code structure. This library works, but is not efficient or safe. Instead of using this, unroll you recursion into iterative algorithms, you will thank me later.
By @crubier
Install
npm install infinistack
Usage
Here is a classical, "dumb" factorial implementation:
const factorial = { if N == 0 return 1; return N * ;}; // Don't do this, it will crash:console;
This can be transformed with infinistack in order to emancipate from stack overflow errors:
; const factorial = ; // This works now!console;
Amazing. Thanks to @razimantv for the original idea in python
Caveats
Not yet tested on:
- Async functions
- Non trivial recursion schemes
- Function calls with non-stringifiable arguments (higher order functions for example)