Avrogen.Util.Random.Constructors (avrogen v1.1.0)

Copy Markdown View Source

Provides functions that return "constructor functions". A constructor function is a function that expects a rand_state and optional parameters, and, on invocation, returns an updated rand_state and a randomly generated value.

The functions in this module are basically 'lazy' wrappers around eager functions in the parent module.

Thanks to this 'laziness', we can specify lists of alternative constructor functions, from which we can randomly choose an element for evaluation (without forcing all elements to be evaluated up front).

Summary

Types

constructor_fun()

@type constructor_fun() :: (Avrogen.Util.Random.rand_state() ->
                        {Avrogen.Util.Random.rand_state(), any()})

constructor_list()

@type constructor_list() ::
  {atom(), constructor_fun()} | {atom(), [constructor_fun()]}

Functions

boolean()

@spec boolean() :: constructor_fun()

date(opts \\ [])

@spec date(Keyword.t()) :: constructor_fun()

datetime(opts \\ [])

@spec datetime(Keyword.t()) :: constructor_fun()

decimal(opts \\ [])

@spec decimal(Keyword.t()) :: constructor_fun()

duration(opts \\ [])

@spec duration(Keyword.t()) :: constructor_fun()

enum_value(enum_module)

@spec enum_value(atom()) :: constructor_fun()

float(opts \\ [])

@spec float(Keyword.t()) :: constructor_fun()

instantiate(rand_state, struct_name, constructors)

Instantiates a struct with random values as per the given constructors list. Returns the updated rand_state and the instantiated struct.

integer(opts \\ [])

@spec integer(Keyword.t()) :: constructor_fun()

list(constructor_fun, max_length \\ 10)

@spec list(constructor_fun(), integer()) :: constructor_fun()

map(value_constructor, opts \\ [])

nothing()

@spec nothing() :: constructor_fun()

string(opts \\ [])

@spec string(Keyword.t()) :: constructor_fun()

time(opts \\ [])

@spec time(Keyword.t()) :: constructor_fun()

uuid(opts \\ [])