{"id":18821031,"url":"https://github.com/crubier/infinistack","last_synced_at":"2025-10-07T17:02:08.411Z","repository":{"id":57273640,"uuid":"129654867","full_name":"crubier/infinistack","owner":"crubier","description":"Infinite recursion in JS without stack overflow errors, based on magic 🎩✨🐇 ","archived":false,"fork":false,"pushed_at":"2018-04-16T20:09:02.000Z","size":19,"stargazers_count":25,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T14:46:38.069Z","etag":null,"topics":["functional-programming","js","recursion"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crubier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-15T22:04:04.000Z","updated_at":"2023-11-27T20:28:02.000Z","dependencies_parsed_at":"2022-09-17T05:11:16.520Z","dependency_job_id":null,"html_url":"https://github.com/crubier/infinistack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crubier%2Finfinistack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crubier%2Finfinistack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crubier%2Finfinistack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crubier%2Finfinistack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crubier","download_url":"https://codeload.github.com/crubier/infinistack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328167,"owners_count":21085261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","js","recursion"],"created_at":"2024-11-08T00:33:17.256Z","updated_at":"2025-10-07T17:02:08.393Z","avatar_url":"https://github.com/crubier.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Infinistack 🎩✨🐇\n\nInfinite recursion in JS without stack overflow errors!\n\nBased on magic, memoization, abuse of exceptions and the work of [@razimantv](https://gist.github.com/razimantv/1b33d4a090a5bc9ed94928012b37c3f0).\n\nIf 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.\n\nBy [@crubier](https://github.com/crubier)\n\n## Install\n\n```bash\nnpm install infinistack\n```\n\n## Usage\n\nHere is a classical, \"dumb\" factorial implementation:\n\n```javascript\nconst factorial = N =\u003e {\n  if (N == 0) {\n    return 1;\n  }\n  return N * factorial(N - 1);\n};\n\n// Don't do this, it will crash:\nconsole.log(factorial(180000));\n```\n\nThis can be transformed with infinistack in order to emancipate from stack overflow errors:\n\n```javascript\nimport infinistack from \"infinistack\";\n\nconst factorial = infinistack(N =\u003e {\n  if (N == 0) {\n    return 1;\n  }\n  return N * factorial(N - 1);\n});\n\n// This works now!\nconsole.log(factorial(180000));\n```\n\nFor more info, see [the tests](https://github.com/crubier/infinistack/blob/master/test.js)\n\nAmazing. Thanks to [@razimantv](https://github.com/razimantv) for [the original idea in python](https://gist.github.com/razimantv/1b33d4a090a5bc9ed94928012b37c3f0)\n\n## Caveats\n\nNot yet tested on:\n\n* Async functions\n* Complex recursion schemes\n* Function with non-stringifiable arguments (higher order functions for example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrubier%2Finfinistack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrubier%2Finfinistack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrubier%2Finfinistack/lists"}