{"id":22736969,"url":"https://github.com/emadb/recursionex","last_synced_at":"2025-03-30T03:15:04.058Z","repository":{"id":231154979,"uuid":"729592142","full_name":"emadb/recursionex","owner":"emadb","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-14T16:44:15.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T05:29:35.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emadb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-09T18:03:37.000Z","updated_at":"2024-04-02T16:46:55.000Z","dependencies_parsed_at":"2024-04-02T18:55:21.622Z","dependency_job_id":"636ed38c-9194-419d-a377-040993db3d7a","html_url":"https://github.com/emadb/recursionex","commit_stats":null,"previous_names":["emadb/recursionex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadb%2Frecursionex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadb%2Frecursionex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadb%2Frecursionex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emadb%2Frecursionex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emadb","download_url":"https://codeload.github.com/emadb/recursionex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246269933,"owners_count":20750321,"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":[],"created_at":"2024-12-10T22:08:43.921Z","updated_at":"2025-03-30T03:15:04.039Z","avatar_url":"https://github.com/emadb.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Let's talk about recursion\n\n- Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem.\n- Some mathematical samples are intriscly recursive: Fact(n) = n * Fact(n - 1), Fact(1) = 1\n- Structure of Recursive Functions\n    Base Case: A condition that stops the recursion, preventing infinite loops.\n    Recursive Step: A part of the function that calls itself with a simpler or smaller argument.\n- The Rationale Behind Using Recursion\n    Ideal for Complex Problems: \"Simplifies coding complex problems like tree traversals.\"\n    Aligns with Functional Programming: \"Recursion is a natural fit for Elixir's functional programming style.\"\n- Benefits\n    Simplicity: Recursion can turn complex algorithms into clearer, more manageable code (tree traversals)\n    Readability and Maintainability: Recursive solutions can be more intuitive and easier to follow (declarative vs imperative)\n    Reducing State Management Complexity: Iteration often requires manual tracking of state, which recursion handles naturally.\n    Recursion complements the stateless and immutable nature of functional programming\n    TCO allows recursion to be as memory efficient as iteration\n- Pitfalls\n    Stack overflow\n    Performance (memory consumption)\n    Debugging\n- Conceptual differences with iterations:\n    Recursion: \"Focuses on breaking down a problem into simpler instances of itself.\"\n    Iteration: \"Relies on a loop construct to repeat an operation until a condition is met.\"\n- Advanced cases\n  Mutual recursion: is_even/1 is_odd/1\n  Accumulative Recursion (TOC Factorial)\n\n\n- TOC\n```\ndefmodule Factorial do\n  def calculate(n), do: factorial_acc(n, 1)\n\n  defp factorial_acc(0, acc), do: acc\n  defp factorial_acc(n, acc) when n \u003e 0, do: factorial_acc(n - 1, n * acc)\nend\n```\n\n```\ndefmodule Factorial do\n  def calculate(0), do: 1\n  def calculate(n) when n \u003e 0, do: n * calculate(n - 1)\nend\n```\n\n## The Rules\n1) When recurring on a list ask two questions about it?\nnull?(list)/empty?(list) and else\n\n2) Always change 1 argument while recurring. It must be change to be closer to the termination. The changing argument must be tested in the termination condition.\n\n\n\n\n## Esempi\n- size\n- sum\n- first\n- last\n- member?\n- remove_first\n- remove_all\n- replace\n- map\n- reduce\n- max (using reduce)\n- all? (using reduce)\n- reverse\n- zip\n\nLodash\n- index_of\n- filter\n- sort_by\n- find\n\n\n- value (operazioni matematiche)\n- Maze example\n- Sorting\n- Tree traversing\n- Split (even and odd)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femadb%2Frecursionex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femadb%2Frecursionex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femadb%2Frecursionex/lists"}