{"id":16732378,"url":"https://github.com/danielberkompas/destructure","last_synced_at":"2025-04-07T07:06:38.318Z","repository":{"id":57489269,"uuid":"72477894","full_name":"danielberkompas/destructure","owner":"danielberkompas","description":"Javascript-style destructuring for Elixir","archived":false,"fork":false,"pushed_at":"2022-08-31T20:08:49.000Z","size":21,"stargazers_count":107,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-09T21:34:10.381Z","etag":null,"topics":["elixir","hex"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/danielberkompas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-10-31T21:04:47.000Z","updated_at":"2024-02-24T06:21:48.000Z","dependencies_parsed_at":"2022-08-29T22:11:52.716Z","dependency_job_id":null,"html_url":"https://github.com/danielberkompas/destructure","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielberkompas%2Fdestructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielberkompas%2Fdestructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielberkompas%2Fdestructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielberkompas%2Fdestructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielberkompas","download_url":"https://codeload.github.com/danielberkompas/destructure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608151,"owners_count":20965952,"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":["elixir","hex"],"created_at":"2024-10-12T23:44:09.049Z","updated_at":"2025-04-07T07:06:38.294Z","avatar_url":"https://github.com/danielberkompas.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Destructure\n[![Hex.pm](https://img.shields.io/hexpm/v/destructure.svg)](https://hex.pm/packages/destructure)\n[![Build Status](https://danielberkompas.semaphoreci.com/badges/destructure/branches/master.svg?style=shields)](https://danielberkompas.semaphoreci.com/projects/destructure)\n\nAdds Javascript-style destructuring to Elixir. When working with a `map`, instead\nof writing match operation like this:\n\n```elixir\ndef full_name(%{first_name: first_name, last_name: last_name}) do\n  \"#{first_name} #{last_name}\"\nend\n```\n\nYou can write:\n\n```elixir\nimport Destructure\n\ndef full_name(d%{first_name, last_name}) do\n  \"#{first_name} #{last_name}\"\nend\n```\n\nIt also works with `structs` and `keyword`.\n\n```elixir\nimport Destructure\n\ndef full_name(d%Person{first_name, last_name}) do\n  \"#{first_name} #{last_name}\"\nend\ndef full_name(d[first_name, last_name]) do\n  \"#{first_name} #{last_name}\"\nend\n```\n\nYou can also do it in a case statement.\n\n```elixir\ncase post(url, data) do\n  {:ok, d%{body}} -\u003e # instead of {:ok, %{body: body}}\n    # use body variable\n  _other -\u003e\n    # ...\nend\n```\n\nUnlike Javascript, you can still bind custom variables:\n\n```elixir\nd(%{first, last, email: mail}) = %{...}\n```\n\nSee the [Hex Documentation](https://hexdocs.pm/destructure) for more details.\n\n## Installation\n\nAdd `destructure` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:destructure, \"~\u003e 0.2.3\"}]\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielberkompas%2Fdestructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielberkompas%2Fdestructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielberkompas%2Fdestructure/lists"}