For example,
x = "foo"
%{foo => 1}
**(CompileError) iex:11: illegal use of variable x in map key
Obviously it's building the map at compile time, which could be more efficient, but why doesn't it fall back to a runtime constructor like most languages with data structure literals? Interested to know if there's something about the characteristics of maps in Elixir that I'm missing.
Adding to the confusion is this Google Groups message from over a year ago, where José Valim says:
Variable keys in maps will be available in the next Erlang release.
But that was a year ago, now, and I can't find any other references to this. To what Erlang version was he referring? I'm running 18 right now and it definitely still isn't in place.
If the key is not present in the map, get() returns null. The get() method returns the value almost instantly, even if the map contains 100 million key/value pairs.
Maps are a mutable data structure, so you can modify them.
Erlang 18 added support for it and we need to update Elixir to leverage that. Therefore, we plan to support it on the next Elixir version, Elixir v1.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With