[erlang-questions] adding maps:merge_nested/2

Guilherme Andrade g@REDACTED
Sat Nov 12 22:58:26 CET 2016


Throwing my two cents out there: I would find 'merge_nested' useful (I'm
pretty sure I've had the need of something similar in the past) but it
looks a bit too specific for the maps module; particularly, one can think
of it as a "map of (maps of ...)" method, not simply a generic, flattened
maps one.

Then again, the lists module includes (very dearly needed) functions for
dealing with 'lists of tuples', so what do I know :)

Perhaps an alternative would be having a merge/N function that receives a
custom value-merger function (besides the unmerged maps), and use it
recursively to solve your particular problem.

On 12 November 2016 at 20:51, Vans S <vans_163@REDACTED> wrote:

> What do you think of a function merge_nested added to maps module?
>
> The function would merge two maps and all nested maps
>
> Example:
>
>
> #{k1=> v1, k2=> #{k3=> 5, k4=> #{k4=> v2}}}
> = maps:merge_nested(
> #{k1=> v1, k2=> #{k3=> 5},
> #{k1=> v1, k2=> #{k4=> #{k4=> v2}}})
>
> Also perhaps extending maps:merge to maps:merge/1 to allow passing a list:
>
>
> maps:merge([#{k1=> v1}, #{k2=> v2}, #{k3=> v3}])
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Guilherme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161112/c48c9c7c/attachment.htm>


More information about the erlang-questions mailing list