API Reference

Every module and function in the standard library. Language modules ship with the core prelude; server modules require @prelude(server).

Language Modules

Core

List

List operations.

FunctionSignatureDescription
lengthfn length(List<T>) -> IntNumber of elements
headfn head(List<T>) -> Option<T>First element
tailfn tail(List<T>) -> List<T>All except first
getfn get(List<T>, Int) -> Option<T>Element at index
get_orfn get_or(List<T>, Int, T) -> TElement at index with default
setfn set(List<T>, Int, T) -> List<T>Replace element at index
slicefn slice(List<T>, Int, Int) -> List<T>Sub-list (start, end exclusive)
fillfn fill(Int, T) -> List<T>Create list filled with value
reversefn reverse(List<T>) -> List<T>Reverse order
sortfn sort(List<T>) -> List<T>Sort ascending
concatfn concat(List<T>, List<T>) -> List<T>Concatenate two lists
containsfn contains(List<T>, T) -> BoolCheck membership
mapfn map(List<T>, (T) -> U) -> List<U>Apply function to each
filterfn filter(List<T>, (T) -> Bool) -> List<T>Keep matching elements
foldfn fold(List<T>, U, (U, T) -> U) -> UReduce to single value
findfn find(List<T>, (T) -> Bool) -> Option<T>First matching element

String

String operations.

FunctionSignatureDescription
lengthfn length(String) -> IntCharacter count
containsfn contains(String, String) -> BoolHas substring?
starts_withfn starts_with(String, String) -> BoolStarts with prefix?
ends_withfn ends_with(String, String) -> BoolEnds with suffix?
to_upperfn to_upper(String) -> StringUppercase
to_lowerfn to_lower(String) -> StringLowercase
trimfn trim(String) -> StringStrip whitespace
reversefn reverse(String) -> StringReverse
splitfn split(String, String) -> List<String>Split by delimiter
joinfn join(List<String>, String) -> StringJoin with separator
slicefn slice(String, Int, Int) -> StringSubstring (start, length)
replacefn replace(String, String, String) -> StringReplace all occurrences
replace_regexfn replace_regex(String, String, String) -> StringRegex replace
matchesfn matches(String, String) -> BoolRegex test
find_matchesfn find_matches(String, String) -> List<String>All regex matches
charsfn chars(String) -> List<String>Split into characters
char_atfn char_at(String, Int) -> Option<String>Character at index
index_offn index_of(String, String) -> IntFirst occurrence index (-1 if none)
to_intfn to_int(String) -> IntParse as integer
from_char_codefn from_char_code(Int) -> StringString from Unicode code point
char_codefn char_code(String) -> IntUnicode code point of first char

Int

Integer operations.

FunctionSignatureDescription
to_stringfn to_string(Int) -> StringConvert to string
parsefn parse(String) -> IntParse string as int
from_floatfn from_float(Float) -> IntTruncate float to int

Float

Floating-point operations.

FunctionSignatureDescription
from_intfn from_int(Int) -> FloatConvert int to float
formatfn format(Float, Int) -> StringFormat with decimal places

Map

Persistent key-value maps.

FunctionSignatureDescription
emptyfn empty() -> Map<K, V>Create empty map
insertfn insert(Map<K, V>, K, V) -> Map<K, V>Insert key-value pair
setfn set(Map<K, V>, K, V) -> Map<K, V>Alias for insert
getfn get(Map<K, V>, K) -> Option<V>Look up key
removefn remove(Map<K, V>, K) -> Map<K, V>Remove key
containsfn contains(Map<K, V>, K) -> BoolCheck if key exists
hasfn has(Map<K, V>, K) -> BoolAlias for contains
keysfn keys(Map<K, V>) -> List<K>All keys
valuesfn values(Map<K, V>) -> List<V>All values
entriesfn entries(Map<K, V>) -> List<(K, V)>All key-value pairs
lenfn len(Map<K, V>) -> IntNumber of entries
sizefn size(Map<K, V>) -> IntAlias for len
from_listfn from_list(List<(K, V)>) -> Map<K, V>Create from pairs

