{"id":21966456,"url":"https://github.com/dreamingechoes/30-seconds-of-elixir-code","last_synced_at":"2025-09-04T19:16:23.511Z","repository":{"id":96611022,"uuid":"156625024","full_name":"dreamingechoes/30-seconds-of-elixir-code","owner":"dreamingechoes","description":"Curated collection of useful Elixir snippets that you can understand in 30 seconds or less. ","archived":false,"fork":false,"pushed_at":"2018-12-22T14:35:52.000Z","size":56,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T07:48:30.786Z","etag":null,"topics":["code","elixir-lang","learning-resources","snippets","snippets-collection"],"latest_commit_sha":null,"homepage":null,"language":null,"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/dreamingechoes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2018-11-08T00:05:53.000Z","updated_at":"2024-11-30T03:29:34.000Z","dependencies_parsed_at":"2023-03-16T20:30:11.028Z","dependency_job_id":null,"html_url":"https://github.com/dreamingechoes/30-seconds-of-elixir-code","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dreamingechoes/30-seconds-of-elixir-code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamingechoes%2F30-seconds-of-elixir-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamingechoes%2F30-seconds-of-elixir-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamingechoes%2F30-seconds-of-elixir-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamingechoes%2F30-seconds-of-elixir-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dreamingechoes","download_url":"https://codeload.github.com/dreamingechoes/30-seconds-of-elixir-code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamingechoes%2F30-seconds-of-elixir-code/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273658410,"owners_count":25145269,"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-09-04T02:00:08.968Z","response_time":61,"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":["code","elixir-lang","learning-resources","snippets","snippets-collection"],"created_at":"2024-11-29T13:16:17.883Z","updated_at":"2025-09-04T19:16:23.444Z","avatar_url":"https://github.com/dreamingechoes.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"![30 Seconds Of Elixir Code](./media/logo.png)\n\n# 30 Seconds Of Elixir Code\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n\u003e A curated collection of useful Elixir snippets that you can understand in 30 seconds or less.\n\n**Note**: This project is inspired by [30 Seconds Of Code](https://github.com/30-seconds/30-seconds-of-code), but there's no affiliation of any kind with that project.\n\n:sparkles: **Always work in progress** :sparkles:\n\n## Table of Contents\n\n### 📚 Array\n\n\u003cdetails\u003e\n\n  \u003csummary\u003eView contents\u003c/summary\u003e\n\n  * [`all_equal`](#all_equal)\n  * [`array_to_csv`](#array_to_csv)\n  * [`bifurcate`](#bifurcate)\n\n\u003c/details\u003e\n\n---\n\n## 📚 Array\n\n### all_equal\n\nCheck if all the elements in an array are equal.\n\n```elixir\ndef all_equal(arr), do: arr |\u003e Enum.dedup() |\u003e Enum.count() == 1\n```\n\n\u003cdetails\u003e\n\n  \u003csummary\u003eExamples\u003c/summary\u003e\n\n  ```elixir\n  all_equal([1, 2, 3, 4, 5, 6])  # false\n  all_equal([1, 1, 1])           # true\n  ```\n\u003c/details\u003e\n\n\u003cbr\u003e[⬆ Back to top](#table-of-contents)\n\n### array_to_csv\n\nConverts a 2D array to a comma-separated values (CSV) string.\n\n```elixir\ndef array_to_csv(arr), do: arr |\u003e Enum.join(\",\")\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eExamples\u003c/summary\u003e\n\n  ```elixir\n  array_to_csv([1, 2, 3, 4])    # \"1,2,3,4\"\n  ```\n\u003c/details\u003e\n\n\u003cbr\u003e[⬆ Back to top](#table-of-contents)\n\n### bifurcate\n\nSplits values into two groups. If an element in filter is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.\n\n```elixir\ndef bifurcate(arr, predicate) do\n  Enum.reduce(\n    arr,\n    %{a: [], b: []},\n    fn x, ac -\u003e\n      if (predicate.(x)) do\n        %{a: [x] ++ ac[:a], b: ac[:b]}\n      else\n        %{a: ac[:a], b: [x] ++ ac[:b]}\n      end\n    end\n  )\nend\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eExamples\u003c/summary\u003e\n\n  ```elixir\n  bifurcate([1, 2, 3, 4], fn x -\u003e rem(x, 2) == 0 end)\n  # %{a: [4, 2], b: [3, 1]}\n  ```\n\u003c/details\u003e\n\n\u003cbr\u003e[⬆ Back to top](#table-of-contents)\n\n\n## Contributing\n\nYou can contribute to this project by [sending a pull request](https://github.com/dreamingechoes/30-seconds-of-elixir-code/pull/new/master) with your new code snippets, or by [creating a new issue](https://github.com/dreamingechoes/30-seconds-of-elixir-code/issues/new) if you want that a new section or snippet is added. Here you have the alphabetical [list of contributors](CONTRIBUTORS.md) of this repository.\n\n----------------------------\n\nThis project was developed by [dreamingechoes](https://github.com/dreamingechoes).\nIt adheres to its [code of conduct](https://github.com/dreamingechoes/base/blob/master/files/CODE_OF_CONDUCT.md) and\n[contributing guidelines](https://github.com/dreamingechoes/base/blob/master/files/CONTRIBUTING.md), and uses an equivalent [license](https://github.com/dreamingechoes/base/blob/master/files/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreamingechoes%2F30-seconds-of-elixir-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdreamingechoes%2F30-seconds-of-elixir-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreamingechoes%2F30-seconds-of-elixir-code/lists"}