{"id":20089933,"url":"https://github.com/bugadani/recursor","last_synced_at":"2026-05-13T02:34:29.858Z","repository":{"id":56951467,"uuid":"51264693","full_name":"bugadani/Recursor","owner":"bugadani","description":"A library to run quasi-recursive functions iteratively","archived":false,"fork":false,"pushed_at":"2016-05-10T11:11:08.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-17T16:42:45.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/bugadani.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":"2016-02-07T20:26:02.000Z","updated_at":"2022-09-23T08:23:25.000Z","dependencies_parsed_at":"2022-08-21T03:40:17.540Z","dependency_job_id":null,"html_url":"https://github.com/bugadani/Recursor","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bugadani/Recursor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRecursor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRecursor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRecursor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRecursor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugadani","download_url":"https://codeload.github.com/bugadani/Recursor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FRecursor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27291121,"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","status":"online","status_checked_at":"2025-11-28T02:00:06.623Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-13T16:20:47.010Z","updated_at":"2025-11-28T02:03:39.691Z","avatar_url":"https://github.com/bugadani.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Recursor\n========\n\nRecursor enabled execution of recursive algorithms in an iterative manner by utiliting PHP's generator feature.\nThis is particularly useful, because there may be algorithms that are easy to implement recursively but hard\niteratively. Also, PHP imposes an artificial nesting limit on recursion.\n\nTo transform a recursive function into a quasi-recursive one using Recursor, basically the only work that is needed is\nto replace `return` keywords with `yield` and recusrive function calls should also be prefixed with `yield`.\n\nAn example that will generate the nth Fibonacci-number:\n\n    $fibonacci = function ($x) use (\u0026$fibonacci) {\n        if ($x === 0) {\n            yield 0;\n        } else if ($x === 1) {\n            yield 1;\n        } else {\n            $x1 = (yield $fibonacci($x - 1));   //retrieves return value of recursive call\n            $x2 = (yield $fibonacci($x - 2));\n            yield $x1 + $x2;                    //yielding a non-generator acts as a return\n        }\n    };\n\n    $wrapped = new Recursor($fibonacci);\n\n    $wrapped(5); // returns 5\n    $wrapped(6); // returns 8\n\nNotes\n--------\n\n * Recursor is built for PHP 5.5. This means that PHP7's generator-return is not supported. As a workaround, functions will\n   \"return\" the first non-generator value it yields and because of this, they will not be able to generate sequences.\n * If you wish to yield a generator that should not be executed, you can wrap it in `\\IteratorIterator` or a custom wrapper.\n\nDownsides\n--------\n\nRecursor relies heavily on generators. Each recursive call instantiates and executes a generator, which has a certain\nCPU and memory overhead. Also, the actual executor function is quite complicated which imposes even more overhead.\nBecause of this, relying on Recurson in performance-sensitive applications is not recommended and an iterative solution\nshould be implemented.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Frecursor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugadani%2Frecursor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Frecursor/lists"}