Ham (Ham v0.3.1)

View Source

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

apply(call, opts \\ [])

(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.

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

@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.

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

@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!(module, function_name, args, return_value, opts \\ [])

@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.