View Source Ham (Ham v0.1.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

Link to this macro

apply(call, opts \\ [])

View Source (macro)

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.
Link to this function

apply(module, function_name, args, opts \\ [])

View Source
@spec apply(module(), atom(), [any()], Keyword.t()) :: any()

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.
Link to this function

validate(module, function_name, args, return_value, opts \\ [])

View Source
@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
Link to this function

validate!(module, function_name, args, return_value, opts \\ [])

View Source
@spec validate!(module(), atom(), [any()], any(), Keyword.t()) :: :ok | no_return()

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.