Collections

Aside from its sequential data types, Ki provides a small number of collections.

Hash Table

Ki's associative array is called table, and is implemented as a hash table.

fn main() {
    var names_to_players1: table(
        key_type: <*str>
        value_type: <*Player!>
        alloc: 5
        values: [
            *"Player 1": *Player("Player 1", 10)!
            *"Player 2": *Player("Player 2", 10)!
        ]
        ordered: false
    )

    var names_to_players2: table([
        "Player 1": Player("Player 1", 10)
        "Player 2": Player("Player 2", 10)
        ordered: true
    ])

}

Set

Ki also provides a set collection. Its implementation is similar to that of table, but the interface provides methods for working with sets.

fn main() {
    val basket1: set(["apple", "banana", "cherry"])
    val basket2: set(["blueberry", "blackberry", "banana"])

    val common: basket1.intersection_of(basket_2)

    for fruit in common {
        echo("${fruit} is in both baskets")
    }
}

A set may be also be ordered.