Standard Library
Built-in functions available in Elo. Click any function to try it in the playground.
Type Selectors
Type selectors validate and parse strings to typed values. They throw an error on invalid input.
Type selectors can be combined into data schemas for validating complex data structures like let Person = { name: String, age: Int } in data |> Person. JS/Ruby only.
Parses a string to an integer. Throws on invalid input.
Int('123')→ 123Parses a string to a float. Throws on invalid input.
Float('3.14')→ 3.14Parses 'true' or 'false' strings to boolean. Throws on invalid input.
Bool('true')→ trueValidates that a value is null. Throws on non-null input.
let T = Int|Null in null |> T→ nullParses an ISO date string (YYYY-MM-DD) to a Date. Throws on invalid input.
Date('2025-01-15')→ D2025-01-15Parses an ISO datetime string to a DateTime. Throws on invalid input.
Datetime('2025-01-15T10:30:00')→ D2025-01-15T10:30:00Parses an ISO 8601 duration string. Throws on invalid input.
Duration('P1D')→ P1DParses a JSON string. Non-strings are returned as-is. Throws on invalid JSON.
Data('{"name": "Alice"}')→ {name: 'Alice'}Any
Functions that work on any type.
Returns the type name of the value.
typeOf(42)→ 'Int'Returns true if the value is null.
isNull(null)→ trueDate
Operators and functions for dates.
Adds a duration to a date.
D2024-01-15 + P7D→ D2024-01-22Subtracts a duration from a date.
D2024-01-15 - P7D→ D2024-01-08Returns the duration between two dates.
D2024-01-15 - D2024-01-01→ P14DExtracts the year from a date.
year(D2024-06-15)→ 2024Extracts the month (1-12) from a date.
month(D2024-06-15)→ 6Extracts the day of month (1-31).
day(D2024-06-15)→ 15DateTime
Operators and functions for datetimes. Date functions (year, month, day) also work on DateTime.
Adds a duration to a datetime.
D2024-01-15T10:00:00Z + PT2H→ D2024-01-15T12:00:00ZSubtracts a duration from a datetime.
D2024-01-15T10:00:00Z - PT2H→ D2024-01-15T08:00:00ZExtracts the hour (0-23) from a datetime.
hour(D2024-06-15T14:30:00Z)→ 14Extracts the minute (0-59) from a datetime.
minute(D2024-06-15T14:30:00Z)→ 30Duration
Operators and functions for ISO 8601 durations.
Adds two durations together.
P1D + PT12H→ P1DT12HScales a duration by a factor.
P1D * 2→ P2DDivides a duration by a factor.
P10D / 2→ P5DList
Operators and functions for working with lists.
Concatenates two lists.
[1, 2] + [3, 4]→ [1, 2, 3, 4]Returns true if all elements satisfy predicate. JS/Ruby only.
all([1, 2, 3], fn(x ~> x > 0))→ trueReturns true if any element satisfies predicate. JS/Ruby only.
any([1, 2, 3], fn(x ~> x > 2))→ trueReturns the element at the given index (0-based).
at([1, 2, 3], 1)→ 2Returns elements where predicate returns true. JS/Ruby only.
filter([1, 2, 3, 4], fn(x ~> x > 2))→ [3, 4]Returns the first element of the list.
first([1, 2, 3])→ 1Returns true if the list is empty.
isEmpty([])→ trueJoins list elements into a string using the separator.
join(['a', 'b', 'c'], ',')→ 'a,b,c'Returns the last element of the list.
last([1, 2, 3])→ 3Returns the number of elements in the list.
length([1, 2, 3])→ 3Returns a new list with fn applied to each element. JS/Ruby only.
map([1, 2, 3], fn(x ~> x * 2))→ [2, 4, 6]Reduces the list to a single value. JS/Ruby only.
reduce([1, 2, 3], 0, fn(acc, x ~> acc + x))→ 6Returns a new list with elements in reverse order.
reverse([1, 2, 3])→ [3, 2, 1]Numeric
Operators and functions for numeric operations (Int and Float).
Adds two numbers.
2 + 3→ 5Subtracts two numbers.
10 - 4→ 6Multiplies two numbers.
3 * 4→ 12Divides two numbers.
10 / 4→ 2.5Returns the remainder after division.
10 % 3→ 1Raises a number to a power.
2 ^ 10→ 1024Returns the absolute value of a number.
abs(-5)→ 5Rounds a number up to the nearest integer.
ceil(3.2)→ 4Rounds a number down to the nearest integer.
floor(3.9)→ 3Rounds a number to the nearest integer.
round(3.7)→ 4String
Operators and functions for string manipulation.
Concatenates two strings.
'hello' + ' world'→ 'hello world'Repeats a string n times.
'hi' * 3→ 'hihihi'Concatenates two strings. Same as +.
concat('hello', ' world')→ 'hello world'Returns true if the string contains the given substring.
contains('hello', 'ell')→ trueReturns true if the string ends with the given suffix.
endsWith('hello', 'lo')→ trueReturns the index of the first occurrence, or null if not found.
indexOf('hello', 'l')→ 2Returns true if the string is empty.
isEmpty('')→ trueReturns the number of characters in the string.
length('hello')→ 5Converts all characters to lowercase.
lower('HELLO')→ 'hello'Pads the end of the string to reach the target length.
padEnd('hi', 5, '.')→ 'hi...'Pads the start of the string to reach the target length.
padStart('42', 5, '0')→ '00042'Replaces the first occurrence of search with repl.
replace('abab', 'ab', 'x')→ 'xab'Replaces all occurrences of search with repl.
replaceAll('abab', 'ab', 'x')→ 'xx'Splits the string into a list using the separator.
split('a,b,c', ',')→ ['a', 'b', 'c']Returns true if the string starts with the given prefix.
startsWith('hello', 'he')→ trueExtracts a substring starting at start (0-indexed) with length len.
substring('hello', 1, 3)→ 'ell'Removes leading and trailing whitespace.
trim(' hi ')→ 'hi'Converts all characters to uppercase.
upper('hello')→ 'HELLO'Tuple (Data)
Functions for working with data structures (tuples and nested objects).
Recursively merges two objects. Nested objects are merged; other values from b override a.
deepMerge({x: {a: 1}}, {x: {b: 2}})→ {x: {a: 1, b: 2}}Navigates the data structure following the path. Returns null if any segment fails. Can fetch multiple paths into a tuple or list.
fetch({name: 'Alice'}, .name)→ 'Alice'fetch({a: 1, b: 2}, {x: .a, y: .b})→ {x: 1, y: 2}fetch({a: 1, b: 2}, [.a, .b])→ [1, 2]Shallow merges two objects. Properties from b override properties from a.
merge({a: 1}, {b: 2})→ {a: 1, b: 2}Returns a new tuple with the value patched at the given path. Creates intermediate structures as needed.
patch({}, .user.name, 'Bob')→ {user: {name: 'Bob'}}