Skip to content

Standard Library Overview

The Almide standard library provides 22 modules covering data types, I/O, networking, and more. Modules are either auto-imported (available without an import statement) or require explicit import.

These modules are available in every Almide file without an import statement:

ModuleDescription
stringString manipulation: trim, split, join, replace, search
listList operations: map, filter, fold, sort, search
mapMap (dictionary) operations: get, set, merge, iterate
intInteger conversion, parsing, bitwise operations
floatFloat conversion, rounding, math utilities
optionOption[T] utilities: map, flat_map, unwrap_or
resultResult[T, E] utilities: map, flat_map, unwrap_or
mathMathematical functions: trig, logarithms, constants
setSet operations: union, intersection, difference
valueGeneric value type for JSON and dynamic data

These modules must be explicitly imported with 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: exec, exit, stdinYes
ModuleDescriptionEffect
jsonJSON parsing, building, path-based accessNo
regexRegular expressions: match, find, replace, splitNo
datetimeDate/time: parse, format, arithmeticMixed
bytesBinary data: encode, decode, slice, hexNo
randomRandom number generationYes
ModuleDescriptionEffect
httpHTTP client and serverYes
ModuleDescriptionEffect
matrixMatrix operations: create, multiply, transposeNo
ModuleDescriptionEffect
logStructured loggingYes
testingTest utilitiesNo
errorError type utilitiesNo

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

All I/O functions are effect fn and return Result:

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) => 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)
  • No synonyms: The name listed in the docs is the only valid name