Brex v0.2.3 Brex.Rule behaviour View Source
The behaviour for module based rules which requires an evaluate/1
function.
Also offers some helpful functions to deal with all kinds of rules.
Furthermore contains the Brex.Rule.Evaluable
protocol which represents the
basic building block of Brex
. Currently supported rule types are:
atom
or rather Modulesfunction
with arity 1struct
s, take a look atBrex.Rule.Struct
for details
Example - Module based rule
defmodule OkRule do
@behaviour Brex.Rule
@impl Brex.Rule
def evaluate(:ok), do: true
@impl Brex.Rule
def evaluate({:ok, _}), do: true
@impl Brex.Rule
def evaluate(_), do: false
end
Link to this section Summary
Functions
Calls evaluate/2
with the given rule and value and wraps it in a
Brex.Result
struct
Returns the number of clauses this rule has
Returns the type or rather the implementation module for
Brex.Rule.Evaluable
Link to this section Types
Link to this section Functions
Link to this function
evaluate(rule, value)
View Source
evaluate(t(), Brex.Types.value()) :: Brex.Types.result()
Calls evaluate/2
with the given rule and value and wraps it in a
Brex.Result
struct.
Link to this function
number_of_clauses(rules)
View Source
number_of_clauses(t() | [t()]) :: non_neg_integer()
Returns the number of clauses this rule has.
Examples
iex> Brex.Rule.number_of_clauses([])
0
iex> rules = [fn _ -> true end]
iex> Brex.Rule.number_of_clauses(rules)
1
iex> rules = [fn _ -> true end, Brex.any(fn _ -> false end, fn _ -> true end)]
iex> Brex.Rule.number_of_clauses(rules)
3
Returns the type or rather the implementation module for
Brex.Rule.Evaluable
.
Examples
iex> Brex.Rule.type(&is_list/1)
Brex.Rule.Evaluable.Function
iex> Brex.Rule.type(SomeModuleRule)
Brex.Rule.Evaluable.Atom
iex> Brex.Rule.type(Brex.all([]))
Brex.Rule.Evaluable.Brex.Operator
iex> Brex.Rule.type("something")
nil
Link to this section Callbacks
Link to this callback
evaluate(value)
View Source
evaluate(value :: Brex.Types.value()) :: Brex.Types.evaluation()