@@ -18,7 +18,7 @@ with no elements).
1818
1919## ` List<T> `
2020
21- ` List<T> ` is a growable, mutable, typed list — a ** built-in generic** , the same
21+ ` List<T> ` is a growable, mutable, typed list - a ** built-in generic** , the same
2222way ` T[] ` arrays are. There's nothing to import; the compiler specializes it per
2323element type and the runtime stores elements contiguously, so it's a thin,
2424allocation-light layer (no boxing).
@@ -79,14 +79,14 @@ loop, so chains are zero-overhead (no intermediate closures).
7979``` x
8080let nums = listOf(1, 2, 3, 4, 5)
8181
82- nums.map { it * 2 } // List<U> — transform (U is the body's type)
83- nums.filter { it % 2 == 0 } // List<T> — keep matching
84- nums.filterNot { it > 3 } // List<T> — drop matching
82+ nums.map { it * 2 } // List<U> - transform (U is the body's type)
83+ nums.filter { it % 2 == 0 } // List<T> - keep matching
84+ nums.filterNot { it > 3 } // List<T> - drop matching
8585nums.forEach { print(it) } // run a side effect per element
8686nums.fold(0) { acc, x => acc + x } // reduce with a seed
8787nums.reduce { a, b => a + b } // reduce, seed = first element
8888nums.sumOf { it } // sum of a projection (Integer/Number)
89- nums.count { it > 2 } // Integer — how many match
89+ nums.count { it > 2 } // Integer - how many match
9090nums.any { it > 4 } // Bool
9191nums.all { it > 0 } // Bool
9292nums.none { it > 9 } // Bool
@@ -103,7 +103,7 @@ nums.first() / nums.last() // ends (bounds-checked)
103103nums.toSet() // Set<T> of the elements
104104nums.toList() // a shallow copy
105105nums.onEach { print(it) } // side effect per element, returns the list
106- nums.withIndex() // List<Pair<Integer, T>> — index/value pairs
106+ nums.withIndex() // List<Pair<Integer, T>> - index/value pairs
107107nested.flatten() // List<List<T>> -> List<T>
108108nums.scan(0) { acc, x => acc + x } // running accumulations, incl. the seed
109109nums.runningFold(0) { acc, x => acc + x } // alias for scan
@@ -115,8 +115,8 @@ Whole-list reductions over the elements (numeric or `String`):
115115nums.sum() // numeric total (0 if empty)
116116nums.min() / nums.max() // natural extreme (aborts if empty)
117117nums.maxOf { it.score } / nums.minOf { it.score } // extreme of a projection
118- nums.contains(3) // Bool — membership
119- nums.indexOf(3) // Integer — first index, or -1
118+ nums.contains(3) // Bool - membership
119+ nums.indexOf(3) // Integer - first index, or -1
120120nums.single { it > 4 } // the one match (aborts if 0 or many)
121121```
122122
@@ -144,19 +144,19 @@ people.sortedByDescending { it.name }
144144Grouping and slicing into sublists:
145145
146146``` x
147- people.groupBy { it.team } // Map<K, List<T>> — bucket by a key
148- people.associateBy { it.id } // Map<K, T> — index by a key
149- items.associateWith { it.price } // Map<T, V> — element -> value (T is primitive/String)
150- nums.chunked(3) // List<List<T>> — consecutive groups
151- nums.windowed(3) // List<List<T>> — sliding windows
147+ people.groupBy { it.team } // Map<K, List<T>> - bucket by a key
148+ people.associateBy { it.id } // Map<K, T> - index by a key
149+ items.associateWith { it.price } // Map<T, V> - element -> value (T is primitive/String)
150+ nums.chunked(3) // List<List<T>> - consecutive groups
151+ nums.windowed(3) // List<List<T>> - sliding windows
152152```
153153
154154` groupBy ` results chain: ` people.groupBy { it.team }.get("x").average { it.age } ` .
155155
156156### Lazy sequences
157157
158158` asSequence() ` makes the pipeline ** lazy** : the chain of lazy operators plus the
159- terminal compile into a ** single fused loop** — no intermediate lists are built,
159+ terminal compile into a ** single fused loop** - no intermediate lists are built,
160160and ` take ` short-circuits.
161161
162162``` x
@@ -173,10 +173,10 @@ nums.asSequence().take(3).sum() // visits only the first 3 elements
173173- ** Terminals:** ` toList() ` , ` toSet() ` , ` forEach ` , ` fold(seed) ` , ` sum() ` ,
174174 ` count() ` , ` any ` , ` all ` , ` first() ` , ` firstOrNone() ` .
175175
176- They chain naturally — ` orders.filter { it.paid }.map { it.qty }.fold(0) { a, b => a + b } ` .
176+ They chain naturally - ` orders.filter { it.paid }.map { it.qty }.fold(0) { a, b => a + b } ` .
177177See ` examples/collections/functional_demo.xi ` .
178178
179- ## Pairs — ` Pair<A, B> `
179+ ## Pairs - ` Pair<A, B> `
180180
181181A two-value tuple. Build one with the ` to ` infix; read the members with ` .first `
182182and ` .second ` . ` A ` and ` B ` can be any types (including lists or other pairs).
@@ -192,7 +192,7 @@ Three `List` operations produce or consume pairs:
192192``` x
193193names.zip(ages) // List<Pair<String, Integer>> (truncated to the shorter)
194194nums.partition { it > 0 } // Pair<List<Integer> matching, List<Integer> not>
195- pairs.unzip // Pair<List<A>, List<B>> — splits a list of pairs back
195+ pairs.unzip // Pair<List<A>, List<B>> - splits a list of pairs back
196196```
197197
198198``` x
@@ -212,7 +212,7 @@ See `examples/collections/pairs_demo.xi`.
212212
213213## ` Set<T> `
214214
215- ` Set<T> ` is a hash set of ** unique** elements — also a built-in generic, created
215+ ` Set<T> ` is a hash set of ** unique** elements - also a built-in generic, created
216216with ` empty ` . Element-type-erased like ` List ` , with ` String ` elements compared by
217217content (not by reference).
218218
@@ -250,7 +250,7 @@ for x in ids { ... }
250250
251251## ` Map<K, V> `
252252
253- ` Map<K, V> ` is a hash map — a built-in generic, created with ` empty ` . Keys are
253+ ` Map<K, V> ` is a hash map - a built-in generic, created with ` empty ` . Keys are
254254primitives or ` String ` (compared by value, ` String ` by content); values can be
255255any type.
256256
@@ -266,7 +266,7 @@ let byId = empty Map<String, Item> // value can be a compound
266266
267267``` x
268268ages.put("ada", 37) // insert or overwrite
269- ages.get("ada") // value (aborts if the key is absent — guard with has)
269+ ages.get("ada") // value (aborts if the key is absent - guard with has)
270270ages.getOr("zz", 0) // value, or the fallback if absent
271271ages.has("ada") // Bool
272272ages.remove("ada") // delete (no-op if absent)
@@ -277,7 +277,7 @@ ages.keys() // a List<K> of the keys
277277ages.values() // a List<V> of the values
278278```
279279
280- Since lookups can miss, iterate over the keys (no ` null ` in Ξ — a missing key
280+ Since lookups can miss, iterate over the keys (no ` null ` in Ξ - a missing key
281281is simply not in ` keys() ` ):
282282
283283``` x
@@ -289,19 +289,19 @@ for k in ages.keys() {
289289
290290### Notes
291291
292- - ` get ` aborts if the key is absent — use ` has ` to check first, or ` getOr ` for a
292+ - ` get ` aborts if the key is absent - use ` has ` to check first, or ` getOr ` for a
293293 default. (A ` V? ` -returning lookup will follow once optionals are wired into the
294294 collection API.)
295295- Keys are restricted to primitives and ` String ` ; values may be any type.
296296- A ` Map<K, V> ` is a mutable handle (reference semantics). Iteration order is
297297 unspecified.
298298
299- ## ` Vec<T> ` — dynamic array
299+ ## ` Vec<T> ` - dynamic array
300300
301301` Vec<T> ` is a growable, index-addressable array. It is the ** same type as
302- ` List<T> ` ** under a familiar name, so it has the entire ` List ` surface — indexing
302+ ` List<T> ` ** under a familiar name, so it has the entire ` List ` surface - indexing
303303(` get ` /` set ` ), ` push ` /` removeAt ` , the whole [ functional API] ( #functional-operations-on-listt ) ,
304- and lazy sequences — plus two array conveniences:
304+ and lazy sequences - plus two array conveniences:
305305
306306``` x
307307let v = vecOf(1, 2, 4) // or: empty Vec<Integer>
@@ -314,7 +314,7 @@ v.map { it * 2 }.filter { it > 4 } // the functional pipeline, as on List
314314Because ` Vec<T> ` and ` List<T> ` are interchangeable, a value built with ` vecOf `
315315can be passed wherever a ` List<T> ` is expected, and vice versa.
316316
317- ## ` Stack<T> ` — LIFO
317+ ## ` Stack<T> ` - LIFO
318318
319319``` x
320320let s = empty Stack<Integer> // or: stackOf(1, 2, 3)
@@ -324,7 +324,7 @@ s.pop() // remove & return the top (aborts if empty)
324324s.len() s.isEmpty() s.clear()
325325```
326326
327- ## ` Queue<T> ` — FIFO
327+ ## ` Queue<T> ` - FIFO
328328
329329``` x
330330let q = empty Queue<String> // or: queueOf("a", "b")
@@ -336,7 +336,7 @@ q.len() q.isEmpty() q.clear()
336336
337337Dequeue is amortised O(1) (an internal head index, no per-element shifting).
338338
339- ## ` SortedQueue<T> ` — priority queue
339+ ## ` SortedQueue<T> ` - priority queue
340340
341341A binary ** min-heap** : ` pop ` /` peek ` always return the ** smallest** element by
342342natural order. Element types are the comparable primitives (` Integer ` , ` Number ` ,
@@ -345,7 +345,7 @@ natural order. Element types are the comparable primitives (`Integer`, `Number`,
345345``` x
346346let pq = sortedQueueOf(5, 1, 9, 3) // or: empty SortedQueue<Integer>
347347pq.push(2)
348- pq.peek() // 1 — the minimum (aborts if empty)
348+ pq.peek() // 1 - the minimum (aborts if empty)
349349pq.pop() // 1, then 2, then 3, ... (ascending)
350350pq.len() pq.isEmpty() pq.clear()
351351```
@@ -354,11 +354,11 @@ pq.len() pq.isEmpty() pq.clear()
354354> guard with ` isEmpty() ` /` len() ` . These containers are mutable handles (reference
355355> semantics), like ` List ` . See ` examples/collections/containers_demo.xi ` .
356356
357- ## Lazy infinite sources — ` generateSequence `
357+ ## Lazy infinite sources - ` generateSequence `
358358
359359` generateSequence(seed) { next } ` is a lazy source whose value starts at ` seed `
360360and advances through the generator each step. It fuses into the sequence loop like
361- any other source, so it's only as long as the bounded terminal asks for — ** always
361+ any other source, so it's only as long as the bounded terminal asks for - ** always
362362bound it** with ` take ` , ` takeWhile ` , or ` first ` :
363363
364364``` x
0 commit comments