Built-in Functions
Risor provides a set of built-in functions that are available in every script without importing any modules. These functions cover type conversions, container operations, encoding/decoding, and general-purpose utilities.
Type Conversions
Functions for converting values between Risor types.
| Function | Description |
|---|---|
int(value?) | Convert to 64-bit integer |
float(value?) | Convert to 64-bit float |
string(value?) | Convert to string |
bool(value?) | Convert to boolean |
byte(value?) | Convert to byte (0--255) |
bytes(value?) | Convert to byte sequence |
list(enumerable?) | Convert an enumerable to a list |
Container Operations
Functions for inspecting and transforming containers such as lists, maps, strings, and byte sequences.
| Function | Description |
|---|---|
len(container) | Length of a string, list, map, or bytes |
keys(container) | Keys from a map or indices from a list |
sorted(items, key?) | Sorted copy with optional comparator |
reversed(sequence) | Reversed copy of a list or string |
filter(items, fn) | Keep elements where fn returns true |
chunk(list, size) | Split a list into chunks of a given size |
range(...) | Lazy integer sequence |
Encoding and Decoding
Functions for serializing and deserializing data in common formats.
| Function | Description |
|---|---|
encode(value, format) | Encode a value to a format |
decode(data, format) | Decode data from a format |
Supported formats: json, base64, base32, hex, csv, urlquery.
Utility
General-purpose functions for inspection, formatting, control flow, and error handling.
| Function | Description |
|---|---|
type(value) | Type name as a string |
sprintf(format, args...) | Format a string (Go fmt.Sprintf syntax) |
error(message, args...) | Create an error value (does not throw) |
assert(condition, message?) | Raise an error if condition is false |
getattr(obj, name, default?) | Safe attribute access |
call(fn, args...) | Call a function dynamically |
any(items) | True if any element is truthy |
all(items) | True if all elements are truthy |
coalesce(values...) | First non-nil argument |