View Source TypeCheck.Spec (TypeCheck v0.10.7)

Link to this section Summary

Functions

True if a spec was added to {module, function, arity}.

Looks up the spec for a particular {module, function, arity}.

Looks up the spec for a particular {module, function, arity}.

Link to this section Functions

Link to this function

defined?(module, function, arity)

View Source

True if a spec was added to {module, function, arity}.

c.f. lookup/3.

iex(1)> defmodule Example3 do
...(2)>   use TypeCheck
...(3)>   @spec! greeter(name :: binary()) :: binary()
...(4)>   def greeter(name), do: "Hello, #{name}!"
...(5)> end
...(6)>
...(7)> TypeCheck.Spec.defined?(Example3, :greeter, 1)
true
...(8)> TypeCheck.Spec.defined?(Example3, :nonexistent, 0)
false
Link to this function

lookup(module, function, arity)

View Source

Looks up the spec for a particular {module, function, arity}.

On success, returns {:ok, spec}. On failure, returns {:error, :not_found}.

This is quite an advanced low-level function, which you usually won't need to interact with directly.

c.f. lookup!/3.

iex(1)> defmodule Example do
...(2)>   use TypeCheck
...(3)>   @spec! greeter(name :: binary()) :: binary()
...(4)>   def greeter(name), do: "Hello, #{name}!"
...(5)> end
...(6)>
...(7)> {:ok, spec} = TypeCheck.Spec.lookup(Example, :greeter, 1)
...(8)> spec
#TypeCheck.Spec<  greeter(name :: binary()) :: binary() >

iex> TypeCheck.Spec.lookup(Example, :nonexistent, 0)
{:error, :not_found}
Link to this function

lookup!(module, function, arity)

View Source

Looks up the spec for a particular {module, function, arity}.

On success, returns spec. Raises when the spec cannot be found.

c.f. lookup/3.

iex(1)> defmodule Example2 do
...(2)>   use TypeCheck
...(3)>   @spec! greeter(name :: binary()) :: binary()
...(4)>   def greeter(name), do: "Hello, #{name}!"
...(5)> end
...(6)>
...(7)> TypeCheck.Spec.lookup!(Example2, :greeter, 1)
#TypeCheck.Spec<  greeter(name :: binary()) :: binary() >

iex> TypeCheck.Spec.lookup!(Example2, :nonexistent, 0)
** (ArgumentError) No spec found for `Example2.nonexistent/0`