summaryrefslogtreecommitdiff
path: root/src/econf.erl
diff options
context:
space:
mode:
authorEvgeny Khramtsov <ekhramtsov@process-one.net>2019-11-08 10:20:18 +0300
committerEvgeny Khramtsov <ekhramtsov@process-one.net>2019-11-08 10:20:18 +0300
commit925998c360879bda303e1dac022032fc8fe648d2 (patch)
treeaef8f6269b3f297fab48f5333ae91cebeb8f51e5 /src/econf.erl
parentCheck if error.log is empty after running test suite (diff)
Preserve order of grouped duplicates
Diffstat (limited to 'src/econf.erl')
-rw-r--r--src/econf.erl19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/econf.erl b/src/econf.erl
index e1231ea6..75817a64 100644
--- a/src/econf.erl
+++ b/src/econf.erl
@@ -232,13 +232,18 @@ format_join(L) ->
%% into a single option with all list-values being concatenated
-spec group_dups(list(T)) -> list(T).
group_dups(Y1) ->
- {Y2, D} = lists:mapfoldl(
- fun({Option, Values}, Acc) when is_list(Values) ->
- {[], dict:append_list(Option, Values, Acc)};
- (Other, Acc) ->
- {[Other], Acc}
- end, dict:new(), Y1),
- lists:append(Y2) ++ dict:to_list(D).
+ lists:reverse(
+ lists:foldl(
+ fun({Option, Values}, Acc) when is_list(Values) ->
+ case lists:keyfind(Option, 1, Acc) of
+ {Option, Vals} when is_list(Vals) ->
+ lists:keyreplace(Option, 1, Acc, {Option, Vals ++ Values});
+ _ ->
+ [{Option, Values}|Acc]
+ end;
+ (Other, Acc) ->
+ [Other|Acc]
+ end, [], Y1)).
%%%===================================================================
%%% Validators from yconf