predicator v0.5.0 Predicator.Evaluator

Evaluator Module

Link to this section Summary

Link to this section Types

Link to this section Functions

Link to this function execute(inst, context_struct \\ %{}, opts \\ [map_type: :atom])

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], ["compare", "LT"]])
  true

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

  iex> Predicator.Evaluator.execute([["load", "name"], ["lit", "jrichocean"], ["compare", "EQ"]], %{age: 19})
  {:error, %Predicator.ValueError{error: "Non valid load value to evaluate", instruction_pointer: 0, instructions: [["load", "name"], ["lit", "jrichocean"], ["compare", "EQ"]], stack: [], opts: [map_type: :atom]}}

  iex> Predicator.Evaluator.execute([["load", "age"], ["lit", 18], ["compare", "GT"]], %{"age" => 19}, [map_type: :string])
  true
Link to this function instruction_not_complete_err(machine)