Skip to content

Standard Library Overview

The Almide standard library covers data types, I/O, networking, numerics and more. Modules are either auto-imported (usable with no import statement at all) or require an explicit import.

The split is not stylistic: everything that can touch the outside world — files, the network, the clock as a source of entropy, the process environment — is import-required, so a file’s imports are an honest summary of what it can reach.

Available in every file with no import statement. Writing import string is redundant.

ModuleDescription
stringString manipulation: trim, split, join, replace, search
listList operations: map, filter, fold, sort, search
mapMap (dictionary) operations: get, set, merge, iterate
setSet operations: union, intersection, difference
intInteger conversion, parsing, bitwise operations
floatFloat conversion, rounding, math utilities
mathMathematical functions: trig, logarithms, constants
optionOption[T] utilities: map, flat_map, unwrap_or
resultResult[T, E] utilities: map, flat_map, unwrap_or
valueGeneric dynamic value type shared with JSON
errorError construction and chaining
datetimeDate/time: parse, format, arithmetic
bytesBinary data: read/write, slice, encode, decode
matrixMatrix operations: create, multiply, transpose
sized numeric typesint8int32, uint8uint64, float32

These need import <module>:

ModuleDescriptionEffect
fsFile system: read, write, list directoriesYes
ioConsole I/O: read_line, print (no newline), read_allYes
envEnvironment: args, env vars, timestamps, sleepYes
processProcess execution, env vars, spawn/kill, signalsYes
pathPath manipulation: join, dirname, basename, extensionNo
argsCommand-line flag and option parsingNo
ModuleDescriptionEffect
jsonJSON parsing, building, path-based accessNo
regexRegular expressions: match, find, replace, splitNo
base64Base64 encoding and decodingNo
hexHexadecimal encoding and decodingNo
ModuleDescriptionEffect
httpHTTP client and serverYes
ModuleDescriptionEffect
testingTest assertions: assert_eq, assert_approx, assert_throwsNo
randomRandom number generationYes

Each built-in data type has a corresponding module for operations:

string.len("hello") // => 5
list.map([1, 2, 3], (x) => x * 2) // => [2, 4, 6]
map.get(m, "key") // => Option[V]
int.to_string(42) // => "42"
float.round(3.7) // => 4.0
option.unwrap_or(some(42), 0) // => 42
result.map(ok(1), (x) => x + 1) // => ok(2)
set.union(a, b) // set union

Most I/O is effect fn returning Result, but not all of it — fs.exists and its siblings are effectful yet return Bool, and fs.temp_dir, env.os, process.args and several io writers are pure. Check the per-module page before assuming:

import fs
effect fn read_config() -> Result[String, String] = {
let text = fs.read_text("config.toml")!
ok(text)
}

Many modules share a consistent vocabulary for higher-order operations:

FunctionAvailable on
maplist, map, set, option, result
filterlist, map, set, option
foldlist, map, set
eachlist, map, set
any / alllist, map, set
findlist, map
containslist, map, set
lenlist, map, set, string
is_emptylist, map, set, string

All stdlib functions can be called in either prefix or method style:

// These are equivalent:
string.len("hello")
"hello".len()
// Chaining with method syntax:
text.trim().split(",").map((s: String) => s.to_upper())
// Chaining with pipe:
text |> string.trim |> string.split(",")
  • One name per operation: len not length/size/count
  • is_ prefix: Boolean-returning functions (is_empty, is_digit)
  • to_ prefix: Type conversion (to_string, to_int)
  • from_ prefix: Construction from another type (from_list, from_bytes)
  • One canonical name: the name listed here is the one to use (a few aliases exist for historical reasons, e.g. string.length)