Hello, I have a problem with properly understanding Enum.reduce but after many tries I managed to get this inside my function to work. However, when I run mix credo --strict
I see there’s a refactoring opportunity because the function body is nested too deep. Could you please help me with refactoring this function? I would appreciate an additional explanation. Thank you!
Enum.reduce(conditions, queryable, fn {k, v}, acc ->
case {k, v} do
{_, ""} ->
acc
{_, _} when is_atom(k) ->
case {k in like_fields, k in date_fields} do
{true, false} -> where_ilike(acc, k, v)
{false, true} -> where_date(acc, k, v)
{false, false} -> where(acc, [u], field(u, ^k) == ^v)
end
_ ->
acc
end
end)