Predicator.Functions.SystemFunctions (predicator v3.7.0)
View SourceBuilt-in helper functions for use in predicator expressions.
This module provides a collection of utility functions that can be called within predicator expressions using function call syntax. These functions operate on values from the evaluation context and return computed results.
Available Functions
String Functions
len(string)- Returns the length of a stringupper(string)- Converts string to uppercaselower(string)- Converts string to lowercasetrim(string)- Removes leading and trailing whitespacestarts_with(string, prefix)- Tests whether a string starts with a prefixends_with(string, suffix)- Tests whether a string ends with a suffixsubstring(string, start[, len])- Extracts a substring from a start indexindex_of(string, sub)- Finds the index of a substring, or -1
List Functions
concat(list1, list2)- Concatenates two lists
Examples
iex> Predicator.evaluate("len('hello')", %{})
{:ok, 5}
iex> Predicator.evaluate("upper('world')", %{})
{:ok, "WORLD"}
iex> Predicator.evaluate("starts_with('hello world', 'hello')", %{})
{:ok, true}
iex> Predicator.evaluate("ends_with('hello world', 'world')", %{})
{:ok, true}
iex> Predicator.evaluate("substring('hello world', 6)", %{})
{:ok, "world"}
iex> Predicator.evaluate("substring('hello world', 0, 5)", %{})
{:ok, "hello"}
iex> Predicator.evaluate("index_of('hello world', 'world')", %{})
{:ok, 6}
iex> Predicator.evaluate("index_of('hello world', 'nope')", %{})
{:ok, -1}
iex> Predicator.evaluate("concat([1, 2], [3])", %{})
{:ok, [1, 2, 3]}
Summary
Functions
Returns all system functions as a map in the format expected by the evaluator.
Types
@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}
Functions
@spec all_functions() :: %{ required(binary()) => {Predicator.Evaluator.function_arity(), function()} }
Returns all system functions as a map in the format expected by the evaluator.
Returns
A map where keys are function names and values are {arity, function} tuples.
Examples
iex> functions = Predicator.Functions.SystemFunctions.all_functions()
iex> Map.has_key?(functions, "len")
true
iex> {arity, _function} = functions["len"]
iex> arity
1