View Source Numscriptex.Run (numscriptex v0.2.2)

A Numscript needs some other data aside from the script itself to run correctly, and Numscriptex.Run solves this problem. If you want to know what exactly these additional fields are, you can learn more on Numscript Playground and the Numscript Docs.

Summary

Types

t()

Type that represents Numscriptex.Run struct.

Functions

Creates a new Numscriptex.Run{} struct.

Puts the chosen value under the field key on the Numscriptex.Run struct as long both are valid.

Same as put/3, but raises an exception if any argument is invalid.

Types

t()

@type t() :: %Numscriptex.Run{balances: map(), metadata: map(), variables: map()}

Type that represents Numscriptex.Run struct.

Fields

Functions

new()

@spec new() :: t()

Creates a new Numscriptex.Run{} struct.

iex>  Numscriptex.Run.new()
%Numscriptex.Run{
  variables: %{},
  balances: %{},
  metadata: %{}
}

put(run_struct, field, value \\ %{})

@spec put(t(), atom(), map()) :: {:ok, t()} | {:error, atom(), map()}

Puts the chosen value under the field key on the Numscriptex.Run struct as long both are valid.

iex> struct = Numscriptex.Run.new()
...> balances =  %{"foo" => %{"USD/2" => 500, "EUR/2" => 300}}
...>
...> Numscriptex.Run.put(struct, :balances, balances)
{:ok,
  %Numscriptex.Run{
    balances: %{"foo" => %{"USD/2" => 500, "EUR/2" => 300}},
    variables: %{},
    metadata: %{}
  }
}

If the value or the field key are invalid, put/3 will return a 3 element error tuple. Ex:

iex> struct = Numscriptex.Run.new()
...>
...> Numscriptex.Run.put(struct, :invalid_field, %{})
{:error, :invalid_field, %{details: "The field 'invalid_field' does not exists."}}

put!(run_struct, field, value)

@spec put!(t(), atom(), map()) :: t() | no_return()

Same as put/3, but raises an exception if any argument is invalid.

iex> struct = Numscriptex.Run.new()
...> balances =  [%{"foo" => %{"USD/2" => 500, "EUR/2" => 300}}]
...>
...> Numscriptex.Run.put!(struct, :balances, balances)
** (ArgumentError) Argument `value` must be a map.