Skip to content

Operators and Functions

TinySystems expressions support a variety of operators and built-in functions for data manipulation.

Arithmetic Operators

Basic Math

OperatorDescriptionExampleResult
+Addition{{5 + 3}}8
-Subtraction{{10 - 4}}6
*Multiplication{{6 * 7}}42
/Division{{15 / 3}}5
%Modulo (remainder){{17 % 5}}2

With Variables

yaml
total: {{$.price * $.quantity}}
discount: {{$.total * 0.1}}
finalPrice: {{$.total - $.discount}}
average: {{$.sum / $.count}}

Operator Precedence

Standard mathematical precedence applies:

  1. Parentheses ()
  2. Multiplication, Division, Modulo *, /, %
  3. Addition, Subtraction +, -
yaml
# Without parentheses: 2 + (3 * 4) = 14
result1: {{2 + 3 * 4}}

# With parentheses: (2 + 3) * 4 = 20
result2: {{(2 + 3) * 4}}

Comparison Operators

OperatorDescriptionExample
==Equal{{$.a == $.b}}
!=Not equal{{$.a != $.b}}
>Greater than{{$.a > $.b}}
<Less than&#123;&#123;$.a < $.b&#125;&#125;
>=Greater or equal&#123;&#123;$.a >= $.b&#125;&#125;
<=Less or equal&#123;&#123;$.a <= $.b&#125;&#125;

Examples

yaml
isEqual: {{$.count == 10}}
isPositive: {{$.value > 0}}
inRange: {{$.age >= 18 && $.age <= 65}}
isEmpty: {{$.items.length == 0}}

Type Comparison

yaml
# String comparison
isAdmin: {{$.role == 'admin'}}

# Number comparison
isExpensive: {{$.price > 100}}

# Boolean comparison
isActive: {{$.enabled == true}}

Logical Operators

OperatorDescriptionExample
&&Logical AND&#123;&#123;$.a && $.b&#125;&#125;
||Logical OR&#123;&#123;$.a || $.b&#125;&#125;
!Logical NOT&#123;&#123;!$.a&#125;&#125;

Truth Tables

AND (&&)

ABA && B
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

OR (||)

ABA || B
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

Complex Conditions

yaml
# Multiple conditions
canAccess: {{$.isLoggedIn && $.hasPermission}}

# Either condition
notify: {{$.isUrgent || $.isHighPriority}}

# Negation
isDisabled: {{!$.enabled}}

# Combined
showWarning: {{($.count > 100 || $.force) && !$.silent}}

Ternary Operator

The conditional (ternary) operator:

condition ? valueIfTrue : valueIfFalse

Basic Usage

yaml
status: "{{$.active ? 'enabled' : 'disabled'}}"
message: "{{$.count > 0 ? 'Has items' : 'Empty'}}"

Nested Ternary

yaml
# Multiple conditions (use sparingly for readability)
grade: "{{$.score >= 90 ? 'A' : ($.score >= 80 ? 'B' : ($.score >= 70 ? 'C' : 'F'))}}"

Type-Preserving

yaml
# Return different types based on condition
result: {{$.hasData ? $.data : []}}
value: {{$.count > 0 ? $.count : 0}}

String Operators

Concatenation

Use + to join strings:

yaml
fullName: "{{$.firstName + ' ' + $.lastName}}"
url: "{{$.baseUrl + '/api/' + $.endpoint}}"

Template Strings

Embed expressions in strings:

yaml
greeting: "Hello, {{$.name}}!"
summary: "Order {{$.orderId}}: {{$.itemCount}} items totaling ${{$.total}}"

Default Value Operator

The || operator provides fallback values:

yaml
# Use default if null/undefined/empty
name: "{{$.name || 'Anonymous'}}"
count: {{$.count || 0}}
items: {{$.list || []}}

# Chain multiple defaults
value: "{{$.primary || $.secondary || $.fallback || 'default'}}"

Built-in Functions

Time Functions

now()

Returns the current timestamp as a Unix timestamp in nanoseconds:

yaml
timestamp: "{{now()}}"

RFC3339()

Formats a timestamp as RFC3339 string:

yaml
formatted: "{{RFC3339(now())}}"
# Output: "2024-01-15T10:30:00Z"

Type Conversion Functions

string()

Convert to string:

yaml
countStr: "{{string($.count)}}"
boolStr: "{{string($.active)}}"

int()

Convert to integer:

yaml
num: {{int($.stringNumber)}}
rounded: {{int($.floatValue)}}

String Functions

upper()

Convert to uppercase:

yaml
loud: "{{upper($.text)}}"
# "hello" → "HELLO"

lower()

Convert to lowercase:

yaml
quiet: "{{lower($.text)}}"
# "HELLO" → "hello"

trim()

Remove whitespace from ends:

yaml
clean: "{{trim($.input)}}"
# "  hello  " → "hello"

len()

Get string length:

yaml
length: {{len($.text)}}

Math Functions

round()

Round to nearest integer:

yaml
rounded: {{round($.value)}}
# 3.7 → 4
# 3.2 → 3

floor()

Round down:

yaml
floored: {{floor($.value)}}
# 3.7 → 3
# 3.2 → 3

ceil()

Round up:

yaml
ceiling: {{ceil($.value)}}
# 3.2 → 4
# 3.7 → 4

abs()

Absolute value:

yaml
absolute: {{abs($.value)}}
# -5 → 5
# 5 → 5

Array Functions

len() for Arrays

Get array length:

yaml
count: {{len($.items)}}

Or use .length property:

yaml
count: {{$.items.length}}

Operator Summary Table

CategoryOperators
Arithmetic+ - * / %
Comparison== != > < >= <=
Logical&& || !
Conditional? :
Default||
Member Access. []

Function Summary Table

FunctionPurposeExample
now()Current timestamp&#123;&#123;now()&#125;&#125;
RFC3339()Format timestamp&#123;&#123;RFC3339(now())&#125;&#125;
string()Convert to string&#123;&#123;string(42)&#125;&#125;
int()Convert to integer&#123;&#123;int("42")&#125;&#125;
upper()Uppercase string&#123;&#123;upper("hi")&#125;&#125;
lower()Lowercase string&#123;&#123;lower("HI")&#125;&#125;
trim()Trim whitespace&#123;&#123;trim(" hi ")&#125;&#125;
len()Length of string/array&#123;&#123;len($.items)&#125;&#125;
round()Round number&#123;&#123;round(3.5)&#125;&#125;
floor()Round down&#123;&#123;floor(3.9)&#125;&#125;
ceil()Round up&#123;&#123;ceil(3.1)&#125;&#125;
abs()Absolute value&#123;&#123;abs(-5)&#125;&#125;

Combining Operations

Complex Calculations

yaml
# Calculate discounted total
subtotal: {{$.price * $.quantity}}
discount: {{$.subtotal * ($.discountPercent / 100)}}
tax: {{($.subtotal - $.discount) * 0.08}}
total: {{$.subtotal - $.discount + $.tax}}

Conditional Formatting

yaml
# Format based on value
display: "{{$.count > 0 ? string($.count) + ' items' : 'Empty'}}"

# Price formatting
priceDisplay: "${{round($.price * 100) / 100}}"

Data Validation

yaml
# Check multiple conditions
isValid: {{$.email != '' && len($.email) > 5 && $.age >= 18}}

# Provide validated value or error
result: "{{$.isValid ? $.data : 'Invalid input'}}"

Next Steps

Build flow-based applications on Kubernetes