Set

Persistent sets.

FunctionSignatureDescription
emptyfn empty() -> Set<T>Create empty set
insertfn insert(Set<T>, T) -> Set<T>Add element
removefn remove(Set<T>, T) -> Set<T>Remove element
containsfn contains(Set<T>, T) -> BoolCheck membership
unionfn union(Set<T>, Set<T>) -> Set<T>Set union
intersectionfn intersection(Set<T>, Set<T>) -> Set<T>Set intersection
lenfn len(Set<T>) -> IntNumber of elements
from_listfn from_list(List<T>) -> Set<T>Create from list

IO

Console

Terminal I/O.

FunctionSignatureDescription
println!fn println!(String) -> UnitPrint with newline
print!fn print!(String) -> UnitPrint without newline
error!fn error!(String) -> UnitPrint to stderr
read_line!fn read_line!() -> StringRead line from stdin

Fs

Filesystem operations.

FunctionSignatureDescription
read!fn read!(String) -> StringRead file contents
write!fn write!(String, String) -> UnitWrite string to file
exists!fn exists!(String) -> BoolCheck if path exists
read_file!fn read_file!(String) -> StringAlias for read!
write_file!fn write_file!(String, String) -> UnitAlias for write!
list_dir!fn list_dir!(String) -> List<String>List directory entries

Env

Environment variables.

FunctionSignatureDescription
get!fn get!(String) -> Option<String>Read env var
set!fn set!(String, String) -> UnitSet env var
args!fn args!() -> List<String>Command-line arguments

Async

Async

Run concurrent tasks with parallel execution, racing, timeouts, and delays.

FunctionSignatureDescription
parallel!fn parallel!(List<() -> T>) -> List<T>Run thunks concurrently, collect all results
race!fn race!(List<() -> T>) -> TRun thunks concurrently, return first result
scatter_gather!fn scatter_gather!(List<() -> T>, (List<T>) -> U) -> URun thunks concurrently, apply gather function
delay!fn delay!(Int, () -> T) -> TWait milliseconds, then execute thunk
interval!fn interval!(Int, () -> Unit) -> UnitRepeatedly execute thunk at interval
timeout!fn timeout!(Int, () -> T) -> Result<T, String>Run thunk with timeout, Err on expiry

Channel

Send and receive messages between concurrent tasks.

FunctionSignatureDescription
boundedfn bounded(Int) -> (Sender<T>, Receiver<T>)Create bounded channel with capacity
send!fn send!(Sender<T>, T) -> UnitSend value into channel
recv!fn recv!(Receiver<T>) -> Option<T>Receive value, None if closed
close!fn close!(Sender<T>) -> UnitClose channel

Scope

Structured concurrency.

FunctionSignatureDescription
spawn!fn spawn!(Scope, () -> T) -> Cell<T>Spawn task in scope

Data

Json

JSON serialization.

FunctionSignatureDescription
parsefn parse(String) -> TParse JSON string
to_stringfn to_string(T) -> StringSerialize to compact JSON
to_string_prettyfn to_string_pretty(T) -> StringSerialize to pretty JSON
to_camel_casefn to_camel_case(T) -> TConvert keys to camelCase
to_snake_casefn to_snake_case(T) -> TConvert keys to snake_case

Crypto

Cryptographic utilities.

FunctionSignatureDescription
sha256fn sha256(String) -> StringSHA-256 hash
hmac_sha256fn hmac_sha256(String, String) -> StringHMAC-SHA256 signature
constant_time_eqfn constant_time_eq(String, String) -> BoolConstant-time string comparison

DateTime

Date and time operations.

FunctionSignatureDescription
now!fn now!() -> IntCurrent Unix timestamp
parsefn parse(String) -> Result<Int, String>Parse date string to timestamp
to_stringfn to_string(Int) -> StringFormat timestamp as ISO 8601
addfn add(Int, Int) -> IntAdd seconds to timestamp
difffn diff(Int, Int) -> IntDifference in seconds

Math

Mathematical functions.

