Skip to content

Instantly share code, notes, and snippets.

@psyeugenic
Last active August 29, 2015 14:06
Show Gist options
  • Save psyeugenic/cb994b668d32497627be to your computer and use it in GitHub Desktop.
Save psyeugenic/cb994b668d32497627be to your computer and use it in GitHub Desktop.
%% or like this
merge_threads_2([#{type := T, counters := C0}=M, #{type := T, counters := C1}|Ms],Acc) ->
merge_threads_2([M#{counters := add_counters(C0,C1)}|Ms],Acc);
merge_threads_2([M1,M2|Ms0],Acc) -> merge_threads_2([M1|Ms0],[M2|Acc]);
merge_threads_2([M],Acc) -> [M|merge_threads_2(Acc,[])];
merge_threads_2([],_) -> [].
add_counters(M1,M2) ->
maps:map(fun(Key,V1) ->
V2 = maps:get(Key,M2),
V1 + V2
end,M1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment