One composes; one doesn't. On Mon, Oct 12, 2020 at 7:25 AM José Valim <jose.va...@dashbit.co> wrote:
> Hi everyone, > > I thought I had commented on this thread but apparently I have not, so > apologies for the delay. > > I am not convinced about this functionality because I honestly do not find > this: > > new_map = > post > |> Map.rename_key(:user_id, :author_id) > |> Map.rename_key(:body, :content) > > clearer than this: > > new_map = %{ > user_id: post.author_id, > content: post.body, > ... > } > > Maybe if you want to keep the other keys as is, then "rename_key" can be > handy, but even then, what happens if you add a new key to post? Does it > automatically appear in the new_map? Or should it not? > > Even if we say that "clearer" is personal, there are practical reasons for > preferring the latter, such as the runtime can optimize it better (as all > keys are literals and the map is not built dynamically), and it is easier > to typecheck maps with known keys. > > So my $.02 here is that this is not something I would necessarily endorse > and, if you really want to rename only certain keys inside a map, you can > do it with a helper function or by using put+drop on the desired keys. > > Thanks! > > -- > 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-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Js0nOTvsiJYapFhnzWZbBM7%3Dw8Z4QdrgGCTvhnCUBHNQ%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Js0nOTvsiJYapFhnzWZbBM7%3Dw8Z4QdrgGCTvhnCUBHNQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- Regards, Bruce Tate CEO <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97> Groxio, LLC. 512.799.9366 br...@grox.io grox.io -- 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-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-6J4c9f48PbnsdeX2EGWsZkn4pdYGc0dKPdRj8pGe%2BxjQ%40mail.gmail.com.