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, or returns the length of an interval. Throws on invalid input.
Duration('P1D')→ P1DDuration(Interval({start: D2024-01-01T10:00:00Z, end: D2024-01-01T12:00:00Z}))→ PT2HConstructs an interval from an object with start and end datetime properties. Use start() and end() to access boundaries.
start(Interval({start: D2024-01-15T10:00:00Z, end: D2024-01-15T18:00:00Z}))→ D2024-01-15T10:00:00ZParses 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)→ 30Returns the start of the given period.
D2024-06-15T10:30:00Z |> startOfMonth→ D2024-06-01T00:00:00ZReturns the end of the given period.
D2024-06-15T10:30:00Z |> endOfYear→ D2024-12-31T23:59:59ZDuration
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→ P5DConverts a duration to its approximate total number of years (1y = 365.25d).
P365D |> inYears |> round→ 1Converts a duration to its approximate total number of quarters (1q = 91.3125d).
P90D |> inQuarters |> round→ 1Converts a duration to its approximate total number of months (1m = 30.4375d).
P365D |> inMonths |> round→ 12Converts a duration to its total number of weeks.
P14D |> inWeeks→ 2.0Converts a duration to its total number of days.
P7D |> inDays→ 7.0Converts a duration to its total number of hours.
P1D |> inHours→ 24.0Converts a duration to its total number of minutes.
PT1H |> inMinutes→ 60.0Converts a duration to its total number of seconds.
P1D |> inSeconds→ 86400.0Interval
Functions for working with time intervals (ranges of datetimes).
Returns the start datetime of the interval.
start(Interval({start: D2024-01-15T10:00:00Z, end: D2024-01-15T18:00:00Z}))→ D2024-01-15T10:00:00ZReturns the end datetime of the interval.
end(Interval({start: D2024-01-15T10:00:00Z, end: D2024-01-15T18:00:00Z}))→ D2024-01-15T18:00:00ZReturns the bounding interval (min start, max end) of two intervals.
end(union(Interval({start: D2024-01-01T10:00:00Z, end: D2024-01-01T12:00:00Z}), Interval({start: D2024-01-01T11:00:00Z, end: D2024-01-01T14:00:00Z})))→ D2024-01-01T14:00:00ZReturns the overlapping portion of two intervals. If no overlap, returns an empty interval (start == end).
start(intersection(Interval({start: D2024-01-01T10:00:00Z, end: D2024-01-01T14:00:00Z}), Interval({start: D2024-01-01T12:00:00Z, end: D2024-01-01T16:00:00Z})))→ D2024-01-01T12:00:00ZList
Operators and functions for working with lists.
Arithmetic
I need to combine lists.
Concatenates two lists.
[1, 2] + [3, 4]→ [1, 2, 3, 4]Element Access
I need to get a specific element.
Returns the element at the given index (0-based).
at([1, 2, 3], 1)→ 2Returns the first element of the list.
first([1, 2, 3])→ 1Returns the last element of the list.
last([1, 2, 3])→ 3Returns the first element that satisfies predicate. Returns null if none found. JS/Ruby only.
find([1, 2, 3], fn(x ~> x > 1))→ 2Predicates
I need to check something about a list.
Returns true if the list contains the given element.
contains([1, 2, 3], 2)→ trueReturns true if the list is empty.
isEmpty([])→ trueReturns true if any element satisfies predicate. JS/Ruby only.
any([1, 2, 3], fn(x ~> x > 2))→ trueReturns true if all elements satisfy predicate. JS/Ruby only.
all([1, 2, 3], fn(x ~> x > 0))→ trueTransform
I need to reshape my list.
Returns a new list with fn applied to each element. JS/Ruby only.
map([1, 2, 3], fn(x ~> x * 2))→ [2, 4, 6]Returns elements where predicate returns true. JS/Ruby only.
filter([1, 2, 3, 4], fn(x ~> x > 2))→ [3, 4]Returns a new list with elements in reverse order.
reverse([1, 2, 3])→ [3, 2, 1]Returns a new list with duplicate elements removed, preserving order.
unique([1, 2, 3, 2, 1])→ [1, 2, 3]Flattens a list of lists by one level.
flat([[1, 2], [3, 4]])→ [1, 2, 3, 4]Returns a new list with elements sorted in ascending order.
sort([3, 1, 4, 1, 5])→ [1, 1, 3, 4, 5]Returns a new list sorted by the value of the given function or path. JS/Ruby only.
sortBy(['banana', 'apple', 'cherry'], fn(x ~> length(x)))→ ['apple', 'banana', 'cherry']Summary
I need a single aggregate value from a list.
Joins list elements into a string using the separator.
join(['a', 'b', 'c'], ',')→ 'a,b,c'Returns the number of elements in the list.
length([1, 2, 3])→ 3Returns the number of elements in the list. Alias for length.
count([1, 2, 3])→ 3Returns the sum of all elements in the list. Returns 0 for an empty list.
sum([1, 2, 3])→ 6Reduces the list using + with an initial value. Works with strings too.
sum(['a', 'b'], '')→ "ab"Returns the arithmetic mean of all elements. Returns null for an empty list.
avg([1, 2, 3])→ 2.0Returns the smallest element of the list.
min([3, 1, 4, 1, 5])→ 1Returns the largest element of the list.
max([3, 1, 4, 1, 5])→ 5Reduces the list to a single value. JS/Ruby only.
reduce([1, 2, 3], 0, fn(acc, x ~> acc + x))→ 6Numeric
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.
Arithmetic
I need to combine strings.
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'Transform
I need to change a string.
Converts all characters to lowercase.
lower('HELLO')→ 'hello'Converts all characters to uppercase.
upper('hello')→ 'HELLO'Removes leading and trailing whitespace.
trim(' hi ')→ 'hi'Removes leading whitespace.
trimStart(' hi ')→ 'hi 'Removes trailing whitespace.
trimEnd(' hi ')→ ' hi'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'Pads the start of the string to reach the target length.
padStart('42', 5, '0')→ '00042'Pads the end of the string to reach the target length.
padEnd('hi', 5, '.')→ 'hi...'Extracts a substring starting at start (0-indexed) with length len.
substring('hello', 1, 3)→ 'ell'Splits the string into a list using the separator.
split('a,b,c', ',')→ ['a', 'b', 'c']Reverses the string.
reverse('hello')→ 'olleh'Predicates
I need to check something about a string.
Returns true if the string is empty.
isEmpty('')→ trueReturns true if the string starts with the given prefix.
startsWith('hello', 'he')→ trueReturns true if the string ends with the given suffix.
endsWith('hello', 'lo')→ trueReturns true if the string is empty or contains only whitespace.
isBlank(' ')→ trueSearch
I need to find something in a string.
Returns true if the string contains the given substring.
contains('hello', 'ell')→ trueReturns the index of the first occurrence, or null if not found.
indexOf('hello', 'l')→ 2Summary
I need a single value from a string.
Returns the number of characters in the string.
length('hello')→ 5Tuple (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.
fetch({user: {name: 'Bob'}}, .user.name)→ 'Bob'fetch({a: 1, b: 2}, {x: .a, y: .b})→ {x: 1, y: 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'}}