type_reader v0.0.1 TypeReader

Link to this section Summary

Functions

Will return the entire type chain for the resolved type, if possible.

Will return the resolved type, if possible.

Link to this section Functions

Link to this function

fetch_remote_type_definition(module, type_name, arity)

Link to this function

type_chain_from_quoted(quoted_type)

Will return the entire type chain for the resolved type, if possible.

Examples

iex> TypeReader.type_chain_from_quoted(quote do: Enum.t())
{:ok, [
  %TerminalType{name: :term, bindings: []},
  %RemoteType{module: Enumerable, name: :t, bindings: []},
  %RemoteType{module: Enum, name: :t, bindings: []},
]}
Link to this function

type_from_quoted(quoted_type)

Will return the resolved type, if possible.

Examples

iex> TypeReader.type_from_quoted(quote do: binary())
{:ok, %TerminalType{name: :binary, bindings: []}}

iex> TypeReader.type_from_quoted(quote do: String.t())
{:ok, %TerminalType{name: :binary, bindings: []}}

iex> TypeReader.type_from_quoted(quote do: integer() | float())
{:ok,
  %TerminalType{
    name: :union,
    bindings: [
      elem_types: [
        %TerminalType{name: :integer, bindings: []},
        %TerminalType{name: :float, bindings: []}
    ]
  ]
}}

iex> TypeReader.type_from_quoted(quote do: {:a, [String.t()]})
{:ok,
  %TypeReader.TerminalType{
    bindings: [
      elem_types: [
        %TypeReader.TerminalType{bindings: [value: :a], name: :literal},
        %TypeReader.TerminalType{
          name: :list,
          bindings: [
            type: %TypeReader.TerminalType{bindings: [], name: :binary}
          ],
        }
      ]
    ],
    name: :tuple
  }}