View Source Drops.Types.Map.DSL (drops v0.1.0)
DSL functions for defining map key and value type specifications.
Functions from this module are typically used via Drops.Contract.schema/1
Summary
Functions
Returns :any type specification.
Returns a boolean type specification.
Returns a type cast specification.
Returns a float type specification.
Returns a float type specification with additional constraints.
Returns an integer type specification.
Returns an integer type specification with additional constraints.
Returns a list type specification.
Returns a list type specification with a constrained member type
Returns a map type specification.
Returns a map type specification with additional constraints.
Returns a maybe type specification.
Returns a maybe type specification with additional constraints.
Returns an optional key specification.
Returns a required key specification.
Returns a string type specification.
Returns a string type specification with additional constraints.
Returns a type specification.
Returns a type specification with additional constraints.
Types
Functions
@spec any() :: type()
Returns :any type specification.
Examples
any()
@spec boolean() :: type()
Returns a boolean type specification.
Examples
# a boolean with no constraints
boolean()
Returns a type cast specification.
Examples
# cast a string to an integer
cast(:string) |> integer()
# cast a string to an integer with additional constraints
cast(string(match?: ~r/\d+/])) |> integer()
@spec float() :: type()
Returns a float type specification.
Examples
# a float with no constraints
float()
@spec float([]) :: type()
Returns a float type specification with additional constraints.
Examples
# a float with constraints
float(gt?: 1.0)
@spec integer() :: type()
Returns an integer type specification.
Examples
# an integer with no constraints
integer()
Returns an integer type specification with additional constraints.
Examples
# an integer with constraints
integer(:even?)
# an integer with multiple constraints
integer([:even?, gt?: 100])
Returns a list type specification.
Examples
# a list with a specified member type
list(:string)
# a list with a specified sum member type
list([:string, :integer])
Returns a list type specification with a constrained member type
Examples
# a list with a specified member type
list(:string, [:filled?])
list(:integer, [gt?: 18])
@spec map() :: type()
Returns a map type specification.
Examples
# a map with no constraints
map()
Returns a map type specification with additional constraints.
Examples
# a map with constraints
map(min_size?: 2)
Returns a maybe type specification.
Examples
# either a nil or a string
maybe(:string)
Returns a maybe type specification with additional constraints.
Examples
# either a nil or a non-empty string
maybe(:string, [:filled?])
Returns an optional key specification.
Examples
%{
optional(:age) => type(:integer)
}
Returns a required key specification.
Examples
%{
required(:email) => type(:string)
}
@spec string() :: type()
Returns a string type specification.
Examples
# a string with no constraints
string()
Returns a string type specification with additional constraints.
Examples
# a string with constraints
string(:filled?)
# a string with multiple constraints
string([:filled?, max_length?: 255])
@spec type({atom(), []}) :: type()
@spec type([{:list, atom()}]) :: type()
@spec type([{:list, []}]) :: type()
@spec type([atom()]) :: [type()]
@spec type(atom()) :: type()
Returns a type specification.
Examples
# string
type(:string)
# either a nil or a string
type([:nil, :string])
Returns a type specification with additional constraints.
Examples
# string with that must be filled
type(:string, [:filled?]),
# an integer that must be greater than 18
type(:integer, [gt?: 18])