I would propose to add this to the Kernel module, to mirror the struct! helper. But adding to Keyword also works. Thoughts?
On Mon, Jul 12, 2021 at 8:38 AM Paulo Valente <polvale...@gmail.com> wrote: > One common problem we face when dealing with keyword list opts is > validating options passed and setting default values to said keyword. > > This commonly yields code like: > > def f(x, opts \\ []) do > > opt_1 = opts[:opt_1] || :default_1 > opt_2 = opts[:opt_2] || :default_2 > ... > end > > Nx.Defn.Kernel has an useful helper for these cases ( > https://github.com/elixir-nx/nx/blob/c8353de695a3d70dc6d518e0ab2ec832faa7df68/nx/lib/nx/defn/kernel.ex#L741 > ). > > Perhaps this helper could be included in the Keyword module, along with a > non-rasing version of some kind? > > -- > 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/09f8df11-459a-44a6-aaf2-34462069d8ccn%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/09f8df11-459a-44a6-aaf2-34462069d8ccn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAGnRm4%2B4tjxfOhvZ2ky%3Dw-u%2Bpfe0xmWEhGRQBxZS8a0fYzgeTQ%40mail.gmail.com.