You are reading the documentation for an outdated Corteza release. 2023.9 is the latest stable Corteza release.

Expression Function Reference

Type functions

coalesce(…​Any)

The coalesce function returns the first non-null value.

Table 1. Examples:
State Expression Result
{
}
out = coalesce(null, 0, 1, 2)
{
  "out": 0
}

isEmpty(Any)

The isEmpty function returns true if the value is empty.

What classifies as empty differs from type to type @todo.

Table 2. Examples:
State Expression Result
{
  "in": ""
}
out = isEmpty(in)
{
  "in": "",
  "out": true
}
{
  "in": 0
}
out = isEmpty(in)
{
  "in": 0,
  "out": true
}

isNil(Any)

The isNil function returns true if the given value is null.

Table 3. Examples:
State Expression Result
{
  "in": null
}
out = isNil(in)
{
  "in": null,
  "out": true
}
{
  "in": 10
}
out = isNil(in)
{
  "in": 10,
  "out": false
}

Array functions

push(array, …​elements)

The push function adds a the specified elements to the end of the array and returns a new array.

The original array remains unchanged.

Table 4. Examples:
State Expression Result
{
  "arr": []
}
new = push(arr, 1)
{
  "arr": [],
  "new": [1]
}
{
  "arr": []
}
new = push(arr, 1, 2, 3)
{
  "arr": [],
  "new": [1, 2, 3]
}
{
  "stuff": [1, 2, 3]
}
new = push([], 1, 2, 3)
{
  "new": [1, 2, 3]
}

pop(array)

The pop function returns the last element of the array.

The original array remains unchanged

Table 5. Examples:
State Expression Result
{
  "arr": [1, 2, 3]
}
last = pop(arr)
{
  "arr": [1, 2, 3],
  "last": 3
}
{
  "arr": []
}
last = pop(arr)
{
  "arr": [],
  "last": null
}

When Any type is used the value will be null. When other type is used, the value will be the zero value of that type.

{

}
last = pop([])
{
  "last": null
}

When Any type is used the value will be null. When other type is used, the value will be the zero value of that type.

shift(array)

The shift function returns the first element of the array.

The original array remains unchanged

Table 6. Examples:
State Expression Result
{
  "arr": [1, 2, 3]
}
first = shift(arr)
{
  "arr": [1, 2, 3],
  "first": 1
}
{
  "arr": []
}
first = shift(arr)
{
  "arr": [],
  "first": null
}

When Any type is used the value will be null. When other type is used, the value will be the zero value of that type.

{

}
first = shift([])
{
  "first": null
}

When Any type is used the value will be null. When other type is used, the value will be the zero value of that type.

count(array, …​elements)

The count function returns the number of occurrences for the given elements.

The count function returns the length of the array if no element is provided.

Table 7. Examples:
State Expression Result
{
  "arr": ["a", "b", "c"]
}
nm = count(arr, "a")
{
  "arr": ["a", "b", "c"],
  "nm": 1
}
{
  "arr": ["a", "b", "c"]
}
nm = count(arr, "a", "b")
{
  "arr": ["a", "b", "c"],
  "nm": 2
}
{
  "arr": ["a", "b", "c"]
}
nm = count(arr)
{
  "arr": ["a", "b", "c"],
  "nm": 3
}

length(array)

The length function returns the length of the input string

has(arr, …​elements)

The has function checks if the provided array contains any of the elements.

The function returns true if elements are found, else it returns false.

Table 8. Examples:
State Expression Result
{
  "arr": ["a", "b", "c"]
}
out = has(arr, "a")
{
  "arr": ["a", "b", "c"],
  "out": true
}
{
  "arr": ["a", "b", "c"]
}
out = has(arr, "/", "b")
{
  "arr": ["a", "b", "c"],
  "out": true
}
{
  "arr": ["a", "b", "c"]
}
out = has(arr, "a", "b", "c")
{
  "arr": ["a", "b", "c"],
  "out": true
}
{
  "arr": ["a", "b", "c"]
}
out = has(arr, "/")
{
  "arr": ["a", "b", "c"],
  "out": false
}

hasAll(arr, …​elements)

The hasAll function checks if the provided array contains all of the elements.

The function returns true if elements are found, else it returns false.

