Skip to content

Commit

Permalink
Replaced group_by_namespace/1 by a call to maps:groups_from_list/2
Browse files Browse the repository at this point in the history
* Since the bump to R25, group_by_namespace/1 follows only branch of the macro
* group_by_namespace/1 occurs once in apps/rebar/src/rebar_prv_completion.erl
  • Loading branch information
Ariel Otilibili committed Jun 4, 2024
1 parent faf0628 commit ace75b6
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions apps/rebar/src/rebar_prv_completion.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ do(State) ->

Providers0 = rebar_state:providers(State),
BareProviders = lists:filter(fun(P) -> provider_get(P, bare) end, Providers0),
ByNamespace = group_by_namespace(BareProviders),
ByNamespace = maps:groups_from_list(fun(P) -> provider_get(P, namespace) end, BareProviders),
Cmds0 = maps:fold(
fun(NS,Ps,CmdAcc) -> namespace_to_cmpl_cmds(NS, Ps)++CmdAcc end,
[],
Expand Down Expand Up @@ -169,22 +169,6 @@ provider_get(P, short_desc) ->
provider_get(P, namespace) ->
element(12, P).

-if(?OTP_RELEASE >= 25).
group_by_namespace(Ps) ->
maps:groups_from_list(fun(P) -> provider_get(P, namespace) end, Ps).
-else.
group_by_namespace(Ps) ->
lists:foldl(fun(P, Acc) ->
K=provider_get(P, namespace),
case Acc of
#{K:=Vs}->Acc#{K:=[P|Vs]};
_ -> Acc#{K=>[P]}
end
end,
#{},
Ps).
-endif.

-spec format_error(any()) -> iolist().
format_error({error_writing_file,File,Err}) ->
io_lib:format("Error occurred when trying to write into ~p file.~nReason: ~p~n", [File,Err]);
Expand Down

0 comments on commit ace75b6

Please sign in to comment.