new_map = %{
foo: Map.fetch!(old_map, "foo"),
bar: Map.fetch!(old_map, "bar"),
...
}
new_map = %{
user_id: post.author_id,
content: post.body,
...
}
new_map =
old_map
|> Map.rename_key("foo", :foo)
|> Map.rename_key("bar", :bar)
...
new_map =
post
|> Map.rename_key(:user_id, :author_id)
|> Map.rename_key(:body, :content)
...
new_map = Map.rename_keys(old_map, %{"foo" => :foo, "bar" => :bar, ...})
new_map = Map.rename_keys(post, %{author_id: :user_id, body: :content, ...})
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/70108df1-6c5e-475b-8dbd-b4222e920e0bo%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d6276452-1e72-4e79-9b25-614c69d7648an%40googlegroups.com.
I’ve implemented our own helper in our projects that does this and would be a fan of seeing it added to Map
.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAMhJPGgq_wJw5QcdJaN1G2zh7X%2BY6pBFsV8HtShFqOuiUeL63g%40mail.gmail.com.
new_map = post |> Map.rename_key(:user_id, :author_id) |> Map.rename_key(:body, :content)
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Js0nOTvsiJYapFhnzWZbBM7%3Dw8Z4QdrgGCTvhnCUBHNQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a9edf077-9a58-4e51-af54-cd0732b3fbf3n%40googlegroups.com.