RTypes v0.1.2 RTypes View Source
The module defines the derive/1
macro which can be used to derive a
run-time checker for the given type.
The module also defines a function derive/3
which can be used at run
time. However, it must be given arguments as module, type name, and a list of
type args.
Link to this section Summary
Functions
Derive a validating function given some type expression.
Derive a validating function given a module name, type name and type parameters.
Link to this section Functions
derive(code) View Source (macro)
Derive a validating function given some type expression.
Usage
iex> require RTypes
iex> port_number? = RTypes.derive(:inet.port_number())
iex> port_number?.(8080)
true
iex> kw_list_of_pos_ints? = RTypes.derive(Keyword.t(pos_integer()))
iex> kw_list_of_pos_ints?.([a: 1, b: 2])
true
Note that the macro expects the argument as in module.type(arg1, arg2)
. That
is a module name followed by .
and the type name, followed by type
parameters enclosed in parenthesis.
derive(mod, type_name, type_args)
View Source
derive(module(), atom(), [RTypes.Extractor.type()]) ::
(term() -> true | no_return())
derive(module(), atom(), [RTypes.Extractor.type()]) :: (term() -> true | no_return())
Derive a validating function given a module name, type name and type parameters.
Type arguments must be concrete types, either built-in or basic types like list()
Example
iex> keyword_list? = RTypes.derive(Keyword, :t, [{:type, 0, :pos_integer, []}])
iex> keyword_list?.(key1: 4, key2: 5)
true