View Source Ham (Ham v0.2.0)
Ham is a library for rigorous typespec checking for module functions including typespecs from implemented behaviours
Summary
Functions
Handy macro to apply a module function validating arguments and return value against typespecs
Apply a module function validating arguments and return value against typespecs
Validate arguments and return value against typespecs.
Validate arguments and return value against typespecs
Functions
Handy macro to apply a module function validating arguments and return value against typespecs
iex> Ham.apply(URI.decode("https%3A%2F%2Felixir-lang.org"))
"https://elixir-lang.org"
iex> Ham.apply(URI.char_reserved?("a"))
** (Ham.TypeMatchError) 1st argument value "a" does not match 1st parameter's type byte().
Value "a" does not match type 0..255.
Apply a module function validating arguments and return value against typespecs
iex> Ham.apply(URI, :decode, ["https%3A%2F%2Felixir-lang.org"])
"https://elixir-lang.org"
iex> Ham.apply(URI, :char_reserved?, ["a"])
** (Ham.TypeMatchError) 1st argument value "a" does not match 1st parameter's type byte().
Value "a" does not match type 0..255.
@spec validate(module(), atom(), [any()], any(), Keyword.t()) :: :ok | {:error, Ham.TypeMatchError.t()}
Validate arguments and return value against typespecs.
iex> Ham.validate(URI, :char_reserved?, [?a], true)
:ok
Validate arguments and return value against typespecs
iex> Ham.validate!(URI, :char_reserved?, ["a"], true)
** (Ham.TypeMatchError) 1st argument value "a" does not match 1st parameter's type byte().
Value "a" does not match type 0..255.