Thanks a lot all for the responses. I get how this would break things considering `Map.get/3` is foundational to many other code bases. So we can consider this as better handled as it's currently done.
Thank you again. On Thu, Jun 23, 2022 at 4:54 PM Ben Wilson <benwilson...@gmail.com> wrote: > > `Map.get(map, key, default_value)` looks better than `Map.get(map, key) > || default_value` > > This isn't a matter of looks, these have straight up different > functionality. You can't change this sort of thing in the language at this > point in its lifecycle. Plus, you'd be forcing everyone who's doing that > first thing to change to the far uglier multiline: > > ``` > case Map.fetch(map, key) do > {:ok, value} -> value > _ -> default_value > end > ``` > On Wednesday, June 22, 2022 at 8:22:50 AM UTC-4 halos...@gmail.com wrote: > >> >> On Jun 22, 2022, at 04:37, Nganga Mburu <mburun...@gmail.com> wrote: >> >> >> >> We've used `map[key] || default_value`, or even `Map.get(map, key) || >> default_value` before but I felt this being handled my `Map.get/3` would >> be better. >> >> `Map.get(map, key, default_value)` looks better than `Map.get(map, key) >> || default_value` >> >> >> This assumes that `nil` isn’t a valid value. For your use-case it may be. >> For other cases, it may be a valid and important value. >> >> I know for a fact that this would break some production code we run and >> be a surprising result for us because it would not behave the way we expect >> for anything else, including JavaScript Map.get. >> >> -a >> > -- > 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/7aa588ab-5aea-4138-8e93-82bed15841ban%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/7aa588ab-5aea-4138-8e93-82bed15841ban%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/CAFVCX%3D2QAviaYQejP3BvN5utuWqwR8VOM%3DKCVuASXUtSbRm96A%40mail.gmail.com.