Tyyppi.Value (tyyppi v0.7.1) View Source

Value type to be used with Tyyppi.

It wraps the standard Elixir type in a struct, also providing optional coercion, validation, documentation, and Access implementation.

Built-in constructors

  • any 
  • atom 
  • string 
  • boolean 
  • integer 
  • non_neg_integer 
  • pos_integer 
  • timeout 
  • pid 
  • mfa 
  • mod_arg 
  • fun 
  • one_of 
  • formulae 
  • list — creates a [type()] wrapped into a value
  • struct 

Link to this section Summary

Types

Type of the coercion function allowed

Type returned from coercions and validations, typical pair of ok/error tuples

Type of the encoder function, that might be used for e. g. Json serialization

Type of the generator function, producing the stream of value()

t()

Type of the validation function allowed

Type of the value behind this struct

Functions

Creates a not defined any() wrapped by Tyyppi.Value

Factory for any() wrapped by Tyyppi.Value

Creates a not defined atom() wrapped by Tyyppi.Value

Factory for atom() wrapped by Tyyppi.Value

Creates a not defined boolean() wrapped by Tyyppi.Value

Factory for boolean() wrapped by Tyyppi.Value

Creates a not defined date_time() wrapped by Tyyppi.Value

Factory for timeout() wrapped by Tyyppi.Value

Creates a not defined formulae wrapped by Tyyppi.Value

Factory for formulae wrapped by Tyyppi.Value

Creates a not defined fun wrapped by Tyyppi.Value

Creates a not defined integer() wrapped by Tyyppi.Value

Factory for integer() wrapped by Tyyppi.Value

Helper guard to match Value instances

Creates a not defined list wrapped by Tyyppi.Value

Factory for list wrapped by Tyyppi.Value

Creates a not defined mfa wrapped by Tyyppi.Value

Factory for mfa wrapped by Tyyppi.Value

Factory for mfa wrapped by Tyyppi.Value

Creates a not defined mod_arg wrapped by Tyyppi.Value

Factory for mod_arg wrapped by Tyyppi.Value

Factory for mod_arg wrapped by Tyyppi.Value

Creates a not defined non_neg_integer() wrapped by Tyyppi.Value

Factory for non_neg_integer() wrapped by Tyyppi.Value

Creates a one_of value wrapped by Tyyppi.Value

Creates a not defined pid() wrapped by Tyyppi.Value

Factory for pid() wrapped by Tyyppi.Value

Factory for pid() wrapped by Tyyppi.Value

Creates a not defined pos_integer() wrapped by Tyyppi.Value

Factory for pos_integer() wrapped by Tyyppi.Value

Creates a not defined String.t() wrapped by Tyyppi.Value

Factory for String.t() wrapped by Tyyppi.Value

Creates a not defined struct wrapped by Tyyppi.Value

Factory for struct wrapped by Tyyppi.Value

Creates a not defined timeout() wrapped by Tyyppi.Value

Factory for timeout() wrapped by Tyyppi.Value

Link to this section Types

Specs

coercer() :: (value() -> either())

Type of the coercion function allowed

Specs

either() :: {:ok, value()} | {:error, any()}

Type returned from coercions and validations, typical pair of ok/error tuples

Specs

encoder() :: (value(), keyword() -> binary()) | nil

Type of the encoder function, that might be used for e. g. Json serialization

Specs

factory_option() ::
  {:value, any()}
  | {:documentation, String.t()}
  | {:type, Tyyppi.T.t(term())}
  | {:coercion, coercer()}
  | {:validation, validator()}
  | {:encoding, encoder()}
  | {:generation, {generator(), any()} | generator() | nil}

Specs

generator() :: (() -> StreamData.t(value())) | (any() -> StreamData.t(value()))

Type of the generator function, producing the stream of value()

Specs

t() :: t(term())

Specs

t(wrapped) :: %Tyyppi.Value{
  value: value(),
  documentation: String.t(),
  type: Tyyppi.T.t(wrapped),
  coercion: coercer(),
  validation: validator(),
  encoding: encoder(),
  generation: {generator(), any()} | generator() | nil,
  __meta__: %{
    defined?: boolean(),
    optional?: boolean(),
    errors: [any()],
    subsection: String.t()
  },
  __context__: %{optional(atom()) => any()}
}

Specs

validator() ::
  (value() -> either()) | (value(), %{required(atom()) => any()} -> either())

Type of the validation function allowed

Specs

value() :: any()

Type of the value behind this struct

Link to this section Functions

Specs

any() :: t()

Creates a not defined any() wrapped by Tyyppi.Value

Specs

any(any() | [factory_option()]) :: t()

Factory for any() wrapped by Tyyppi.Value

Specs

atom() :: t()

Creates a not defined atom() wrapped by Tyyppi.Value

