View Source Tyyppi.Valuable behaviour (tyyppi v0.12.3)

The behaviour all participants of the Tyyppi’s operations should have implemented.

It’s implemented by Tyyppi.Value and Tyyppi.Struct, making them available for deep nested validations, coercion and generation.

Link to this section Summary

Types

Type returned from coercions and validations, typical pair of ok/error tuples, involving the value() as a main type behind

Type of the generation function, basically returning a stream of generated values

Type of the value behind the implementation

Callbacks

The coercion function, receiving the value()

Flattens the struct using the options passed

The generation function, returning the generator for the whole

The validation function, receiving the value()

Link to this section Types

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

Type returned from coercions and validations, typical pair of ok/error tuples, involving the value() as a main type behind

@type generation() :: StreamData.t(value())

Type of the generation function, basically returning a stream of generated values

@type value() :: any()

Type of the value behind the implementation

Link to this section Callbacks

@callback coerce(value()) :: either()

The coercion function, receiving the value()

@callback flatten(
  value(),
  keyword()
) :: value()

Flattens the struct using the options passed

@callback generation(value()) :: generation()

The generation function, returning the generator for the whole

@callback validate(value()) :: either()

The validation function, receiving the value()