Built-in Functions
Ordo provides a comprehensive set of built-in functions for use in expressions.
String Functions
len(string)
Returns the length of a string.
len("hello") # 5
len("") # 0
len(user.name) # depends on nameupper(string)
Converts string to uppercase.
upper("hello") # "HELLO"
upper(code) # uppercase of codelower(string)
Converts string to lowercase.
lower("HELLO") # "hello"
lower(email) # lowercase emailtrim(string)
Removes leading and trailing whitespace.
trim(" hello ") # "hello"
trim(input) # trimmed inputcontains(string, substring)
Checks if string contains substring.
contains("hello world", "world") # true
contains(email, "@gmail.com") # true if Gmailstarts_with(string, prefix)
Checks if string starts with prefix.
starts_with("hello", "he") # true
starts_with(order_id, "ORD-") # true if starts with ORD-ends_with(string, suffix)
Checks if string ends with suffix.
ends_with("hello", "lo") # true
ends_with(filename, ".pdf") # true if PDF fileArray Functions
len(array)
Returns the number of elements in an array.
len([1, 2, 3]) # 3
len(order.items) # number of items
len([]) # 0sum(array)
Returns the sum of numeric array elements.
sum([1, 2, 3]) # 6
sum(prices) # total of prices
sum([]) # 0avg(array)
Returns the average of numeric array elements.
avg([1, 2, 3]) # 2
avg(scores) # average score
avg([10]) # 10min(array)
Returns the minimum value in an array.
min([3, 1, 2]) # 1
min(bids) # lowest bidmax(array)
Returns the maximum value in an array.
max([3, 1, 2]) # 3
max(scores) # highest scoreNumeric Functions
abs(number)
Returns the absolute value.
abs(-5) # 5
abs(5) # 5
abs(balance) # positive balanceround(number)
Rounds to the nearest integer.
round(3.4) # 3
round(3.5) # 4
round(3.6) # 4floor(number)
Rounds down to the nearest integer.
floor(3.9) # 3
floor(3.1) # 3
floor(-3.1) # -4ceil(number)
Rounds up to the nearest integer.
ceil(3.1) # 4
ceil(3.9) # 4
ceil(-3.9) # -3Utility Functions
exists(field)
Checks if a field exists and is not null.
exists(user.email) # true if email exists
exists(optional_field) # false if null/missingUse this to safely check optional fields before accessing them:
exists(discount) && discount > 0coalesce(value1, value2, ...)
Returns the first non-null value.
coalesce(null, "default") # "default"
coalesce(user.nickname, user.name) # nickname or name
coalesce(a, b, c, "fallback") # first non-nullCommon patterns:
# Default value
coalesce(config.timeout, 30)
# Fallback chain
coalesce(user.display_name, user.full_name, user.email, "Anonymous")
# Safe field access
coalesce(response.data.value, 0)Function Composition
Functions can be composed:
# Uppercase and check length
len(upper(name)) > 0
# Sum and compare
sum(prices) > avg(prices) * len(prices)
# Coalesce with transformation
upper(coalesce(code, "DEFAULT"))Type Handling
Functions handle type conversions automatically:
# len works on strings and arrays
len("hello") # 5
len([1, 2, 3]) # 3
# Numeric functions convert strings
abs("-5") # 5
sum(["1", "2"]) # 3Error Handling
Functions return sensible defaults on errors:
| Scenario | Result |
|---|---|
len(null) | 0 |
sum([]) | 0 |
avg([]) | 0 |
upper(null) | "" |
coalesce(null, null) | null |
Performance Notes
- All functions are optimized for high performance
- String operations use zero-copy where possible
- Array functions use iterators (no intermediate allocations)
- Function calls add ~10-50ns overhead