[erlang-questions] map module functions, map "cons" idea

Daniel Goertzen daniel.goertzen@REDACTED
Thu Jul 31 21:28:39 CEST 2014

I just watched Kenneth’s map talk from the EUC (http://vimeo.com/99747090).
 He asked for feedback on maps, so here’s mine:

1. I ported a few functions from the lists module.  The ones I found useful
were filter() and mapfold().  I also found with() useful, which does the
opposite of maps:without().  I would be very happy to see these 3 functions
in the maps module.

2. In the talk there was a question about matching an empty map, and also a
question about precise matching like how one would match a list.  I have
always wondered similar things, so it got me thinking…

What if we use a "cons" in a map pattern to allow matching all remaining
keys that were not selected in the main part of the pattern?  This would be
roughly symmetric to what you can do with lists and binaries.  For example:

#{ a:=A, c:=C | Rest } = #{a=>1, b=>2, c=>3, d=>4}.   % Rest = #{b=>2, d=>4}

That in itself I think has limited use, but it could be used to exactly
match a map (ie, no extra pairs other than those specified in the match):

f(#{ a:=A, c:=C | Rest })

  when maps:size(Rest)==0 ->


If the pattern to the right of the bar is elided, we could take it to mean
“match the empty map”.  The previous example could be rewritten as:

f(#{ a:=A, c:=C |}) ->


This also lets you match just the empty map as was asked in the talk:

f(#{|}) ->


Apologies if something like this has already been discussed.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140731/55b55f9c/attachment.htm>

More information about the erlang-questions mailing list