24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-18 22:15:20 +02:00

Preserve order of grouped duplicates

This commit is contained in:
Evgeny Khramtsov 2019-11-08 10:20:18 +03:00
parent f6d7af1a2b
commit 925998c360

View File

@ -232,13 +232,18 @@ format_join(L) ->
%% into a single option with all list-values being concatenated %% into a single option with all list-values being concatenated
-spec group_dups(list(T)) -> list(T). -spec group_dups(list(T)) -> list(T).
group_dups(Y1) -> group_dups(Y1) ->
{Y2, D} = lists:mapfoldl( lists:reverse(
fun({Option, Values}, Acc) when is_list(Values) -> lists:foldl(
{[], dict:append_list(Option, Values, Acc)}; fun({Option, Values}, Acc) when is_list(Values) ->
(Other, Acc) -> case lists:keyfind(Option, 1, Acc) of
{[Other], Acc} {Option, Vals} when is_list(Vals) ->
end, dict:new(), Y1), lists:keyreplace(Option, 1, Acc, {Option, Vals ++ Values});
lists:append(Y2) ++ dict:to_list(D). _ ->
[{Option, Values}|Acc]
end;
(Other, Acc) ->
[Other|Acc]
end, [], Y1)).
%%%=================================================================== %%%===================================================================
%%% Validators from yconf %%% Validators from yconf