Predicator.Functions.SystemFunctions (predicator v2.2.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 whitespace
Numeric Functions
abs(number)
- Returns the absolute value of a numbermax(a, b)
- Returns the larger of two numbersmin(a, b)
- Returns the smaller of two numbers
Date Functions
year(date)
- Extracts the year from a date or datetimemonth(date)
- Extracts the month from a date or datetimeday(date)
- Extracts the day from a date or datetime
Examples
iex> Predicator.BuiltInFunctions.call("len", ["hello"])
{:ok, 5}
iex> Predicator.BuiltInFunctions.call("upper", ["world"])
{:ok, "WORLD"}
iex> Predicator.BuiltInFunctions.call("max", [10, 5])
{:ok, 10}
iex> Predicator.BuiltInFunctions.call("unknown", [])
{:error, "Unknown function: unknown"}
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()) => {non_neg_integer(), 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