Table 9. Examples:
State Expression Result
{
  "arr": ["a", "b", "c"]
}
out = hasAll(arr, "a")
{
  "arr": ["a", "b", "c"],
  "out": true
}
{
  "arr": ["a", "b", "c"]
}
out = hasAll(arr, "/", "b")
{
  "arr": ["a", "b", "c"],
  "out": false
}
{
  "arr": ["a", "b", "c"]
}
out = hasAll(arr, "a", "b", "c")
{
  "arr": ["a", "b", "c"],
  "out": true
}
{
  "arr": ["a", "b", "c"]
}
out = hasAll(arr, "/")
{
  "arr": ["a", "b", "c"],
  "out": false
}

find(arr, elements)

The find function returns the position of the given element (zero-based numbering). If the element does not exist, the function returns -1.

Table 10. Examples:
State Expression Result
{
  "arr": ["a", "b", "c"]
}
index = find(arr, "a")
{
  "arr": ["a", "b", "c"],
  "index": 0
}
{
  "arr": ["a", "b", "c"]
}
index = find(arr, "b")
{
  "arr": ["a", "b", "c"],
  "index": 1
}
{
  "arr": ["a", "b", "c"]
}
index = find(arr, "/")
{
  "arr": ["a", "b", "c"],
  "index": -1
}

sort(array, descending)

The sort function returns the sorted array, either ascending if the second parameter is false or descending if the second parameter is true.

The original array remains unchanged.

Table 11. Examples:
State Expression Result
{
  "arr": ["c", "a", "b"]
}
sorted = sort(arr, false)
{
  "arr": ["c", "a", "b"],
  "sorted": ["a", "b", "c"]
}
{
  "arr": ["c", "a", "b"]
}
sorted = sort(arr, true)
{
  "arr": ["c", "a", "b"],
  "sorted": ["c", "b", "a"]
}

String functions

trim(string)

The trim function removes all leading and trailing whitespace defined by the Unicode standard.

List of Unicode whitespaces:
  • U+0020: Space,

  • U+00A0: no-break space,

  • U+1680: ogham space mark,

  • U+180E: mongolian vowel separator,

  • U+2000: en quad,

  • U+2001: em quad,

  • U+2002: en space,

  • U+2003: em space,

  • U+2004: three-per-em space,

  • U+2005: four-per-em space,

  • U+2006: six-per-em space,

  • U+2007: figure space,

  • U+2008: punctuation space,

  • U+2009: thin space,

  • U+200A: hair space,

  • U+200B: zero width space,

  • U+202F: narrow no-break space,

  • U+205F: medium mathematical space,

  • U+3000: ideographic space,

  • U+FEFF: zero width no-break space.

Table 12. Examples:
State Expression Result
{
  "in": "\t abcd \t"
}
out = trim(in)
{
  "in": "\t abcd \t",
  "out": "abcd"
}
{
  "in": "\t ab cd \t"
}
out = trim(in)
{
  "in": "\t abcd \t",
  "out": "ab cd"
}

trimLeft(string, remove)

The trimLeft function removes the specified characters from the start of the string.

Table 13. Examples:
State Expression Result
{
  "in": "abcd"
}
out = trimLeft(in, "ab")
{
  "in": "abcd",
  "out": "cd"
}
{
  "in": "abcd"
}
out = trimLeft(in, "abcd")
{
  "in": "abcd",
  "out": ""
}

trimRight(string, remove)

The trimRight function removes the specified characters from the end of the string.

Table 14. Examples:
State Expression Result
{
  "in": "abcd"
}
out = trimFight(in, "cd")
{
  "in": "abcd",
  "out": "ab"
}
{
  "in": "abcd"
}
out = trimFight(in, "abcd")
{
  "in": "abcd",
  "out": ""
}

toLower(string)

The toLower function returns a new string with upper case letters mapped to their lower case counterpart.

Table 15. Examples:
State Expression Result
{
  "in": "Abcd"
}
out = toLower(in)
{
  "in": "Abcd",
  "out": "abcd"
}
{
  "in": "ABCD"
}
out = toLower(in)
{
  "in": "ABCD",
  "out": "abcd"
}

toUpper(string)

The toUpper function returns a new string with lower case letters mapped to their upper case counterpart.

Table 16. Examples:
State Expression Result
{
  "in": "Abcd"
}
out = toUpper(in)
{
  "in": "Abcd",
  "out": "abcd"
}
{
  "in": "ABCD"
}
out = toUpper(in)
{
  "in": "ABCD",
  "out": "abcd"
}

shortest(string1, …​strings)

The shortest function returns the shortest string from the given arguments.

