Typle.Type (Typle v0.1.0)

View Source

Representation of Elixir set-theoretic types.

Each type is a struct with a kind field indicating the type category and a params field carrying kind-specific data. The dynamic? flag indicates whether the type is wrapped in dynamic().

Summary

Functions

Returns the atom() type, optionally with a literal value.

Returns the binary() type.

Returns the bitstring() type.

Returns true or false -- the boolean type.

Returns dynamic() or dynamic(inner).

Returns the empty_list() type.

Returns the float() type.

Returns a function() type with the given clauses.

Returns the integer() type.

Returns an intersection of the given types. Single-element intersections collapse.

Returns a list() type with the given element type (defaults to term()).

Returns a map() type with optional keys and open/closed flag.

Returns the negation of the given type.

Returns the none() type (bottom type, empty set).

Returns true if the type represents the empty/bottom type.

Returns integer() or float() -- the number type.

Returns an open tuple type (at least the given elements, possibly more).

Returns the pid() type.

Returns the port() type.

Returns the reference() type.

Returns the term() type (top type, set of all values).

Returns true if the type represents the unknown/top type.

Formats the type using Elixir's type notation.

Returns a closed tuple type with the given element types.

Returns a union of the given types. Single-element unions collapse.

Types

kind()

@type kind() ::
  :integer
  | :float
  | :binary
  | :bitstring
  | :atom
  | :tuple
  | :list
  | :empty_list
  | :map
  | :function
  | :pid
  | :port
  | :reference
  | :union
  | :intersection
  | :negation
  | :none
  | :term

t()

@type t() :: %Typle.Type{dynamic?: boolean(), kind: kind(), params: term()}

Functions

atom(literal \\ nil)

@spec atom(atom() | nil) :: t()

Returns the atom() type, optionally with a literal value.

binary()

@spec binary() :: t()

Returns the binary() type.

bitstring()

@spec bitstring() :: t()

Returns the bitstring() type.

boolean()

@spec boolean() :: t()

Returns true or false -- the boolean type.

dynamic(inner \\ term())

@spec dynamic(t()) :: t()

Returns dynamic() or dynamic(inner).

empty_list()

@spec empty_list() :: t()

Returns the empty_list() type.

float()

@spec float() :: t()

Returns the float() type.

function(clauses)

@spec function([{[t()], t()}]) :: t()

Returns a function() type with the given clauses.

integer()

@spec integer() :: t()

Returns the integer() type.

intersection(types)

@spec intersection([t()]) :: t()

Returns an intersection of the given types. Single-element intersections collapse.

list(elem_type \\ term())

@spec list(t()) :: t()

Returns a list() type with the given element type (defaults to term()).

map(keys \\ [], open? \\ true)

@spec map(
  keyword(),
  boolean()
) :: t()

Returns a map() type with optional keys and open/closed flag.

negation(type)

@spec negation(t()) :: t()

Returns the negation of the given type.

none()

@spec none() :: t()

Returns the none() type (bottom type, empty set).

none?(arg1)

@spec none?(t()) :: boolean()

Returns true if the type represents the empty/bottom type.

number()

@spec number() :: t()

Returns integer() or float() -- the number type.

open_tuple(elements)

@spec open_tuple([t()]) :: t()

Returns an open tuple type (at least the given elements, possibly more).

pid()

@spec pid() :: t()

Returns the pid() type.

port()

@spec port() :: t()

Returns the port() type.

reference()

@spec reference() :: t()

Returns the reference() type.

term()

@spec term() :: t()

Returns the term() type (top type, set of all values).

term?(arg1)

@spec term?(t()) :: boolean()

Returns true if the type represents the unknown/top type.

to_string(type)

@spec to_string(t()) :: String.t()

Formats the type using Elixir's type notation.

Examples

iex> Typle.Type.to_string(Typle.Type.integer())
"integer()"

iex> Typle.Type.to_string(Typle.Type.union([Typle.Type.atom(:ok), Typle.Type.atom(:error)]))
":error or :ok"

tuple(elements)

@spec tuple([t()]) :: t()

Returns a closed tuple type with the given element types.

union(types)

@spec union([t()]) :: t()

Returns a union of the given types. Single-element unions collapse.