Skip to content

Commit

Permalink
feat: add Vx.Type.constraints/2
Browse files Browse the repository at this point in the history
  • Loading branch information
tlux committed Mar 25, 2024
1 parent 44019e1 commit 0ae5b1e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/vx/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ defmodule Vx.Type do
|> Enum.reverse()
end

@doc """
Returns the constraints of the type with the given name.
"""
@doc since: "0.4.0"
@spec constraints(type, atom) :: [Constraint.t()]
when type: t(atom) | custom(module, atom)
def constraints(type, name) do
type
|> constraints()
|> Enum.filter(&match?(%Constraint{name: ^name}, &1))
end

defp resolve(%{__type__: %__MODULE__{} = type}), do: type
defp resolve(%__MODULE__{} = type), do: type

Expand Down

0 comments on commit 0ae5b1e

Please sign in to comment.