[erlang-questions] Wanted additions to the maps module?

Björn-Egil Dahlberg XB bjorn-egil.xb.dahlberg@REDACTED
Wed Apr 13 15:40:57 CEST 2016

There is currently no (good) way to get out of C-context to execute some 
erlang snippet and then get back into c-context. Traps does this but 
only in a controlled manner. I think it is doable though.

Your proposal of maps_apply/3 is the maps equivalent of dict:update/3 
and sadly that name is already occupied in maps (it's the equivalent of 

I think we should add it to the API without thinking about the 
performance too much. Performance can always be improved later on.

Is maps:apply/3 the best name we can think of? I don't really trust you 
and naming things. =) update/3,4 would probably have been best but c'est 
la vie.

// Björn-Egil

On 2016-04-13 13:09, Jesper Louis Andersen wrote:
> On Fri, Apr 8, 2016 at 8:31 PM, Björn-Egil Dahlberg 
> <wallentin.dahlberg@REDACTED <mailto:wallentin.dahlberg@REDACTED>> 
> wrote:
>     Have you repeated some code or built your own private lib to
>     handle certain maps specific tasks and thought "why isn't this in
>     the maps module?"
> One function I like to have is "apply update via function", and I 
> implement it somewhat often:
> maps_apply(F, K, Map) ->
>     V = maps:get(K, Map),
>     maps:put(K, F(V), Map).
> But it can be made much faster in a direct implementation since I 
> don't have to first pick up the value: I can apply F when I sit with 
> the value at hand and thus avoid the "put" lookup path. It might, 
> however, be nasty to implement because F is in Erlang-context, whereas 
> the maps operations are in BIF-context.
> -- 
> J.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160413/810bb7c9/attachment.htm>

More information about the erlang-questions mailing list