FunctionSignatureDescription
absfn abs(Int) -> IntAbsolute value
minfn min(Int, Int) -> IntSmaller of two
maxfn max(Int, Int) -> IntLarger of two
clampfn clamp(Int, Int, Int) -> IntConstrain between min and max
powfn pow(Int, Int) -> IntExponentiation
sqrtfn sqrt(Float) -> FloatSquare root
sinfn sin(Float) -> FloatSine
cosfn cos(Float) -> FloatCosine
atan2fn atan2(Float, Float) -> FloatTwo-argument arctangent
floorfn floor(Float) -> FloatRound down
ceilfn ceil(Float) -> FloatRound up

Error Handling

Option

Optional values.

FunctionSignatureDescription
unwrapfn unwrap(Option<T>) -> TExtract value or panic
unwrap_orfn unwrap_or(Option<T>, T) -> TExtract value or default
is_somefn is_some(Option<T>) -> BoolHas value?
is_nonefn is_none(Option<T>) -> BoolIs None?
ok_orfn ok_or(Option<T>, E) -> Result<T, E>Convert to Result
mapfn map(Option<T>, (T) -> U) -> Option<U>Transform value
flat_mapfn flat_map(Option<T>, (T) -> Option<U>) -> Option<U>Chain optional operations

Result

Error handling.

FunctionSignatureDescription
unwrapfn unwrap(Result<T, E>) -> TExtract Ok or panic
unwrap_orfn unwrap_or(Result<T, E>, T) -> TExtract Ok or default
is_okfn is_ok(Result<T, E>) -> BoolIs Ok?
is_errfn is_err(Result<T, E>) -> BoolIs Err?
ensurefn ensure(Bool, E) -> Result<Unit, E>Assert condition
mapfn map(Result<T, E>, (T) -> U) -> Result<U, E>Transform Ok value
and_thenfn and_then(Result<T, E>, (T) -> Result<U, E>) -> Result<U, E>Chain Result operations
map_errfn map_err(Result<T, E>, (E) -> F) -> Result<T, F>Transform Err value
contextfn context(Result<T, E>, String) -> Result<T, {context: String, error: E}>Add error context

Other

Log

Structured logging (ambient effect).

FunctionSignatureDescription
info!fn info!(String) -> UnitLog at info level
warn!fn warn!(String) -> UnitLog at warning level
error!fn error!(String) -> UnitLog at error level
debug!fn debug!(String) -> UnitLog at debug level

Time

Clock operations (ambient effect).

FunctionSignatureDescription
now!fn now!() -> IntCurrent Unix timestamp in milliseconds
sleep!fn sleep!(Int) -> UnitPause for milliseconds

Random

Random number generation.

FunctionSignatureDescription
int!fn int!(Int, Int) -> IntRandom int in range (inclusive)
bool!fn bool!() -> BoolRandom boolean
uuid!fn uuid!() -> StringRandom UUID v4
bytes!fn bytes!(Int) -> StringRandom bytes as hex (max 1024)

Weak

Weak references.

FunctionSignatureDescription
downgradefn downgrade(T) -> Weak<T>Create weak reference
upgradefn upgrade(Weak<T>) -> Option<T>Try to upgrade to strong reference

Server Modules

Web

Router

HTTP routing.

FunctionSignatureDescription
newfn new() -> RouterCreate empty router
getfn get(Router, String, Handler) -> RouterGET route
postfn post(Router, String, Handler) -> RouterPOST route
putfn put(Router, String, Handler) -> RouterPUT route
deletefn delete(Router, String, Handler) -> RouterDELETE route
patchfn patch(Router, String, Handler) -> RouterPATCH route
optionsfn options(Router, String, Handler) -> RouterOPTIONS route
headfn head(Router, String, Handler) -> RouterHEAD route
anyfn any(Router, String, Handler) -> RouterAll methods
usefn use(Router, Middleware) -> RouterAdd middleware
groupfn group(Router, String, Router) -> RouterGroup under prefix
resourcesfn resources(Router, String, Record) -> RouterRESTful resource routes
statefn state(Router, String, T) -> RouterAttach shared state
docs_jsonfn docs_json(Router) -> StringGenerate OpenAPI spec
wsfn ws(Router, String, Handler) -> RouterWebSocket handler
routesfn routes(Router) -> List<Record>Route table

