Skip to content

Commit

Permalink
Merge pull request #2907 from ariel-anieli/filtermap
Browse files Browse the repository at this point in the history
Made `rebar_utils:filtermap/2` to call directly `lists:filtermap/2`
  • Loading branch information
ferd authored Jul 29, 2024
2 parents 4ca95a1 + f20d726 commit fac203c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/rebar/src/rebar_compiler_erl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ dependencies(Source, _SourceDir, Dirs, DepOpts) ->
%% TODO: check for core transforms?
{_MissIncl, _MissInclLib} =/= {[],[]} andalso
?DIAGNOSTIC("Missing: ~p", [{_MissIncl, _MissInclLib}]),
lists:filtermap(
rebar_utils:filtermap(
fun (Mod) -> rebar_compiler_epp:resolve_source(Mod, Dirs) end,
OptPTrans ++ PTrans ++ Behaviours) ++ AbsIncls
catch
Expand Down
2 changes: 1 addition & 1 deletion apps/rebar/src/rebar_plugins.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ install(State, AppInfo) ->
filter_existing_plugins(Plugins, State) ->
PluginNames = lists:zip(Plugins, rebar_state:deps_names(Plugins)),
AllPlugins = rebar_state:all_plugin_deps(State),
lists:filtermap(fun({Plugin, PluginName}) ->
rebar_utils:filtermap(fun({Plugin, PluginName}) ->
case rebar_app_utils:find(PluginName, AllPlugins) of
{ok, _} ->
false;
Expand Down
15 changes: 3 additions & 12 deletions apps/rebar/src/rebar_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,13 @@ sort_deps(Deps) ->
droplast(L) ->
lists:reverse(tl(lists:reverse(L))).

%% @doc filtermap takes in a function that is either or both
%% a predicate and a map, and returns the matching and valid elements.
%% @doc wrapper around lists:filtermap/2
-spec filtermap(F, [In]) -> [Out] when
F :: fun((In) -> boolean() | {true, Out}),
In :: term(),
Out :: term().
filtermap(F, [Hd|Tail]) ->
case F(Hd) of
true ->
[Hd|filtermap(F, Tail)];
{true,Val} ->
[Val|filtermap(F, Tail)];
false ->
filtermap(F, Tail)
end;
filtermap(F, []) when is_function(F, 1) -> [].
filtermap(F, In) ->
lists:filtermap(F, In).

is_arch(ArchRegex) ->
case re:run(get_arch(), ArchRegex, [{capture, none}, unicode]) of
Expand Down

0 comments on commit fac203c

Please sign in to comment.