Note that the branching and pattern matching can also be applied to fn and are equivalent:
Enum.reduce(conditions, queryable, fn
{_, ""}, acc ->
acc
{k, v}, 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 ->
acc
end)
You can also merge the first and third branches:
Enum.reduce(conditions, queryable, fn
{k, v}, acc when is_atom(k) and v != "" ->
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 ->
acc
end)


