Table 17. Examples:
State Expression Result
{

}
out = shortest("a", "aa", "aaa")
{
  "out": "a"
}
{

}
out = shortest("a")
{
  "out": "a"
}

longest(arg1, arg2, …​a

The longest function returns the longest string from the given arguments.

Table 18. Examples:
State Expression Result
{

}
out = longest("a", "aa", "aaa")
{
  "out": "aaa"
}
{

}
out = longest("a")
{
  "out": "a"
}

format(format, …​arguments)

The format function returns a new constructed from the given template and arguments. Refer to String Formatting for more details.

Table 19. Examples:
State Expression Result
{

}
out = format("string %s, and float %.2f", "hi", 12.345)
{
  "out": "string hi, and float 12.35"
}

title(string)

The title function turns the first character of to uppercase.

Table 20. Examples:
State Expression Result
{
  "in": "abcd"
}
out = title(in)
{
  "in": "abcd",
  "out": "Abcd"
}
{
  "in": "abcd efg"
}
out = title(in)
{
  "in": "abcd efg",
  "out": "Abcd efg"
}

untitle(string)

The untitle function turns does the opposite from what title(string) does.

Table 21. Examples:
State Expression Result
{
  "in": "Abcd"
}
out = untitle(in)
{
  "in": "Abcd",
  "out": "abcd"
}
{
  "in": "Abcd efg"
}
out = untitle(in)
{
  "in": "Abcd efg",
  "out": "abcd efg"
}

repeat(string, count)

The repeat function returns a new string where the original one is repeated count times.

Table 22. Examples:
State Expression Result
{
  "in": "abcd"
}
out = count(in, 1)
{
  "in": "abcd",
  "out": "abcd"
}
{
  "in": "abcd"
}
out = count(in, 2)
{
  "in": "abcd",
  "out": "abcdabcd"
}

replace(string, old, new,

The replace function returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.

Table 23. Examples:
State Expression Result
{
  "in": "foo foo foo"
}
out = replace(in, "foo", "bar", 1)
{
  "in": "foo foo foo",
  "out": "bar foo foo"
}
{
  "in": "foo foo foo"
}
out = replace(in, "foo", "bar", 0)
{
  "in": "foo foo foo",
  "out": "foo foo foo"
}
{
  "in": "foo foo foo"
}
out = replace(in, "foo", "bar", -1)
{
  "in": "foo foo foo",
  "out": "bar bar bar"
}

isUrl(string)

The isUrl function checks if the given string is a valid URL address. If the string is a valid URL the function returns true else it returns false.

Table 24. Examples:
State Expression Result
{
  "in": "https://www.example.tld"
}
out = isUrl(in)
{
  "in": "https://www.example.tld",
  "out": true
}
{
  "in": "uhoh"
}
out = isUrl(in)
{
  "in": "uhoh",
  "out": false
}

isEmail(string)

The isEmail function checks if the given string is a valid email address. If the string is a valid email the function returns true else it returns false.

Table 25. Examples:
State Expression Result
{
  "in": "hi@email.tld"
}
out = isEmail(in)
{
  "in": "hi@email.tld",
  "out": true
}
{
  "in": "uhoh"
}
out = isEmail(in)
{
  "in": "uhoh",
  "out": false
}

split(string, separator)

The split function returns an array of strings where the original string is split by the separator.

Table 26. Examples:
State Expression Result
{
  "in": "aa.bb.cc"
}
out = split(in, ".")
{
  "in": "aa.bb.cc",
  "out": ["aa", "bb", "cc"]
}
{
  "in": "aa.bb.cc"
}
out = split(in, "/")
{
  "in": "aa.bb.cc",
  "out": ["aa.bb.cc"]
}

join(strings, separator)

The join function joins the strings from the array into a single string separated by the separator.

Table 27. Examples:
State Expression Result
{
  "in": ["aa", "bb", "cc"]
}
out = join(in, ".")
{
  "in": ["aa", "bb", "cc"],
  "out": "aa.bb.cc"
}

hasSubstring(string, substring, case)

The hasSubstring function checks if the given string contains the substring.

When the third argument is true the function is case sensitive else it is not.

Table 28. Examples:
State Expression Result
{
  "in": "abcd"
}
out = hasSubstring(in, "bc", false)
{
  "in": "abcd",
  "out": true
}
{
  "in": "aBCd"
}
out = hasSubstring(in, "bc", false)
{
  "in": "aBCd",
  "out": true
}
{
  "in": "aBCd"
}
out = hasSubstring(in, "bc", true)
{
  "in": "aBCd",
  "out": false
}
{
  "in": "abcd"
}
out = hasSubstring(in, "xy", false)
{
  "in": "abcd",
  "out": false
}

substring(string, start, end)

The substring function returns the substring of the given string.

Both start and end are inclusive ([start, end])

Table 29. Examples:
State Expression Result
{
  "in": "abcd"
}
out = substring(in, 1, 2)
{
  "in": "abcd",
  "out": "bc"
}
{
  "in": "abcd"
}
out = substring(in, 1, -1)
{
  "in": "abcd",
  "out": "bcd"
}
{
  "in": "abcd"
}
out = substring(in, 4, -1)
{
  "in": "abcd",
  "out": ""
}

hasPrefix(string, prefix)

The hasPrefix function checks if the given string includes the prefix. If the prefix exists the function returns true else it returns false.

Table 30. Examples:
State Expression Result
{
  "in": "abcd"
}
out = hasPrefix(in, "ab")
{
  "in": "abcd",
  "out": true
}
{
  "in": "abcd"
}
out = hasPrefix(in, "cd")
{
  "in": "abcd",
  "out": false
}
{
  "in": "abcd"
}
out = hasPrefix(in, "xy")
{
  "in": "abcd",
  "out": false
}

hasSuffix(string, prefix)

The hasSuffix function checks if the given string includes the suffix. If the suffix exists the function returns true else it returns false.

Table 31. Examples:
State Expression Result
{
  "in": "abcd"
}
out = hasSuffix(in, "cd")
{
  "in": "abcd",
  "out": true
}
{
  "in": "abcd"
}
out = hasSuffix(in, "ab")
{
  "in": "abcd",
  "out": false
}
{
  "in": "abcd"
}
out = hasSuffix(in, "xy")
{
  "in": "abcd",
  "out": false
}

shorten(string, type, count)

The shorten function cuts off the given string at count characters or words when type is set to char.

The string is suffixed with ellipsis after the cutoff point.

Table 32. Examples:
State Expression Result
{
  "in": "This is a whole sentence"
}
out = shorten(in, "word", 4)
{
  "in": "This is a whole sentence",
  "out": "This is a whole …"
}

camelize(string)

The camelize function returns a new string in the camelCase form.

Table 33. Examples:
State Expression Result
{
  "in": "Foo bar"
}
out = camelize(in)
{
  "in": "Foo bar",
  "out": "fooBar"
}

snakify(string)

The snakify function returns a new string in the snake_case form.

Table 34. Examples:
State Expression Result
{
  "in": "Foo bar baz"
}
out = snakify(in)
{
  "in": "Foo bar baz",
  "out": "foo_bar_baz"
}

match(string, regex)

The match function checks if the string matches the given regular expression.

Table 35. Examples:

State

Expression

Result

base64encode(string)`

The base64encode function returns the base64 encoded input string.

Table 36. Examples:

State

Expression

Result

length(string)

The length function returns the length of the input string

Table 37. Examples:

State

Expression

Result

count(string, …​characters)

The count function returns the number of occurrences for the given characters.

The count function returns the length of the string if no character is provided.

Table 38. Examples:
State Expression Result
{
  "in": "foo"
}
out = count(in, "o")
{
  "in": "foo",
  "out": 2
}

Numeric functions

min(…​number)

The min function returns the number with the lowest value.

Table 39. Examples:
State Expression Result
{
}
out = min(1, 2, 3, -1)
{
  "out": -1
}

max(…​number)

The max function returns the number with the highest value.

Table 40. Examples:
State Expression Result
{
}
out = min(1, 2, 3, -1)
{
  "out": 3
}

round(number, places)

The round function rounds the number to the specified number of places. The function returns a float.

To get rid of the floating point, simply cast to an Integer.

Table 41. Examples:
State Expression Result
{
  "in": 10.123
}
out = round(in, 2)
{
  "in": 10.123,
  "out": 10.12
}
{
  "in": 10.123
}
out = round(in, 0)
{
  "in": 10.123,
  "out": 10
}

floor(number)

The floor function rounds the number down to the nearest integer.

Table 42. Examples:
State Expression Result
{
  "in": 10.123
}
out = floor(in)
{
  "in": 10.123,
  "out": 10
}

ceil(number)

The ceil function rounds the number up to the nearest integer.

Table 43. Examples:
State Expression Result
{
  "in": 10.123
}
out = ceil(in)
{
  "in": 10.123,
  "out": 11
}

abs(number)

The abs function returns the absolute value of the provided number.

Table 44. Examples:
State Expression Result
{
  "in": -10
}
out = abs(in)
{
  "in": -10
  "out": 10
}
{
  "in": 10
}
out = abs(in)
{
  "in": 10
  "out": 10
}

log(number)

The log function returns the base 10 logarithm of the given number.

Table 45. Examples:
State Expression Result
{
  "in": 100
}
out = log(in)
{
  "in": 100
  "out": 2
}

pow(number, exp)

The pow function returns the number to the power of exp.

|pow |pow(number, number)|The function returns x**y, the base-x exponential of y, see math.Pow|pow(2, 3) results in 8

Table 46. Examples:
State Expression Result
{
  "in": 2,
  "exp": 3
}
out = pow(in, exp)
{
  "in": 2,
  "exp": 3,
  "out": 8
}

sqrt(number)

The sqrt function returns the square root of the given number.

Table 47. Examples:
State Expression Result
{
  "in": 4
}
out = sqrt(in)
{
  "in": 4,
  "out": 2
}

sum(…​number)

The sum function returns the sum of all the provided arguments.

Table 48. Examples:
State Expression Result
{
}
out = sum(1, 2, 3, -1)
{
  "out": 5
}

average(…​number)

The average function returns the average from the provided arguments.

Table 49. Examples:
State Expression Result
{
}
out = average(1, 2)
{
  "out": 1.5
}

random(a, b?)

The random function returns a random number. When called with one argument (random(to)) the random number is between 0 and to. When called with two arguments (random(from, to)) the random number is between from and to.

Table 50. Examples:
State Expression Result
{
  "to": 10
}
out = random(to)
{
  "to": 10,
  "out": 3.412
}
{
  "from": 5,
  "to": 10
}
out = random(to)
{
  "from": 5,
  "to": 10,
  "out": 5.9
}

int(Any)

The int function casts the argument to Integer. If the value can not be casted, the function returns 0

When you assign a value to a variable it is automatically casted to the specified type. You only need explicit casting when providing arguments.

Table 51. Examples:
State Expression Result
{
  "in": "10"
}
out = int(in)
{
  "in": "10",
  "out": 10
}
{
  "in": "NO"
}
out = int(in)
{
  "in": "NO",
  "out": 0
}

Date and time functions

earliest(DateTime, …​DateTime)

|earliest |earliest(arg1, arg2, …​argN)|The function returns earliest DateTime.|earliest(datefield1, datefield2) results in "1970-01-01T00:00:00"

The earliest function returns the earliest DateTime.

Table 52. Examples:
State Expression Result
{
}
out = earliest(parseISOTime("2019-01-01T00:00:00Z"), parseISOTime("2020-01-01T00:00:00Z"))
{
  "out": "2019-01-01T00:00:00Z"
}

latest

The latest function returns the latest DateTime.

Table 53. Examples:
State Expression Result
{
}
out = latest(parseISOTime("2019-01-01T00:00:00Z"), parseISOTime("2020-01-01T00:00:00Z"))
{
  "out": "2020-01-01T00:00:00Z"
}

parseISOTime

The parseISOTime function parses the ISO formatted timestamp.

Table 54. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z"
}
out = parseISOTime("2020-01-01T00:00:00Z")
{
  "in": "2020-01-01T00:00:00Z",
  "out": "2020-01-01T00:00:00Z"
}

modTime

The modTime function returns a new DateTime with added duration. The modTime function interacts with the time part of the DateTime.

Use modDate, modWeek, modMonth, or modYear if you wish to adjust larger components.

Table 55. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1h"
}
out = modTime(in, d)
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1h",
  "out": "2020-01-01T01:00:00Z",
}

modDate(datetime, days)

The modDate function returns a new DateTime with added days. The modDate function interacts with the date (days) part of the DateTime.

Table 56. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1"
}
out = modDate(in, d)
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1",
  "out": "2020-01-02T00:00:00Z",
}

modWeek(datetime, weeks)

The modWeek function returns a new DateTime with added weeks. The modWeek function interacts with the date (days) part of the DateTime.

Table 57. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1"
}
out = modWeek(in, d)
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1",
  "out": "2020-01-08T00:00:00Z",
}

modMonth(datetime, months)

The modMonth function returns a new DateTime with added months. The modMonth function interacts with the month part of the DateTime.

Table 58. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1"
}
out = modMonth(in, d)
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1",
  "out": "2020-02-01T00:00:00Z",
}

modYear(datetime, years)

The modYear function returns a new DateTime with added years. The modYear function interacts with the year part of the DateTime.

Table 59. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1"
}
out = modYear(in, d)
{
  "in": "2020-01-01T00:00:00Z",
  "d": "1",
  "out": "2021-00-01T00:00:00Z",
}

parseDuration

The parseDuration function returns the parsed duration from the given string.

Table 60. Examples:
State Expression Result
{
  "in": "2h"
}
out = parseDuration(in)
{
  "in": "2h",
  "out": "2h0m0s"
}

strftime(datetime, pattern)

The strftime function returns the formatted DateTime based on the given pattern. Refer to Date and time formatting for more details.

Table 61. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z"
}
out = strftime(in, "%Y-%m-%d")
{
  "in": "2020-01-01T00:00:00Z",
  "out": "2020-01-01"
}

isLeapYear(datetime)

The isLeapYear function returns true if the given DateTime is a leap year.

Table 62. Examples:
State Expression Result
{
  "in": "2020-01-01T00:00:00Z"
}
out = isLeapYear(in)
{
  "in": "2020-01-01T00:00:00Z",
  "out": true
}
{
  "in": "2019-01-01T00:00:00Z"
}
out = isLeapYear(in)
{
  "in": "2019-01-01T00:00:00Z",
  "out": false
}

now

The now function returns the current DateTime

Table 63. Examples:
State Expression Result
{
}
out = now()
{
  "out": "2022-02-24T18:00:00Z"
}

isWeekDay

|isWeekDay |isWeekDay(datetime)|The function returns true if the specified day is week day.|isWeekDay(datefield) results in true

The isWeekDay function returns true if the given DateTime is a week day.

Table 64. Examples:
State Expression Result
{
  "in": "2022-02-24T00:00:00Z"
}
out = isWeekDay(in)
{
  "in": "2022-02-24T00:00:00Z",
  "out": true
}
{
  "in": "2022-02-26T00:00:00Z"
}
out = isWeekDay(in)
{
  "in": "2022-02-26T00:00:00Z",
  "out": false
}

sub(from, to)

The sub function returns the difference between two DateTime in milliseconds.

The from must be larger then to; if not, the function will error out.

Table 65. Examples:
State Expression Result
{
  "from": "2022-02-02T00:00:00Z",
  "to": "2022-02-01T00:00:00Z"
}
out = sub(from, to)
{
  "from": "2022-02-02T00:00:00Z",
  "to": "2022-02-01T00:00:00Z"
  "out": 86400000
}

KV functions

The resulting type of the KV function is based on the first argument. You may not provide multiple different KV types (KV, KVV, Vars) into the same function.

To examplify; merge(KV, KVV, Vars) is not allowed.

set(kv, k, v)

The set function assigns a value to the given KV-like variable.

The original value remains unchanged.

Table 66. Examples:
State Expression Result
{
  "in": {}
}
out = set(in, "foo", "bar")
{
  "in": {},
  "out": {"foo": "bar"}
}

merge(kv, …​kv)

|merge |merge(KV, arg1, …​argN)|The function combines all of the given KV types into a single KV type.|merge(&KVV{"foo": ["foo"]}, &KVV{"bar": ["bar"]}) results in &KVV{"foo": ["foo"], "bar": ["bar"]}, Same for KV and Vars.

The merge function merges all of the KV-like variables into a single KV.

The original value remains unchanged.

Table 67. Examples:
State Expression Result
{
  "a": {"foo": "foo"},
  "b": {"bar": "baz"}
}
out = merge(a, b)
{
  "a": {"foo": "foo"},
  "b": {"bar": "baz"}
  "out": {"foo": "foo", "bar": "baz"}
}

filter(kv, …​include)

The filter function returns a new KV including only the specified keys.

The original value remains unchanged.

Table 68. Examples:
State Expression Result
{
  "in": {"foo": "foo", "bar": "bar"}
}
out = filter(in, "foo")
{
  "in": {"foo": "foo", "bar": "bar"},
  "out": {"foo": "foo"}
}

omit(kv, …​exclude)

The omit function returns a new KV without the specified keys.

The original value remains unchanged.

Table 69. Examples:
State Expression Result
{
  "in": {"foo": "foo", "bar": "bar"}
}
out = filter(in, "foo")
{
  "in": {"foo": "foo", "bar": "bar"},
  "out": {"bar": "bar"}
}