Those are not equivalent though, as one is passing a map and the other a keyword list. You could call Map.new but it is unlikely you have a map made only of external arguments... so I am thinking you can't really escape from buiilding the map by hand.
*José Valim* www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D On Sun, Jan 20, 2019 at 7:58 PM Valter Sundström <valter.sundst...@gmail.com> wrote: > Sorry I messed up the title forgetting to add `[proposal]`, but since you > answered here, let's go with this thread. > > The GenServer case I am talking about is essentially this: > def start_link(opts) do > state = %{ > foo: Keyword.fetch!(opts, :foo), > bar: Keyword.fetch!(opts, :bar) > } > > GenServer.start_link(__MODULE__, state, opts) > end > > > I believe I am not alone in doing similar things, but possibly I am. The > reasoning being to fail quickly at initialization. > This could instead be written as: > def start_link(opts) do > GenServer.start_link(__MODULE__, Keyword.take!(opts, [:foo, :bar]), > opts) > end > > This, I think is clearer. > > > > > On Sunday, January 20, 2019 at 7:47:53 PM UTC+1, José Valim wrote: >> >> Just for completeness, if we add those functions, we also need to add >> Map.drop! and Keyword.drop!. Btw, your description here makes more sense, >> as I can see this feature being useful for keywords, but not really for >> maps. Do you have some code snippets you could show us too? >> >> Thanks Valter! >> >> *José Valim* >> www.plataformatec.com.br >> Skype: jv.ptec >> Founder and Director of R&D >> >> >> On Sun, Jan 20, 2019 at 7:36 PM Valter Sundström <valter.s...@gmail.com> >> wrote: >> >>> I somewhat often find myself wanting to take subsets of maps and >>> keywords lists, verifying that all keys I take exist. >>> An initial PR for this is available here >>> <https://github.com/elixir-lang/elixir/pull/8657>, but as josé pointed >>> out, a discussion needs to be had regarding the need for it. >>> One of my main usages of this is for example when initializing the state >>> of a `GenServer`, or if extracting some options from a keyword list to pass >>> along to some other module. >>> Please chime in if you have any opinions! >>> >>> // Valter >>> >>> -- >>> 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/5990bdcd-83d2-4925-8af6-79bbaa488667%40googlegroups.com >>> <https://groups.google.com/d/msgid/elixir-lang-core/5990bdcd-83d2-4925-8af6-79bbaa488667%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > 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/bf4a83a9-c925-40fe-a1f6-fbbb7159b5cb%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/bf4a83a9-c925-40fe-a1f6-fbbb7159b5cb%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAGnRm4LrMG8Qby874u_YZPj%3DEgJEm1TNFE1P4Fo_f7jN7DJ2mg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.