Collections
Arrays
Section titled “Arrays”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]Spread
Section titled “Spread”Combine arrays with ...:
let combined = [...items1, ...items2]Dictionaries
Section titled “Dictionaries”Key-value collections, typed:
let scores: Dictionary<string, int> = {"alice": 100, "bob": 95}scores["carol"] = 88let aliceScore = scores["alice"]Spread
Section titled “Spread”Merge dictionaries with ...:
let merged = {...dict1, ...dict2}Nested collections
Section titled “Nested collections”Generics compose freely:
let teams: Array<Dictionary<string, Player>>let nested: Dictionary<string, Dictionary<string, int>>Tuples
Section titled “Tuples”Rust-style, with destructuring:
let point = (10.0, 20.0)let (x, y) = pointTyped tuples
Section titled “Typed tuples”let point: (float, float) = (10.0, 20.0)let player = ("Hero", 100.0, true)let (name, health, isActive) = playerFunction returns
Section titled “Function returns”Tuples are useful for returning multiple values:
func getPosition() -> (float, float) { return (self.x, self.y)}
let (px, py) = player.getPosition()