[erlang-questions] Accessing a single value from MAPS

Jesper Louis Andersen <>
Sun Sep 6 21:02:58 CEST 2015


On Sun, Sep 6, 2015 at 8:45 PM, Theepan <> wrote:

> What is the syntactic sugar to access single value from MAPS?


#{ key := Value } = Map

There are currently only injection operators available for maps in the
syntax and no availability of projection operators. The closest thing you
get to a projection is maps:get/2 indeed. As for the nested case:

nest_lookup([], V) -> V;
nest_lookup([K|Ks], M) ->
    nest_lookup(Ks, maps:get(K, M)).

And you are ready to do nested lookups:

nest_lookup([a,b,c], Map).



-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150906/c1726b28/attachment.html>


More information about the erlang-questions mailing list