View Source Corsa.Spec (corsa v0.1.2)
SpecArgs contract, also known as type requirements, must be met before executing a function. In Corsa, they are checked during runtime and just prior to the annotated function's execution.
Example
iex> defmodule Elixir.Corsa.Spec.Example do ...> use Corsa.Type ...> use Corsa.Assert ...> use Corsa.Spec ...> spec f(arg1 :: integer(), arg2 :: boolean()), :ok ...> def f(1, false), do: :error ...> def f(_arg1, _arg2), do: :ok ...> end iex> Elixir.Corsa.Spec.Example.f(1, true) iex> Elixir.Corsa.Spec.Example.f(1, false) ** (Corsa.SpecResultViolationError) @spec does not hold in call 'Corsa.Spec.Example.f(1, true)' with result ':ok'
Summary
Functions
Errors
iex> defmodule Elixir.Corsa.Spec.ExampleError do ...> use Corsa.Type ...> use Corsa.Assert ...> use Corsa.Spec ...> spec f(arg1 :: integer(), arg1 :: boolean()), boolean() ...> def f(_arg1, _arg2), do: :ok ...> end ** (Corsa.SpecError) arguments in @spec should contain different names