predicator v0.7.3 Predicator.Evaluator

Evaluator Module

Link to this section Summary

Types

Error types returned from Predicator.Evaluator

Link to this section Types

Link to this type error_t()
error_t() ::
  {:error,
   InstructionError.t()
   | ValueError.t()
   | Predicator.InstructionNotCompleteError.t()}

Error types returned from Predicator.Evaluator

Link to this section Functions

Link to this function execute(machine)
Link to this function execute(inst, context \\ %{}, opts \\ [map_type: :string, nil_values: ["", nil]])

Execute will evaluate a predicator instruction set.

If your context struct is using string_keyed map then you will need to pass in the [map_type: :string] options to the execute function to evaluate.

Examples:

iex> Predicator.Evaluator.execute([[“lit”, true]]) true

iex> Predicator.Evaluator.execute([[“lit”, 2], [“lit”, 3], [“comparator”, “LT”]]) true

iex> Predicator.Evaluator.execute([[“load”, “age”], [“lit”, 18], [“comparator”, “GT”]], %{age: 19}) true

iex> Predicator.Evaluator.execute([[“load”, “name”], [“lit”, “jrichocean”], [“comparator”, “EQ”]], %{age: 19}) {:error, %Predicator.ValueError{error: “Non valid load value to evaluate”, instruction_pointer: 0, instructions: [[“load”, “name”], [“lit”, “jrichocean”], [“comparator”, “EQ”]], stack: [], opts: [map_type: :string, nil_values: [“”, nil]]}}

iex> Predicator.Evaluator.execute([[“load”, “age”], [“lit”, 18], [“comparator”, “GT”]], %{“age” => 19}, [map_type: :string]) true

Link to this function to_machine(instructions, context, opts)