4 ms·
Well yes, because not finding a key in a map is not an error typically. Map.get is the same way, as is Access. It returns nil. If you want it to be an error you
by jolux 5y ago
Well yes, because not finding a key in a map is not an error typically. Map.get is the same way, as is Access. It returns nil. If you want it to be an error you can use the version that raises.
- Grimm1 5y agoThat's not true across many of the languages I use, dict.pop returns a key error in python for instance. By having a version that raises the standard library is basically saying not having a key is the error state.
- jolux 5y ago> That's not true across many of the languages I use, dict.pop returns a key error in python for instance. Yeah, sorry. I should have been more clear. This behavior is common in Lisps, which is what I’m used to. It’s less common in mainstream languages. With Elixir it may be Clojure-inspired. > By having a version that raises the standard library is basically saying not having a key is the error state. Not necessarily, it’s saying you can choose whether it should be an error or not. Notably other functions that error don’t give you the option of specifying a default. That’s the difference here. Nil is returned because it’s passed in, it’s the default argument for the “default value” parameter.