exchema v0.4.0 Exchema

Exchema is a library for defining data structures using refinement types.

Exchema is split in some components:

  • Exchema - the main module. It does type checking and deal with type checking errors.
  • Exchema.Predicates - The default predicate library you can use to refine your types. It’s just a bunch of 2-arity functions that receives the value and some options.
  • Exchema.Notation - a DSL for defining types.

It also comes with a series of pre-defined types you can check under Exchema.Types namespace.

Link to this section Summary

Functions

Flattens a list of errors that follows the :nested_errors pattern where the error returned follow this structure

Link to this section Types

Link to this type error()
error() :: {Type.predicate_spec(), any(), any()}
Link to this type flattened_error()
flattened_error() :: {[any()], Type.predicate_spec(), any(), any()}

Link to this section Functions

Link to this function errors(val, type, opts \\ [])
errors(any(), Type.spec(), [{atom(), any()}]) :: [error()]
Link to this function flatten_errors(errors)
flatten_errors([error()]) :: [flattened_error()]

Flattens a list of errors that follows the :nested_errors pattern where the error returned follow this structure:

{
  {predicate, predicate_opts, {
    :nested_errors,
    [
      {key, error},
      {key, error}
    ]
  }
}

The returned result is a list of a 4-tuple where the first element is the path of keys to reach the error and the rest is the normal 3-tuple error elements (predicate, predicate options and the error itself)

Link to this function is?(val, type, opts \\ [])
is?(any(), Type.spec(), [{atom(), any()}]) :: boolean()