> `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.