|
|
@@ -31,7 +31,6 @@
|
|
|
binary_string/1,
|
|
|
deep_convert/3,
|
|
|
diff_maps/2,
|
|
|
- merge_with/3,
|
|
|
best_effort_recursive_sum/3,
|
|
|
if_only_to_toggle_enable/2
|
|
|
]).
|
|
|
@@ -231,55 +230,6 @@ convert_keys_to_atom(BinKeyMap, Conv) ->
|
|
|
[]
|
|
|
).
|
|
|
|
|
|
-%% copy from maps.erl OTP24.0
|
|
|
-merge_with(Combiner, Map1, Map2) when
|
|
|
- is_map(Map1),
|
|
|
- is_map(Map2),
|
|
|
- is_function(Combiner, 3)
|
|
|
-->
|
|
|
- case map_size(Map1) > map_size(Map2) of
|
|
|
- true ->
|
|
|
- Iterator = maps:iterator(Map2),
|
|
|
- merge_with_t(
|
|
|
- maps:next(Iterator),
|
|
|
- Map1,
|
|
|
- Map2,
|
|
|
- Combiner
|
|
|
- );
|
|
|
- false ->
|
|
|
- Iterator = maps:iterator(Map1),
|
|
|
- merge_with_t(
|
|
|
- maps:next(Iterator),
|
|
|
- Map2,
|
|
|
- Map1,
|
|
|
- fun(K, V1, V2) -> Combiner(K, V2, V1) end
|
|
|
- )
|
|
|
- end;
|
|
|
-merge_with(Combiner, Map1, Map2) ->
|
|
|
- ErrorType = error_type_merge_intersect(Map1, Map2, Combiner),
|
|
|
- throw(#{maps_merge_error => ErrorType, args => [Map1, Map2]}).
|
|
|
-
|
|
|
-merge_with_t({K, V2, Iterator}, Map1, Map2, Combiner) ->
|
|
|
- case Map1 of
|
|
|
- #{K := V1} ->
|
|
|
- NewMap1 = Map1#{K := Combiner(K, V1, V2)},
|
|
|
- merge_with_t(maps:next(Iterator), NewMap1, Map2, Combiner);
|
|
|
- #{} ->
|
|
|
- merge_with_t(maps:next(Iterator), maps:put(K, V2, Map1), Map2, Combiner)
|
|
|
- end;
|
|
|
-merge_with_t(none, Result, _, _) ->
|
|
|
- Result.
|
|
|
-
|
|
|
-error_type_merge_intersect(M1, M2, Combiner) when is_function(Combiner, 3) ->
|
|
|
- error_type_two_maps(M1, M2);
|
|
|
-error_type_merge_intersect(_M1, _M2, _Combiner) ->
|
|
|
- badarg_combiner_function.
|
|
|
-
|
|
|
-error_type_two_maps(M1, M2) when is_map(M1) ->
|
|
|
- {badmap, M2};
|
|
|
-error_type_two_maps(M1, _M2) ->
|
|
|
- {badmap, M1}.
|
|
|
-
|
|
|
%% @doc Sum-merge map values.
|
|
|
%% For bad merges, ErrorLogger is called to log the key, and value in M2 is ignored.
|
|
|
best_effort_recursive_sum(M10, M20, ErrorLogger) ->
|
|
|
@@ -314,7 +264,7 @@ do_best_effort_recursive_sum(M1, M2, ErrorLogger) ->
|
|
|
V1 + V2
|
|
|
end
|
|
|
end,
|
|
|
- merge_with(F, M1, M2).
|
|
|
+ maps:merge_with(F, M1, M2).
|
|
|
|
|
|
deep_filter(M, F) when is_map(M) ->
|
|
|
%% maps:filtermap is not available before OTP 24
|