Server

HTTP server.

FunctionSignatureDescription
listen!fn listen!(Router, Int) -> UnitStart server on port

Request

HTTP request object.

FunctionSignatureDescription
headerfn header(Request, String) -> Option<String>Read header
methodfn method(Request) -> StringHTTP method
body_jsonfn body_json(Request) -> Result<T, HttpError>Parse body as JSON
paramfn param(Request, String) -> Result<String, String>Path parameter
param_intfn param_int(Request, String) -> Result<Int, String>Path parameter as int
queryfn query(Request, String) -> Option<String>Query parameter
query_intfn query_int(Request, String) -> Result<Int, String>Query parameter as int
decodefn decode(Request, String) -> Result<T, Response>Decode and validate body
multipartfn multipart(Request) -> List<Record>Parse multipart form data

Response

HTTP response construction.

FunctionSignatureDescription
okfn ok(String) -> Response200 with text
jsonfn json(T) -> Response200 with JSON
createdfn created(T) -> Response201
no_contentfn no_content() -> Response204
bad_requestfn bad_request(String) -> Response400
unauthorizedfn unauthorized(String) -> Response401
forbiddenfn forbidden(String) -> Response403
not_foundfn not_found(String) -> Response404
method_not_allowedfn method_not_allowed(String) -> Response405
conflictfn conflict(String) -> Response409
unprocessablefn unprocessable(String) -> Response422
too_many_requestsfn too_many_requests(String) -> Response429
errorfn error(String) -> Response500
bad_gatewayfn bad_gateway(String) -> Response502
service_unavailablefn service_unavailable(String) -> Response503
gateway_timeoutfn gateway_timeout(String) -> Response504
statusfn status(Int, String) -> ResponseCustom status
with_headerfn with_header(Response, String, String) -> ResponseAdd header
with_headersfn with_headers(Response, List<(String, String)>) -> ResponseAdd multiple headers
set_cookiefn set_cookie(Response, String, String) -> ResponseSet cookie
redirectfn redirect(String) -> Response302 redirect
redirect_permanentfn redirect_permanent(String) -> Response301 redirect
redirect_temporaryfn redirect_temporary(String) -> Response307 redirect

Http

HTTP client.

FunctionSignatureDescription
get!fn get!(String) -> ResponseGET request
post!fn post!(String, String) -> ResponsePOST request with body
put!fn put!(String, String) -> ResponsePUT request with body
delete!fn delete!(String) -> ResponseDELETE request
request!fn request!(RequestConfig) -> ResponseCustom request

Database

Sqlite

SQLite database.

FunctionSignatureDescription
connect!fn connect!(String) -> UnitOpen database file
execute!fn execute!(String, List<String>) -> IntExecute statement
query!fn query!(String, List<String>) -> List<Row>Run query
query_one!fn query_one!(String, List<String>) -> Option<Row>First row
query_as!fn query_as!(Decoder, String, List<String>) -> List<T>Query with decoder
query_one_as!fn query_one_as!(Decoder, String, List<String>) -> Option<T>First row with decoder
query_map!fn query_map!(String, List<String>) -> List<Row>Query for mapping

Postgres

PostgreSQL database.

FunctionSignatureDescription
connect!fn connect!(String) -> UnitOpen connection
execute!fn execute!(String, List<String>) -> IntExecute statement
query!fn query!(String, List<String>) -> List<Row>Run query
query_one!fn query_one!(String, List<String>) -> Option<Row>First row
query_as!fn query_as!(Decoder, String, List<String>) -> List<T>Query with decoder
query_one_as!fn query_one_as!(Decoder, String, List<String>) -> Option<T>First row with decoder
query_map!fn query_map!(String, List<String>) -> List<Row>Query for mapping

Mysql

MySQL database.

