Skip to content

Collections

Ordered, typed collections indexed by integer:

let items: Array<string> = ["sword", "shield", "potion"]
let grid: Array<Array<int>>
items.push("dagger")
let first = items[0]

Combine arrays with ...:

let combined = [...items1, ...items2]

Key-value collections, typed:

let scores: Dictionary<string, int> = {"alice": 100, "bob": 95}
scores["carol"] = 88
let aliceScore = scores["alice"]

Merge dictionaries with ...:

let merged = {...dict1, ...dict2}

Generics compose freely:

let teams: Array<Dictionary<string, Player>>
let nested: Dictionary<string, Dictionary<string, int>>

Rust-style, with destructuring:

let point = (10.0, 20.0)
let (x, y) = point
let point: (float, float) = (10.0, 20.0)
let player = ("Hero", 100.0, true)
let (name, health, isActive) = player

Tuples are useful for returning multiple values:

func getPosition() -> (float, float) {
return (self.x, self.y)
}
let (px, py) = player.getPosition()