Specs

atom(options :: any() | [factory_option()]) :: t()

Factory for atom() wrapped by Tyyppi.Value

Specs

boolean() :: t()

Creates a not defined boolean() wrapped by Tyyppi.Value

Specs

boolean(options :: any() | [factory_option()]) :: t()

Factory for boolean() wrapped by Tyyppi.Value

Specs

date_time() :: t()

Creates a not defined date_time() wrapped by Tyyppi.Value

Specs

date_time(options :: any() | [factory_option()]) :: t()

Factory for timeout() wrapped by Tyyppi.Value

Specs

formulae() :: t()

Creates a not defined formulae wrapped by Tyyppi.Value

Specs

formulae(
  options :: Formulae.t() | binary() | [{:formulae, any()} | factory_option()]
) :: t()
Link to this function

formulae(value, formulae)

View Source

Specs

formulae(
  value :: any(),
  formulae :: Formulae.t() | binary() | {module(), atom(), list()}
) :: t()

Factory for formulae wrapped by Tyyppi.Value

Specs

fun(:any | arity() | keyword() | (... -> any())) :: t() | no_return()

Creates a not defined fun wrapped by Tyyppi.Value

Specs

integer() :: t()

Creates a not defined integer() wrapped by Tyyppi.Value

Specs

integer(options :: any() | [factory_option()]) :: t()

Factory for integer() wrapped by Tyyppi.Value

Link to this macro

is_value(value)

View Source (macro)

Helper guard to match Value instances

Specs

list() :: t()

Creates a not defined list wrapped by Tyyppi.Value

Specs

list(
  options ::
    Tyyppi.T.t(wrapped) | [{:type, Tyyppi.T.t(wrapped)} | factory_option()]
) :: t(wrapped)
when wrapped: term()

Factory for list wrapped by Tyyppi.Value

Specs

list(value :: list(), type :: Tyyppi.T.t(wrapped)) :: t(wrapped)
when wrapped: term()

Specs

mfa() :: t()

Creates a not defined mfa wrapped by Tyyppi.Value

Specs

mfa(
  options ::
    boolean()
    | function()
    | {module(), atom(), non_neg_integer()}
    | [{:existing, boolean()} | factory_option()]
) :: t()

Factory for mfa wrapped by Tyyppi.Value

Specs

mfa(m :: module(), f :: atom(), a :: non_neg_integer()) :: t()

Factory for mfa wrapped by Tyyppi.Value

Specs

mod_arg() :: t()

Creates a not defined mod_arg wrapped by Tyyppi.Value

Specs

mod_arg(
  options ::
    boolean() | {module(), list()} | [{:existing, boolean()} | factory_option()]
) :: t()

Factory for mod_arg wrapped by Tyyppi.Value

Specs

mod_arg(m :: module(), args :: list()) :: t()

Factory for mod_arg wrapped by Tyyppi.Value

Specs

non_neg_integer() :: t()

Creates a not defined non_neg_integer() wrapped by Tyyppi.Value

Link to this function

non_neg_integer(options)

View Source

Specs

non_neg_integer(options :: any() | [factory_option()]) :: t()

Factory for non_neg_integer() wrapped by Tyyppi.Value

Specs

one_of([any()]) :: t()

Creates a one_of value wrapped by Tyyppi.Value

Specs

one_of(any(), [any()]) :: t()

Specs

optional(t(wrapped)) :: t(wrapped) when wrapped: term()

Specs

pid() :: t()

Creates a not defined pid() wrapped by Tyyppi.Value

Specs

pid(options :: any() | [factory_option()]) :: t()

Factory for pid() wrapped by Tyyppi.Value

Specs

pid(p1 :: non_neg_integer(), p2 :: non_neg_integer(), p3 :: non_neg_integer()) ::
  t()

Factory for pid() wrapped by Tyyppi.Value

Specs

pos_integer() :: t()

Creates a not defined pos_integer() wrapped by Tyyppi.Value

Specs

pos_integer(options :: any() | [factory_option()]) :: t()

Factory for pos_integer() wrapped by Tyyppi.Value

Specs

string() :: t()

Creates a not defined String.t() wrapped by Tyyppi.Value

Specs

string(options :: any() | [factory_option()]) :: t()

Factory for String.t() wrapped by Tyyppi.Value

Specs

struct() :: t()

Creates a not defined struct wrapped by Tyyppi.Value

Specs

struct(options :: [factory_option()]) :: t()
struct(value :: struct()) :: t()

Factory for struct wrapped by Tyyppi.Value

Specs

timeout() :: t()

Creates a not defined timeout() wrapped by Tyyppi.Value

Specs

timeout(options :: any() | [factory_option()]) :: t()

Factory for timeout() wrapped by Tyyppi.Value