All Projects β†’ crubier β†’ infinistack

crubier / infinistack

Licence: MIT license
Infinite recursion in JS without stack overflow errors, based on magic πŸŽ©βœ¨πŸ‡

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to infinistack

Atto
An insanely simple self-hosted functional programming language
Stars: ✭ 119 (+395.83%)
Mutual labels:  recursion
Functional Programming In Elm
DRAFT outlining some techniques of functional programming
Stars: ✭ 200 (+733.33%)
Mutual labels:  recursion
Recursion-Tree-Visualizer
A simple python package that helps to visualise any recursive function by adding a single line of code.
Stars: ✭ 89 (+270.83%)
Mutual labels:  recursion
Dsa Geeksclasses
DSA-Self Paced With Doubt Assistance Course Solutions in Python (Python 3)
Stars: ✭ 137 (+470.83%)
Mutual labels:  recursion
Leetcode
High-quality LeetCode solutions
Stars: ✭ 178 (+641.67%)
Mutual labels:  recursion
Golang Examples
Some examples for the programming language Go.
Stars: ✭ 14 (-41.67%)
Mutual labels:  recursion
Glom
β˜„οΈ Python's nested data operator (and CLI), for all your declarative restructuring needs. Got data? Glom it! β˜„οΈ
Stars: ✭ 1,341 (+5487.5%)
Mutual labels:  recursion
Dynamic-Programming-Questions-by-Aditya-Verma
Aditya Verma (Youtube) DP Playlist Codes/Solutions.
Stars: ✭ 148 (+516.67%)
Mutual labels:  recursion
Recursion Tree Visualizer
🌳 Input the javascript code of any recursive function and visualize your recursion tree
Stars: ✭ 198 (+725%)
Mutual labels:  recursion
interview-cookbook
A playground for learning DataStructures, Algorithms, and Object-Oriented Concepts.
Stars: ✭ 25 (+4.17%)
Mutual labels:  recursion
Typelang
🌳 A tiny language interpreter implemented purely in TypeScript's type-system
Stars: ✭ 149 (+520.83%)
Mutual labels:  recursion
Algo Tree
Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
Stars: ✭ 166 (+591.67%)
Mutual labels:  recursion
Data-Structure-Algorithm-Programs
This Repo consists of Data structures and Algorithms
Stars: ✭ 464 (+1833.33%)
Mutual labels:  recursion
Data Structures
Data-Structures using C++.
Stars: ✭ 121 (+404.17%)
Mutual labels:  recursion
recursion-and-dynamic-programming
Julia and Python recursion algorithm, fractal geometry and dynamic programming applications including Edit Distance, Knapsack (Multiple Choice), Stock Trading, Pythagorean Tree, Koch Snowflake, Jerusalem Cross, SierpiΕ„ski Carpet, Hilbert Curve, Pascal Triangle, Prime Factorization, Palindrome, Egg Drop, Coin Change, Hanoi Tower, Cantor Set, Fibo…
Stars: ✭ 37 (+54.17%)
Mutual labels:  recursion
Project Euler Solutions
Runnable code for solving Project Euler problems in Java, Python, Mathematica, Haskell.
Stars: ✭ 1,374 (+5625%)
Mutual labels:  recursion
Awesome Functional Programming
Yet another resource for collecting articles, videos etc. regarding functional programming
Stars: ✭ 2,725 (+11254.17%)
Mutual labels:  recursion
interview-refresh-java-bigdata
a one-stop repo to lookup for code snippets of core java concepts, sql, data structures as well as big data. It also consists of interview questions asked in real-life.
Stars: ✭ 25 (+4.17%)
Mutual labels:  recursion
recursive-variant
Recursive Variant: A simple library for Recursive Variant Types
Stars: ✭ 67 (+179.17%)
Mutual labels:  recursion
algoexpert
AlgoExpert is an online platform that helps software engineers to prepare for coding and technical interviews.
Stars: ✭ 8 (-66.67%)
Mutual labels:  recursion

Infinistack πŸŽ©βœ¨πŸ‡

Infinite recursion in JS without stack overflow errors!

Based on magic, memoization, 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 your 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 = N => {
  if (N == 0) {
    return 1;
  }
  return N * factorial(N - 1);
};

// Don't do this, it will crash:
console.log(factorial(180000));

This can be transformed with infinistack in order to emancipate from stack overflow errors:

import infinistack from "infinistack";

const factorial = infinistack(N => {
  if (N == 0) {
    return 1;
  }
  return N * factorial(N - 1);
});

// This works now!
console.log(factorial(180000));

For more info, see the tests

Amazing. Thanks to @razimantv for the original idea in python

Caveats

Not yet tested on:

  • Async functions
  • Complex recursion schemes
  • Function with non-stringifiable arguments (higher order functions for example)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].