Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/more aggressive do map simplification #1429

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions lib/ash/filter/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,11 @@
end

def map(expression, func) do
if expression != func.(expression) do
IO.inspect(expression, label: "expression")

Check warning on line 1152 in lib/ash/filter/filter.ex

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix credo --strict

There should be no calls to `IO.inspect/1`.

Check warning on line 1152 in lib/ash/filter/filter.ex

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix credo --strict

There should be no calls to `IO.inspect/1`.
IO.inspect(func.(expression), label: "func.(expression)")

Check warning on line 1153 in lib/ash/filter/filter.ex

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix credo --strict

There should be no calls to `IO.inspect/1`.

Check warning on line 1153 in lib/ash/filter/filter.ex

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix credo --strict

There should be no calls to `IO.inspect/1`.
end

do_map(func.(expression), func)
end

Expand All @@ -1159,17 +1164,20 @@
value when is_tuple(value) ->
value
|> Tuple.to_list()
|> map(func)
|> do_map(func)
|> List.to_tuple()

value when is_list(value) ->
Enum.map(value, &map(&1, func))
Enum.map(value, &do_map(&1, func))

%MapSet{} = value ->
MapSet.new(value, &do_map(&1, func))

%BooleanExpression{left: left, right: right} = expr ->
%{expr | left: map(left, func), right: map(right, func)}
%{expr | left: do_map(left, func), right: do_map(right, func)}

%Not{expression: not_expr} = expr ->
%{expr | expression: map(not_expr, func)}
%{expr | expression: do_map(not_expr, func)}

%Ash.Query.Parent{} = this ->
# you have to map over the internals of this yourself
Expand All @@ -1179,30 +1187,30 @@
custom_expression ->
%{
custom_expression
| expression: map(expression, func),
simple_expression: map(simple_expression, func)
| expression: do_map(expression, func),
simple_expression: do_map(simple_expression, func)
}

%Ash.Query.Exists{} = expr ->
# you have to map over the internals of exists yourself
func.(expr)

%Ash.Query.Call{args: args} = op ->
%{op | args: map(args, func)}
%{op | args: do_map(args, func)}

%{__operator__?: true, left: left, right: right} = op ->
%{op | left: map(left, func), right: map(right, func)}
%{op | left: do_map(left, func), right: do_map(right, func)}

%{__function__?: true, arguments: arguments} = function ->
%{
function
| arguments:
Enum.map(arguments, fn
{key, arg} when is_atom(key) ->
{key, map(arg, func)}
{key, do_map(arg, func)}

arg ->
map(arg, func)
do_map(arg, func)
end)
}

Expand All @@ -1213,7 +1221,7 @@
value when is_map(value) ->
value
|> Map.to_list()
|> map(func)
|> do_map(func)
|> Map.new()

other ->
Expand Down
Loading