Skip to main content
Kira

Maps & Collections

Hash Maps (std.map)

For key-value storage with O(1) lookups:

fn count_words(words: List[string]) -> HashMap {
    var counts: HashMap = std.map.new()

    for word in words {
        let current: i32 = std.map.get(counts, word) ?? 0
        counts = std.map.put(counts, word, current + 1)
    }

    return counts
}

Operations

FunctionDescription
std.map.new()Create empty map
std.map.get(m, key)Get value by key (returns Option)
std.map.put(m, key, value)Insert or update a key-value pair
std.map.contains(m, key)Check if key exists

Time Operations (std.time)

effect fn timed_operation() -> void {
    let start: i64 = std.time.now()

    // Do some work...
    std.time.sleep(100)  // Sleep 100ms

    let elapsed: i64 = std.time.elapsed(start, std.time.now())
    std.io.println("Operation took " + to_string(elapsed) + "ms")
}

Math Operations (std.math)

Mathematical operations are available in std.math.

Assertions (std.assert)

std.assert.eq(actual, expected)     // Assert equality
std.assert.ne(actual, unexpected)   // Assert inequality
std.assert.true(condition)          // Assert condition is true