<div dir="ltr">I'm actually working on something similar. And problem is that one cannot assume that merge logic is the same for all nested levels. In other words for M1{....Kn => M2 } (i am using incorrect syntax for clarity ) we cannot assume that merging function is the same for M1 and M2. So then one can try to pass list of merger functions that each correspond to "merging" level as: <div><br></div><div>M1{... Kn => M2 {...Knm => M3}}, [F1,F2,F3] where F1(M1) would "recursively" call F2(M2) and so on</div><div><br></div><div>but this is also incorrect assumption and one can imagine that map can have multiple nested maps on the same level with</div><div> different semantics for merging as:</div><div><br></div><div>M1{...Kn=> M2 ... Km => M3} </div><div>where we want function F1 to merge M2 and F3 to merge M3.</div><div><br></div><div>there is also problem in type conversion: </div><div><br></div><div>M1{K => atom} , M2{K => M3} </div><div><br></div><div>should key K now be list: [atom, M3]?? It cannot be  map as there is no valid key, except in odd cases where you want something like </div><div>Mr{K => M{atom => M3}}. It is "natural" that it should be list but again it could be tuple!  </div><div><br></div><div>For now i think this problem gets easier if we generalize it. Then question is how to merge ANY two objects in erlang ? My answer is to pass a pair to the merge function that is merge on type dispatch. </div><div><br></div><div>F(X, Y) when is_list(X) andalso is_list(Y) -> </div><div>           %get two elements Xn, Yn</div><div>           F(Xn, Yn),</div><div>           ....;</div><div>F(X, Y) when is_atom(X) andalso is_atom(Y) -> // branch termination</div><div>           X; % this is just for illustration logic can be to throw or what ever </div><div>.....</div><div> </div><div>IMO this strategy gives most flexibility and one can make wrapper </div><div><br></div><div>merge(X, Y , F);</div><div><br></div><div>and then provide implementation of different merging logics to be used as needed </div><div><br></div><div>my_merge_logic(X, Y) .....</div><div><br></div><div>call merge </div><div><br></div><div>merge(X, Y, fun my_merge_logic/2),</div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><br></div></div>