Just a few remarks if you don’t mind:
Enum.reject(schema, fn {_, v}
I’d go with something longer and less generic than k (key?) and v (value?). Maybe {field, schema}? Plus in this case I think it makes sense to use {_k, v} to explain the meaning of the first element.
cond do
is_tuple(v) -> {k, elem(v, 0)}
is_atom(v) -> {k, v}
true -> raise(ArgumentError, "Bad formed schema")
end
Using more pattern matching would be more idiomatic:
case v do
{type, _opts} when is_atom(type) -> {k, type}
type when is_atom(type) -> {k, type}
_ -> raise ArgumentError, "bad schema: #{inspect(v)}"
end
And one more thing:
schema |> Enum.map(fn {k, v} -> ... end) |> Enum.into(%{})
can be replaced with:
Map.new(schema, fn {k, v} -> ... end)






















