{"id":23547228,"url":"https://github.com/kpanic/carry","last_synced_at":"2025-04-24T06:10:33.730Z","repository":{"id":54962239,"uuid":"159988992","full_name":"kpanic/carry","owner":"kpanic","description":"Carry, a dead simple package that converts a map %{\"hello\" =\u003e \"world\"} to an Elixir struct","archived":false,"fork":false,"pushed_at":"2021-02-09T14:12:21.000Z","size":20,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T18:46:57.468Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kpanic.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":"2018-12-01T21:30:50.000Z","updated_at":"2022-06-02T20:00:42.000Z","dependencies_parsed_at":"2022-08-14T07:31:06.196Z","dependency_job_id":null,"html_url":"https://github.com/kpanic/carry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpanic%2Fcarry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpanic%2Fcarry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpanic%2Fcarry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpanic%2Fcarry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kpanic","download_url":"https://codeload.github.com/kpanic/carry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250573351,"owners_count":21452352,"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-26T09:14:59.283Z","updated_at":"2025-04-24T06:10:33.712Z","avatar_url":"https://github.com/kpanic.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Carry\n\nCarry is a super simple, dependency free package that transforms a map from this\nform:\n\n```elixir\n%{\"carillon\" =\u003e \"sound\", \"marimba\" =\u003e \"percussion\"}\n```\n\nto the corresponding Elixir `struct`.\n\nFor example, given this `struct`:\n\n```elixir\n  defmodule Instrument do\n    defstruct [:carillon]\n  end\n```\n\nby invoking the function with the expanded struct:\n\n```elixir\niex\u003e Carry.on(%{\"carillon\" =\u003e \"sound\", \"marimba\" =\u003e \"percussion\"}, %Instrument{})\n%Instrument{carillon: \"sound\"}\n```\n\nor with the atom representing the struct\n\n```elixir\niex\u003e Carry.on(%{\"carillon\" =\u003e \"sound\", \"marimba\" =\u003e \"percussion\"}, Instrument)\n%Instrument{carillon: \"sound\"}\n```\n\nor as a syntactic sugar functionality\n\n```elixir\niex\u003e Carry.on(%Instrument{carillon: \"sound\"}, Instrument)\n%Instrument{carillon: \"sound\"}\n```\n\nwhich will just call `struct(module, Map.from_struct(struct))` under the hood\n\nThis is usually useful when having a decoded payload from json (a map) and\nwe want to convert to an Elixir `struct`.\n\nThis implementation does not use `String.to_atom/1` in order to not exhaust the\nBEAM atom table limits, since atoms are not garbage collected.\n\nI was using `exconstrutor`, however I noticed that it seems to generate new\natoms in some corner cases.\nSee https://github.com/appcues/exconstructor/issues/25 to get more context.\n\n### Credits\n\nThanks to to the https://hex.pm/packages/poison library for *heavy* influence =)\n\n### **NOTE**\n\nIf you are using `Poison`, you can just do `Poison.decode(json_string, as: %YourStruct{})`\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `carry` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:carry, \"~\u003e 0.1\"}\n  ]\nend\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/carry](https://hexdocs.pm/carry).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpanic%2Fcarry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkpanic%2Fcarry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpanic%2Fcarry/lists"}