Collections
Kestrel ships four built-in collection types: ordered (Array), keyed (Dictionary), unordered-unique (Set), and fixed-size heterogeneous (Tuple). Arrays, dictionaries, and sets all work with the iterator chain (map, filter, fold, etc.); tuples are a fixed-size grouping rather than a sequence.
Quick reference
let xs: [Int] = [1, 2, 3]; // Array
let ages: Dictionary[String, Int] = ["alice": 30]; // Dictionary
let tags: Set[String] = ["urgent", "pending"]; // Set
let pair: (Int, String) = (42, "answer"); // Tuple
The literal syntaxes use [...] for arrays, [k: v, ...] for dicts, and (...) for tuples. Sets use a constructor or a literal-with-context pattern (the type annotation distinguishes from Array).
Iteration
Every collection type works with for:
for x in xs { println("\(x)"); }
for (key, value) in ages { println("\(key) is \(value)"); }
And with the iterator chain:
<!-- sample: continue -->let evens = xs.filter(where: { it % 2 == 0 });
let sum = xs.iter().fold(from: 0, by: { (acc, n) in acc + n });
For the deeper iterator story — laziness, custom iterators, the Iterator protocol — see Iterators.
Subpages
- Arrays — ordered, indexable collections
- Dictionaries — key-value lookup
- Sets — unordered collections of unique values
- Tuples — fixed-size heterogeneous values
- Iterators —
for,map/filter/fold, custom iterators