FunctionSignatureDescription
connect!fn connect!(String) -> UnitOpen connection
execute!fn execute!(String, List<String>) -> IntExecute statement
query!fn query!(String, List<String>) -> List<Row>Run query
query_one!fn query_one!(String, List<String>) -> Option<Row>First row
query_as!fn query_as!(Decoder, String, List<String>) -> List<T>Query with decoder
query_one_as!fn query_one_as!(Decoder, String, List<String>) -> Option<T>First row with decoder
query_map!fn query_map!(String, List<String>) -> List<Row>Query for mapping

Row

Database row access.

FunctionSignatureDescription
stringfn string(Row, String) -> StringString column
intfn int(Row, String) -> IntInt column
floatfn float(Row, String) -> FloatFloat column
boolfn bool(Row, String) -> BoolBool column
optional_stringfn optional_string(Row, String) -> Option<String>Nullable string
optional_intfn optional_int(Row, String) -> Option<Int>Nullable int
decodefn decode(Row, Decoder) -> TDecode row to record

Sql

Database migrations.

FunctionSignatureDescription
migrate!fn migrate!(String) -> Result<Int, String>Run migrations from directory

Auth

Jwt

JSON Web Tokens.

FunctionSignatureDescription
signfn sign(Record, String) -> StringSign claims as JWT (HS256)
sign_withfn sign_with(Record, String, { expires_in: Int }) -> StringSign with options
verifyfn verify(String, String) -> Result<Record, String>Verify and decode
decodefn decode(String) -> Result<Record, String>Decode without verifying

Session

Session management.

FunctionSignatureDescription
create!fn create!(Record) -> StringCreate session, return ID
get!fn get!(String) -> Option<Record>Get session data
set!fn set!(String, String, T) -> UnitUpdate session field
delete!fn delete!(String) -> UnitRemove session

Middleware

Request middleware utilities.

FunctionSignatureDescription
extract_bearerfn extract_bearer(Request) -> Result<String, HttpError>Extract Bearer token
extract_basicfn extract_basic(Request) -> Result<(String, String), HttpError>Extract Basic auth
cors_configfn cors_config(List<String>) -> RecordCORS configuration
rate_limit_configfn rate_limit_config(Int, Int) -> RecordRate limiting config

Validation

Validate

Request validation.

FunctionSignatureDescription
requiredfn required(T, String) -> Result<T, HttpError>Check not None
stringfn string(T, String) -> Result<String, HttpError>Validate string
intfn int(T, String) -> Result<Int, HttpError>Validate int
booleanfn boolean(T, String) -> Result<Bool, HttpError>Validate bool
min_lengthfn min_length(String, Int, String) -> Result<String, HttpError>Min string length
max_lengthfn max_length(String, Int, String) -> Result<String, HttpError>Max string length
minfn min(Int, Int, String) -> Result<Int, HttpError>Min number
maxfn max(Int, Int, String) -> Result<Int, HttpError>Max number
one_offn one_of(String, List<String>, String) -> Result<String, HttpError>Allowed values

HttpError

Typed HTTP errors.

FunctionSignatureDescription
bad_requestfn bad_request(String) -> HttpError400
unauthorizedfn unauthorized(String) -> HttpError401
forbiddenfn forbidden(String) -> HttpError403
not_foundfn not_found(String) -> HttpError404
method_not_allowedfn method_not_allowed(String) -> HttpError405
conflictfn conflict(String) -> HttpError409
unprocessablefn unprocessable(String) -> HttpError422
too_many_requestsfn too_many_requests(String) -> HttpError429
internalfn internal(String) -> HttpError500
bad_gatewayfn bad_gateway(String) -> HttpError502
service_unavailablefn service_unavailable(String) -> HttpError503
gateway_timeoutfn gateway_timeout(String) -> HttpError504
with_contextfn with_context(HttpError, String) -> HttpErrorAdd context
with_codefn with_code(HttpError, String) -> HttpErrorAdd error code
to_responsefn to_response(HttpError) -> ResponseConvert to Response

Realtime

Ws

WebSocket communication.

FunctionSignatureDescription
send!fn send!(String) -> UnitSend message
receive!fn receive!() -> Result<String, String>Receive message
close!fn close!() -> UnitClose connection