Predicator.Functions.SystemFunctions (predicator v2.2.0)

View Source

Built-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 string
  • upper(string) - Converts string to uppercase
  • lower(string) - Converts string to lowercase
  • trim(string) - Removes leading and trailing whitespace

Numeric Functions

  • abs(number) - Returns the absolute value of a number
  • max(a, b) - Returns the larger of two numbers
  • min(a, b) - Returns the smaller of two numbers

Date Functions

  • year(date) - Extracts the year from a date or datetime
  • month(date) - Extracts the month from a date or datetime
  • day(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

function_result()

@type function_result() :: {:ok, Predicator.Types.value()} | {:error, binary()}

Functions

all_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