You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Astra standard library provides core types, built-in functions, and utility modules. Built-in types and functions are always available without imports. Standard library modules can be imported with import std.<module>.
Built-in Types
These types are built into the language and always available:
Type
Description
Literal Syntax
Int
64-bit signed integer
0, 42, -7
Float
64-bit floating point
3.14, 0.0, -1.5
Bool
Boolean
true, false
Text
UTF-8 string
"hello", "", "line\n"
Unit
Empty type (no value)
() (implicit)
Option[T]
Optional value
Some(value), None
Result[T, E]
Success or error
Ok(value), Err(error)
List[T]
Ordered collection
[1, 2, 3], []
Tuple
Fixed-size heterogeneous collection
(1, "hello", true)
Map[K, V]
Key-value collection
Map.new(), Map.from([(k, v)])
Set[T]
Unique value collection
Set.new(), Set.from([1, 2, 3])
Built-in Functions
These functions are always available without imports.
I/O
Function
Signature
Description
print(values...)
(...) -> Unit
Print values to stdout without newline (requires Console)
println(values...)
(...) -> Unit
Print values to stdout with newline (requires Console)
Assertions (test-only)
Function
Signature
Description
assert(cond)
(Bool) -> Unit
Assert condition is true
assert(cond, msg)
(Bool, Text) -> Unit
Assert with custom error message
assert_eq(a, b)
(T, T) -> Unit
Assert two values are equal
Collections
Function
Signature
Description
len(value)
(Text | List | Tuple | Map | Set) -> Int
Returns length/size
range(start, end)
(Int, Int) -> List[Int]
Creates list of integers from start (inclusive) to end (exclusive)
Type Conversion
Function
Signature
Description
to_text(value)
(T) -> Text
Convert any value to its text representation
to_int(value)
(Float | Text | Bool) -> Int or Option[Int]
Convert to Int (Text returns Option)
to_float(value)
(Int | Text) -> Float or Option[Float]
Convert to Float (Text returns Option)
Math
Function
Signature
Description
abs(x)
(Int | Float) -> Int | Float
Absolute value
min(a, b)
(Int, Int) -> Int or (Float, Float) -> Float
Minimum of two values
max(a, b)
(Int, Int) -> Int or (Float, Float) -> Float
Maximum of two values
pow(base, exp)
(Int | Float, Int | Float) -> Int | Float
Raise base to power
sqrt(x)
(Float | Int) -> Float
Square root
floor(x)
(Float) -> Float
Round down to nearest integer
ceil(x)
(Float) -> Float
Round up to nearest integer
round(x)
(Float) -> Float
Round to nearest integer
Option/Result Constructors
Function
Signature
Description
Some(value)
(T) -> Option[T]
Wrap value in Some
None
Option[T]
Empty option value
Ok(value)
(T) -> Result[T, E]
Wrap value in Ok
Err(error)
(E) -> Result[T, E]
Wrap error in Err
Effect Convenience Wrappers
These provide direct access to common effect operations. They require the corresponding effect to be declared.
Function
Signature
Effect
Description
read_file(path)
(Text) -> Result[Text, Text]
Fs
Read file contents
write_file(path, content)
(Text, Text) -> Result[Unit, Text]
Fs
Write file contents
http_get(url)
(Text) -> Result[Text, Text]
Net
HTTP GET request
http_post(url, body)
(Text, Text) -> Result[Text, Text]
Net
HTTP POST request
random_int(min, max)
(Int, Int) -> Int
Rand
Random integer in [min, max)
random_bool()
() -> Bool
Rand
Random boolean
current_time_millis()
() -> Int
Clock
Current time in milliseconds
get_env(name)
(Text) -> Option[Text]
Env
Get environment variable
Built-in Methods by Type
Text Methods
Method
Signature
Description
.len()
() -> Int
Length in characters
.to_upper()
() -> Text
Uppercase version
.to_lower()
() -> Text
Lowercase version
.trim()
() -> Text
Remove leading/trailing whitespace
.contains(needle)
(Text) -> Bool
Check if contains substring
.starts_with(prefix)
(Text) -> Bool
Check if starts with prefix
.ends_with(suffix)
(Text) -> Bool
Check if ends with suffix
.split(delimiter)
(Text) -> List[Text]
Split by delimiter
.replace(from, to)
(Text, Text) -> Text
Replace all occurrences
.chars()
() -> List[Text]
List of individual characters
.repeat(n)
(Int) -> Text
Repeat string n times
.index_of(needle)
(Text) -> Option[Int]
Position of first occurrence, or None
.substring(start, end)
(Int, Int) -> Text
Substring from start (inclusive) to end (exclusive)