Actually, right! I could use struct/2 from Kernel - to convert to an internal struct it would validate the keys and provide with the defaults! Anyways, it's good to know the official stance on the subject, and I'd better use keyword for options instead of maps as it's the idiomatic way.
Thanks everyone! On Friday, October 18, 2024 at 5:14:10 AM UTC-5 gener...@gmail.com wrote: > There are already Structs and NimbleOptions > https://github.com/dashbitco/nimble_options which kind of do the same > thing. > Maybe it's still a good idea but it is totally doable as is. > > > On Thu, 17 Oct 2024 at 22:22, Rudolf Manusadzhian <rud.ma...@gmail.com> > wrote: > >> It's been a couple of years since Erlang started favoring maps for >> options to keywords (proplists how it's called there). *See >> https://erlangforums.com/t/handling-options-in-erlang-otp-apis/1133 >> <https://erlangforums.com/t/handling-options-in-erlang-otp-apis/1133>* >> >> Recently in an elixir project I tried to also use map for options but >> faced the lack of the analog of Keyword.validate!/2 which is very handy! >> >> I propose adding a similar function to Map as well. >> >> While I'm not entirely sure about the API. Here I put together a commit >> where I adapted a lot from Keyword.validate/2 >> >> >> https://github.com/RudolfMan/elixir/commit/5be16e1b5309a0be127f5fa3198a5f0487187463 >> >> The result looks like this: >> >> [image: Screen Shot 2024-10-17 at 11.08.01 PM.png] >> >> WDYT? >> >> -- >> > 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/e8094862-56a7-4550-9cc9-e17dbe395daan%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elixir-lang-core/e8094862-56a7-4550-9cc9-e17dbe395daan%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/e210723f-f47d-4312-ab65-76d87ea0ee9en%40googlegroups.com.