Elixir v0.13 has introduced Maps
, a key value store. Quoting elixir 0.13 docs
A Dict implementation that works on maps. Maps are key-value stores where keys are compared using the match operator (===). Maps can be created with the %{} special form defined in the Kernel.SpecialForms module.
Now just FYI, to use Maps
, elixir branch v0.13
needs to be checked out and also we need to use erlang 17 rc 1. I am not going into details, but here are some useful information.
1.) Get and install erlang 17 rc 1. One can also use multiple release manager for erlang
2.) Get and install elixir v0.13
like
Defining a map
Let’s dive in, roll your sleeves and fire up iex
There is one other way to initialize or construct Map
via new
method, as explained below
Accessing Map
Accessing map is pretty simple, like we see in other language (i.e ruby, javascript)
Like wise updating, deleting and other operations go by Dict
style
Maps
implements most of Dict
methods, one can look them in docs
Uses
Maps can be used as data model in modules
using defstruct
. Here is how
We can access it by
Manipulating struct are same as Maps
Disclaimer: Maps are hot changes, available only in elixir v0.13
, they might change in future.
elixir programming :)
About The Author
I am Pankaj Baagwan, a System Design Architect. A Computer Scientist by heart, process enthusiast, and open source author/contributor/writer. Advocates Karma. Love working with cutting edge, fascinating, open source technologies.
To consult Pankaj Bagwan on System Design, Cyber Security and Application Development, SEO and SMO, please reach out at me[at]bagwanpankaj[dot]com
For promotion/advertisement of your services and products on this blog, please reach out at me[at]bagwanpankaj[dot]com
Stay tuned <3. Signing off for RAAM