Dx.Defd.Fn (dx v0.3.5)

View Source

Internal wrapper for a function.

This includes multiple compiled versions of the function, plus some meta information on whether the function can ever load any data (i.e. return {:not_loaded, ...} instead of {:ok, ...}).

The final_args versions assume that arguments are already finalized, i.e. hold no Dx.Scope or Dx.Defd.Fn structs.

Summary

Types

t()

A wrapper struct for a function with multiple compiled versions and metadata.

Functions

Extracts the defd-compatible function from a Dx.Defd.Fn struct if given one, otherwise returns the input unchanged.

Extracts the final_args_ok_fun from a Dx.Defd.Fn struct if given one, otherwise returns the input unchanged. The final_args_ok_fun assumes final arguments and is guaranteed to return {:ok, result}.

Extracts the ok_fun from a Dx.Defd.Fn struct if given one, otherwise returns the input unchanged. The ok_fun is guaranteed to return {:ok, result}.

Convert a function or Dx.Defd.Fn struct to a function returning a Dx.Defd.Result.

Types

t()

@type t() :: %Dx.Defd.Fn{
  final_args_fun: function(),
  final_args_ok?: boolean(),
  final_args_ok_fun: function() | nil,
  fun: function(),
  ok?: boolean(),
  ok_fun: function() | nil,
  scope: function()
}

A wrapper struct for a function with multiple compiled versions and metadata.

Fields:

  • :ok? - Whether the function can be guaranteed to return {:ok, result}
  • :final_args_ok? - Whether the function can be guaranteed to return {:ok, result} when given final arguments
  • :fun - defd-compatible function that may return {:not_loaded, ...} or {:ok, ...}
  • :ok_fun - Version of function guaranteed to return {:ok, ...} (can be nil)
  • :final_args_fun - Version of function that assumes final arguments
  • :final_args_ok_fun - Version of function that assumes final arguments and returns {:ok, ...} (can be nil)
  • :scope - scope version of the function. See Dx.Scope.

Functions

maybe_unwrap(other)

Extracts the defd-compatible function from a Dx.Defd.Fn struct if given one, otherwise returns the input unchanged.

maybe_unwrap_final_args_ok(other)

Extracts the final_args_ok_fun from a Dx.Defd.Fn struct if given one, otherwise returns the input unchanged. The final_args_ok_fun assumes final arguments and is guaranteed to return {:ok, result}.

maybe_unwrap_ok(other)

Extracts the ok_fun from a Dx.Defd.Fn struct if given one, otherwise returns the input unchanged. The ok_fun is guaranteed to return {:ok, result}.

to_defd_fun(fun)

Convert a function or Dx.Defd.Fn struct to a function returning a Dx.Defd.Result.