{"id":16211579,"url":"https://github.com/laurabeatris/list-length-recursion","last_synced_at":"2025-04-07T21:38:50.127Z","repository":{"id":100511692,"uuid":"413447961","full_name":"LauraBeatris/list-length-recursion","owner":"LauraBeatris","description":"Elixir algorithm exercise to practice recursion using tail call optimization","archived":false,"fork":false,"pushed_at":"2021-10-04T16:15:26.000Z","size":3,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-13T23:13:36.881Z","etag":null,"topics":["algorithms-and-data-structures","elixir","functional-programming","recursion"],"latest_commit_sha":null,"homepage":"","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/LauraBeatris.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,"publiccode":null,"codemeta":null}},"created_at":"2021-10-04T14:05:37.000Z","updated_at":"2021-10-07T13:13:24.000Z","dependencies_parsed_at":"2023-05-15T14:00:30.695Z","dependency_job_id":null,"html_url":"https://github.com/LauraBeatris/list-length-recursion","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"rocketseat-education/ignite-template-elixir-utilizando-recursao","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LauraBeatris%2Flist-length-recursion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LauraBeatris%2Flist-length-recursion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LauraBeatris%2Flist-length-recursion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LauraBeatris%2Flist-length-recursion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LauraBeatris","download_url":"https://codeload.github.com/LauraBeatris/list-length-recursion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247734008,"owners_count":20987188,"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":["algorithms-and-data-structures","elixir","functional-programming","recursion"],"created_at":"2024-10-10T10:48:28.438Z","updated_at":"2025-04-07T21:38:50.096Z","avatar_url":"https://github.com/LauraBeatris.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"left\"\u003e\n   \u003cimg src=\"https://dg8krxphbh767.cloudfront.net/tracks/elixir.svg\" /\u003e\n\u003c/p\u003e\n\n# List Length with Recursion \n\nElixir algorithm exercise to practice recursion using [tail call optimization](https://blog.appsignal.com/2019/03/19/elixir-alchemy-recursion.html)\n\n## Interesting Resources\n- [Iteration, Recursion, and Tail-call Optimization in Elixir\n](https://blog.appsignal.com/2019/03/19/elixir-alchemy-recursion.html)\n- [Multi-clause Functions with Pattern Matching and Guards in Elixir\n](https://www.culttt.com/2016/05/23/multi-clause-functions-pattern-matching-guards-elixir)\n- [Elixir Lists](https://inquisitivedeveloper.com/lwm-elixir-14/)\n\n## Module Usage\n```elixir\n  ListLength.call([]) # Result: 0\n  ListLength.call([1, 2, 3]) # Result: 3\n```\n\n## Algorithm Explanation\n```elixir\n  def call(list), do: get_length(list, 0)\n\n  # Hide the logic with private functions - helps to abstract the logic from the main function\n  # Multi-clause functions: overload a function by specifying different clauses to match against - if tail is empty, then return the current accumulator value \n  defp get_length([], acc), do: acc\n\n  # Prepend to a list using the | operator in order to access head and tail - possible due to Elixir nature of having linked lists \n  # Recursively call function and increase accumulator argument until the tail is empty \n  defp get_length([_head | tail], acc), do: get_length(tail, 1 + acc)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaurabeatris%2Flist-length-recursion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaurabeatris%2Flist-length-recursion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaurabeatris%2Flist-length-recursion/lists"}