Expression.V2.Callbacks (expression v2.33.1)

Use this module to implement one's own callbacks. The standard callbacks available are implemented in Expression.V2.Callbacks.Standard.

defmodule MyCallbacks do
  use Expression.V2.Callbacks

  @doc """
  Roll a dice and randomly return a number between 1 and 6.
  """
  def dice_roll(ctx) do
    Enum.random(1..6)
  end

end

Summary

Functions

Convert a string function name into an atom meant to handle that function

Callback a function while evaluating the context against an expression.

Functions

Link to this function

atom_function_name(function_name)

Convert a string function name into an atom meant to handle that function

Reserved words such as and, if, and or are automatically suffixed with an _ underscore.

Link to this function

callback(module \\ Standard, context, function_name, arguments)

@spec callback(
  module :: module(),
  context :: map(),
  function_name :: binary(),
  arguments :: [any()]
) :: any()

Callback a function while evaluating the context against an expression.

Callback functions in this module are either:

  1. The function name as is
  2. The function name with an underscore suffix if the function name is a reserved word
  3. The function name suffixed with _vargs if the takes a variable set of arguments
Link to this function

implements(module \\ Standard, function_name, arguments)

@spec implements(module(), function_name :: String.t(), arguments :: [any()]) ::
  {:exact, module(), function_name :: atom()}
  | {:vargs, module(), function_name :: atom()}
  | {:error, reason :: String.t()}