<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1478446594473_655523" dir="ltr">These days I am working more and more with javascript on the front-end, erlang on the back. The map type fits really well and is simple.<br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655547"><br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655548">I usually try to keep my data flat but often this is not the reality. For example parsing some JSON from the frontend into a map is dead simple, I know I rather just send erlang binary term format, but not everyone has a fully working erlang term serializer for their language.<br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655549"><br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655550">Also the recent addition of with and without to maps shows that indeed there is a need for more functionality out of maps. <br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655551"><br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655552">As neoncontrails recently told me, "a list is just a map", let that sink in! Indeed a list is simply a map, with the index being the key. Its maps, maps all the way down, then more maps.<br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655553"><br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655554">Another useful function is to diff two maps, but this now I think is indeed beyond scope of the maps module.<br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655555"><br clear="none" id="yui_3_16_0_ym19_1_1478446594473_655556">Also Haskell style lens or similar to make accessing/updating nested properties would be useful, but again beyond the scope of this merge_nested.<br><span id="yui_3_16_0_ym19_1_1478446594473_655557"><br>PS. And you know what just happened :)</span></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Saturday, November 12, 2016 4:58 PM, Guilherme Andrade <g@gandrade.net> wrote:<br></font></div> <br><br> <div class="y_msg_container"><div id="yiv7878065344"><div><div dir="ltr"><div><div>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.<br clear="none"><br clear="none"></div>Then again, the lists module includes (very dearly needed) functions for dealing with 'lists of tuples', so what do I know :)<br clear="none"><br clear="none"></div>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.<div class="yiv7878065344gmail_extra"><br clear="none"><div class="yiv7878065344yqt1591156948" id="yiv7878065344yqtfd38917"><div class="yiv7878065344gmail_quote">On 12 November 2016 at 20:51, Vans S <span dir="ltr"><<a rel="nofollow" shape="rect" ymailto="mailto:vans_163@yahoo.com" target="_blank" href="mailto:vans_163@yahoo.com">vans_163@yahoo.com</a>></span> wrote:<br clear="none"><blockquote class="yiv7878065344gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">What do you think of a function merge_nested added to maps module?<br clear="none">
<br clear="none">
The function would merge two maps and all nested maps<br clear="none">
<br clear="none">
Example:<br clear="none">
<br clear="none">
<br clear="none">
#{k1=> v1, k2=> #{k3=> 5, k4=> #{k4=> v2}}}<br clear="none">
= maps:merge_nested(<br clear="none">
#{k1=> v1, k2=> #{k3=> 5},<br clear="none">
#{k1=> v1, k2=> #{k4=> #{k4=> v2}}})<br clear="none">
<br clear="none">
Also perhaps extending maps:merge to maps:merge/1 to allow passing a list:<br clear="none">
<br clear="none">
<br clear="none">
maps:merge([#{k1=> v1}, #{k2=> v2}, #{k3=> v3}])<br clear="none">
______________________________ _________________<br clear="none">
erlang-questions mailing list<br clear="none">
<a rel="nofollow" shape="rect" ymailto="mailto:erlang-questions@erlang.org" target="_blank" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/ listinfo/erlang-questions</a><br clear="none">
</blockquote></div></div><br clear="none"><br clear="all"><br clear="none">-- <br clear="none"><div class="yiv7878065344gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<div class="yiv7878065344yqt1591156948" id="yiv7878065344yqtfd00634"><br clear="none"></div></div></div></div></div></div></div><div class="yiv7878065344yqt1591156948" id="yiv7878065344yqtfd99845">
</div></div></div></div></div><br><br></div> </div> </div> </div></div></body></html>