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

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Wed Apr 13 13:09:53 CEST 2016


On Fri, Apr 8, 2016 at 8:31 PM, Björn-Egil Dahlberg <
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160413/88da04a7/attachment.htm>


More information about the erlang-questions mailing list