@grain/stdlib 0.6.6 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/array.gr +55 -7
  5. package/array.md +606 -560
  6. package/bigint.md +228 -228
  7. package/buffer.gr +85 -53
  8. package/buffer.md +442 -319
  9. package/bytes.gr +112 -35
  10. package/bytes.md +299 -219
  11. package/char.gr +201 -99
  12. package/char.md +447 -120
  13. package/exception.gr +11 -11
  14. package/exception.md +29 -4
  15. package/float32.gr +327 -3
  16. package/float32.md +698 -111
  17. package/float64.gr +320 -3
  18. package/float64.md +698 -111
  19. package/fs.gr +1082 -0
  20. package/fs.md +630 -0
  21. package/hash.gr +142 -88
  22. package/hash.md +105 -17
  23. package/int16.md +178 -178
  24. package/int32.gr +26 -5
  25. package/int32.md +266 -231
  26. package/int64.gr +27 -2
  27. package/int64.md +266 -231
  28. package/int8.md +178 -178
  29. package/json.gr +366 -51
  30. package/json.md +431 -15
  31. package/list.gr +328 -31
  32. package/list.md +759 -336
  33. package/map.gr +20 -12
  34. package/map.md +266 -260
  35. package/marshal.gr +41 -40
  36. package/marshal.md +14 -14
  37. package/number.gr +278 -35
  38. package/number.md +688 -269
  39. package/option.md +162 -162
  40. package/package.json +5 -3
  41. package/path.gr +48 -0
  42. package/path.md +180 -89
  43. package/pervasives.gr +2 -2
  44. package/pervasives.md +275 -275
  45. package/priorityqueue.gr +7 -7
  46. package/priorityqueue.md +131 -131
  47. package/queue.gr +183 -29
  48. package/queue.md +404 -148
  49. package/random.md +43 -43
  50. package/range.gr +4 -4
  51. package/range.md +42 -42
  52. package/rational.md +123 -123
  53. package/regex.gr +52 -51
  54. package/regex.md +102 -102
  55. package/result.md +118 -118
  56. package/runtime/atof/common.md +39 -39
  57. package/runtime/atof/decimal.gr +6 -6
  58. package/runtime/atof/decimal.md +14 -14
  59. package/runtime/atof/lemire.gr +5 -5
  60. package/runtime/atof/lemire.md +1 -1
  61. package/runtime/atof/parse.gr +16 -16
  62. package/runtime/atof/parse.md +2 -2
  63. package/runtime/atof/slow.md +1 -1
  64. package/runtime/atof/table.md +2 -2
  65. package/runtime/atoi/parse.gr +3 -3
  66. package/runtime/atoi/parse.md +1 -1
  67. package/runtime/bigint.gr +15 -47
  68. package/runtime/bigint.md +54 -60
  69. package/runtime/compare.gr +2 -2
  70. package/runtime/compare.md +8 -8
  71. package/runtime/dataStructures.md +211 -211
  72. package/runtime/debugPrint.gr +4 -1
  73. package/runtime/debugPrint.md +9 -9
  74. package/runtime/equal.gr +99 -77
  75. package/runtime/equal.md +8 -8
  76. package/runtime/exception.gr +62 -82
  77. package/runtime/exception.md +62 -11
  78. package/runtime/gc.gr +39 -45
  79. package/runtime/gc.md +4 -4
  80. package/runtime/malloc.gr +7 -7
  81. package/runtime/malloc.md +13 -13
  82. package/runtime/math/kernel/cos.gr +70 -0
  83. package/runtime/math/kernel/cos.md +14 -0
  84. package/runtime/math/kernel/sin.gr +65 -0
  85. package/runtime/math/kernel/sin.md +14 -0
  86. package/runtime/math/kernel/tan.gr +136 -0
  87. package/runtime/math/kernel/tan.md +14 -0
  88. package/runtime/math/rempio2.gr +244 -0
  89. package/runtime/math/rempio2.md +14 -0
  90. package/runtime/math/trig.gr +130 -0
  91. package/runtime/math/trig.md +28 -0
  92. package/runtime/math/umuldi.gr +26 -0
  93. package/runtime/math/umuldi.md +14 -0
  94. package/runtime/numberUtils.gr +29 -29
  95. package/runtime/numberUtils.md +12 -12
  96. package/runtime/numbers.gr +373 -381
  97. package/runtime/numbers.md +348 -342
  98. package/runtime/string.gr +37 -105
  99. package/runtime/string.md +20 -26
  100. package/runtime/unsafe/constants.md +24 -24
  101. package/runtime/unsafe/conv.md +19 -19
  102. package/runtime/unsafe/memory.gr +24 -20
  103. package/runtime/unsafe/memory.md +27 -7
  104. package/runtime/unsafe/offsets.gr +36 -0
  105. package/runtime/unsafe/offsets.md +88 -0
  106. package/runtime/unsafe/panic.gr +28 -0
  107. package/runtime/unsafe/panic.md +14 -0
  108. package/runtime/unsafe/tags.md +32 -32
  109. package/runtime/unsafe/wasmf32.md +28 -28
  110. package/runtime/unsafe/wasmf64.md +28 -28
  111. package/runtime/unsafe/wasmi32.md +47 -47
  112. package/runtime/unsafe/wasmi64.md +50 -50
  113. package/runtime/utf8.gr +189 -0
  114. package/runtime/utf8.md +117 -0
  115. package/runtime/wasi.gr +4 -2
  116. package/runtime/wasi.md +147 -147
  117. package/set.gr +18 -11
  118. package/set.md +253 -247
  119. package/stack.gr +171 -2
  120. package/stack.md +371 -89
  121. package/string.gr +352 -557
  122. package/string.md +298 -255
  123. package/uint16.md +170 -170
  124. package/uint32.gr +25 -4
  125. package/uint32.md +249 -214
  126. package/uint64.gr +25 -5
  127. package/uint64.md +249 -214
  128. package/uint8.md +170 -170
  129. package/uri.gr +57 -53
  130. package/uri.md +88 -89
  131. package/wasi/file.gr +67 -59
  132. package/wasi/file.md +308 -308
  133. package/wasi/process.md +26 -26
  134. package/wasi/random.md +12 -12
  135. package/wasi/time.md +16 -16
  136. package/runtime/utils/printing.gr +0 -60
  137. package/runtime/utils/printing.md +0 -26
package/queue.md CHANGED
@@ -17,6 +17,14 @@ No other changes yet.
17
17
  from "queue" include Queue
18
18
  ```
19
19
 
20
+ ```grain
21
+ let queue = Queue.fromList([0, 1])
22
+ Queue.push(2, queue)
23
+ assert Queue.pop(queue) == Some(0)
24
+ assert Queue.pop(queue) == Some(1)
25
+ assert Queue.pop(queue) == Some(2)
26
+ ```
27
+
20
28
  ## Types
21
29
 
22
30
  Type declarations included in the Queue module.
@@ -41,25 +49,35 @@ No other changes yet.
41
49
  </details>
42
50
 
43
51
  ```grain
44
- make : (?size: Number) => Queue<a>
52
+ make: (?size: Number) => Queue<a>
45
53
  ```
46
54
 
47
55
  Creates a new queue with an initial storage of the given size. As values are
48
56
  added or removed, the internal storage may grow or shrink. Generally, you
49
- won’t need to care about the storage size of your map and can use the
57
+ won’t need to care about the storage size of your queue and can use the
50
58
  default size.
51
59
 
52
60
  Parameters:
53
61
 
54
- |param|type|description|
55
- |-----|----|-----------|
56
- |`?size`|`Number`|The initial storage size of the queue|
62
+ | param | type | description |
63
+ | ------- | -------- | ------------------------------------- |
64
+ | `?size` | `Number` | The initial storage size of the queue |
57
65
 
58
66
  Returns:
59
67
 
60
- |type|description|
61
- |----|-----------|
62
- |`Queue<a>`|An empty queue|
68
+ | type | description |
69
+ | ---------- | -------------- |
70
+ | `Queue<a>` | An empty queue |
71
+
72
+ Examples:
73
+
74
+ ```grain
75
+ Queue.make() // Creates a new queue
76
+ ```
77
+
78
+ ```grain
79
+ Queue.make(size=16) // Creates a new queue with an initial size of 16
80
+ ```
63
81
 
64
82
  ### Queue.**isEmpty**
65
83
 
@@ -69,22 +87,32 @@ No other changes yet.
69
87
  </details>
70
88
 
71
89
  ```grain
72
- isEmpty : (queue: Queue<a>) => Bool
90
+ isEmpty: (queue: Queue<a>) => Bool
73
91
  ```
74
92
 
75
93
  Checks if the given queue contains no items.
76
94
 
77
95
  Parameters:
78
96
 
79
- |param|type|description|
80
- |-----|----|-----------|
81
- |`queue`|`Queue<a>`|The queue to check|
97
+ | param | type | description |
98
+ | ------- | ---------- | ------------------ |
99
+ | `queue` | `Queue<a>` | The queue to check |
82
100
 
83
101
  Returns:
84
102
 
85
- |type|description|
86
- |----|-----------|
87
- |`Bool`|`true` if the queue has no items or `false` otherwise|
103
+ | type | description |
104
+ | ------ | ----------------------------------------------------- |
105
+ | `Bool` | `true` if the queue has no items or `false` otherwise |
106
+
107
+ Examples:
108
+
109
+ ```grain
110
+ Queue.isEmpty(Queue.make()) == true
111
+ ```
112
+
113
+ ```grain
114
+ Queue.isEmpty(Queue.fromList([1, 2])) == false
115
+ ```
88
116
 
89
117
  ### Queue.**size**
90
118
 
@@ -94,22 +122,32 @@ No other changes yet.
94
122
  </details>
95
123
 
96
124
  ```grain
97
- size : (queue: Queue<a>) => Number
125
+ size: (queue: Queue<a>) => Number
98
126
  ```
99
127
 
100
128
  Computes the size of the input queue.
101
129
 
102
130
  Parameters:
103
131
 
104
- |param|type|description|
105
- |-----|----|-----------|
106
- |`queue`|`Queue<a>`|The queue to inspect|
132
+ | param | type | description |
133
+ | ------- | ---------- | -------------------- |
134
+ | `queue` | `Queue<a>` | The queue to inspect |
107
135
 
108
136
  Returns:
109
137
 
110
- |type|description|
111
- |----|-----------|
112
- |`Number`|The count of the items in the queue|
138
+ | type | description |
139
+ | -------- | ----------------------------------- |
140
+ | `Number` | The count of the items in the queue |
141
+
142
+ Examples:
143
+
144
+ ```grain
145
+ Queue.size(Queue.make()) == 0
146
+ ```
147
+
148
+ ```grain
149
+ Queue.size(Queue.fromList([1, 2])) == 2
150
+ ```
113
151
 
114
152
  ### Queue.**peek**
115
153
 
@@ -119,22 +157,34 @@ No other changes yet.
119
157
  </details>
120
158
 
121
159
  ```grain
122
- peek : (queue: Queue<a>) => Option<a>
160
+ peek: (queue: Queue<a>) => Option<a>
123
161
  ```
124
162
 
125
163
  Provides the value at the beginning of the queue, if it exists.
126
164
 
127
165
  Parameters:
128
166
 
129
- |param|type|description|
130
- |-----|----|-----------|
131
- |`queue`|`Queue<a>`|The queue to inspect|
167
+ | param | type | description |
168
+ | ------- | ---------- | -------------------- |
169
+ | `queue` | `Queue<a>` | The queue to inspect |
132
170
 
133
171
  Returns:
134
172
 
135
- |type|description|
136
- |----|-----------|
137
- |`Option<a>`|`Some(value)` containing the value at the beginning of the queue or `None` otherwise.|
173
+ | type | description |
174
+ | ----------- | ------------------------------------------------------------------------------------- |
175
+ | `Option<a>` | `Some(value)` containing the value at the beginning of the queue or `None` otherwise. |
176
+
177
+ Examples:
178
+
179
+ ```grain
180
+ Queue.peek(Queue.make()) == None
181
+ ```
182
+
183
+ ```grain
184
+ let queue = Queue.make()
185
+ Queue.push(1, queue)
186
+ assert Queue.peek(queue) == Some(1)
187
+ ```
138
188
 
139
189
  ### Queue.**push**
140
190
 
@@ -144,17 +194,26 @@ No other changes yet.
144
194
  </details>
145
195
 
146
196
  ```grain
147
- push : (value: a, queue: Queue<a>) => Void
197
+ push: (value: a, queue: Queue<a>) => Void
148
198
  ```
149
199
 
150
200
  Adds a new item to the end of the queue.
151
201
 
152
202
  Parameters:
153
203
 
154
- |param|type|description|
155
- |-----|----|-----------|
156
- |`value`|`a`|The item to be added|
157
- |`queue`|`Queue<a>`|The queue being updated|
204
+ | param | type | description |
205
+ | ------- | ---------- | ----------------------- |
206
+ | `value` | `a` | The item to be added |
207
+ | `queue` | `Queue<a>` | The queue being updated |
208
+
209
+ Examples:
210
+
211
+ ```grain
212
+ let queue = Queue.make()
213
+ assert Queue.peek(queue) == None
214
+ Queue.push(1, queue)
215
+ assert Queue.peek(queue) == Some(1)
216
+ ```
158
217
 
159
218
  ### Queue.**pop**
160
219
 
@@ -164,24 +223,33 @@ No other changes yet.
164
223
  </details>
165
224
 
166
225
  ```grain
167
- pop : (queue: Queue<a>) => Option<a>
226
+ pop: (queue: Queue<a>) => Option<a>
168
227
  ```
169
228
 
170
229
  Removes the item at the beginning of the queue.
171
230
 
172
231
  Parameters:
173
232
 
174
- |param|type|description|
175
- |-----|----|-----------|
176
- |`queue`|`Queue<a>`|The queue being updated|
233
+ | param | type | description |
234
+ | ------- | ---------- | ----------------------- |
235
+ | `queue` | `Queue<a>` | The queue being updated |
177
236
 
178
237
  Returns:
179
238
 
180
- |type|description|
181
- |----|-----------|
182
- |`Option<a>`|The element removed from the queue|
239
+ | type | description |
240
+ | ----------- | ---------------------------------- |
241
+ | `Option<a>` | The element removed from the queue |
183
242
 
184
- ### Queue.**toList**
243
+ Examples:
244
+
245
+ ```grain
246
+ let queue = Queue.make()
247
+ Queue.push(1, queue)
248
+ assert Queue.pop(queue) == Some(1)
249
+ assert Queue.pop(queue) == None
250
+ ```
251
+
252
+ ### Queue.**clear**
185
253
 
186
254
  <details disabled>
187
255
  <summary tabindex="-1">Added in <code>0.6.0</code></summary>
@@ -189,24 +257,28 @@ No other changes yet.
189
257
  </details>
190
258
 
191
259
  ```grain
192
- toList : (queue: Queue<a>) => List<a>
260
+ clear: (queue: Queue<a>) => Void
193
261
  ```
194
262
 
195
- Converts a queue into a list of its elements.
263
+ Clears the queue by removing all of its elements.
196
264
 
197
265
  Parameters:
198
266
 
199
- |param|type|description|
200
- |-----|----|-----------|
201
- |`queue`|`Queue<a>`|The queue to convert|
267
+ | param | type | description |
268
+ | ------- | ---------- | ------------------ |
269
+ | `queue` | `Queue<a>` | The queue to clear |
202
270
 
203
- Returns:
271
+ Examples:
204
272
 
205
- |type|description|
206
- |----|-----------|
207
- |`List<a>`|A list containing all queue values|
273
+ ```grain
274
+ let queue = Queue.make()
275
+ Queue.push(1, queue)
276
+ assert Queue.size(queue) == 1
277
+ Queue.clear(queue)
278
+ assert Queue.size(queue) == 0
279
+ ```
208
280
 
209
- ### Queue.**fromList**
281
+ ### Queue.**copy**
210
282
 
211
283
  <details disabled>
212
284
  <summary tabindex="-1">Added in <code>0.6.0</code></summary>
@@ -214,24 +286,34 @@ No other changes yet.
214
286
  </details>
215
287
 
216
288
  ```grain
217
- fromList : (list: List<a>) => Queue<a>
289
+ copy: (queue: Queue<a>) => Queue<a>
218
290
  ```
219
291
 
220
- Creates a queue from a list.
292
+ Produces a shallow copy of the input queue.
221
293
 
222
294
  Parameters:
223
295
 
224
- |param|type|description|
225
- |-----|----|-----------|
226
- |`list`|`List<a>`|The list to convert|
296
+ | param | type | description |
297
+ | ------- | ---------- | ----------------- |
298
+ | `queue` | `Queue<a>` | The queue to copy |
227
299
 
228
300
  Returns:
229
301
 
230
- |type|description|
231
- |----|-----------|
232
- |`Queue<a>`|A queue containing all list values|
302
+ | type | description |
303
+ | ---------- | -------------------------------------------------- |
304
+ | `Queue<a>` | A new queue containing the elements from the input |
233
305
 
234
- ### Queue.**clear**
306
+ Examples:
307
+
308
+ ```grain
309
+ let queue = Queue.make()
310
+ Queue.push(1, queue)
311
+ let copiedQueue = Queue.copy(queue)
312
+ Queue.push(2, queue) // Does not affect copiedQueue
313
+ assert Queue.pop(copiedQueue) == Some(1)
314
+ ```
315
+
316
+ ### Queue.**toList**
235
317
 
236
318
  <details disabled>
237
319
  <summary tabindex="-1">Added in <code>0.6.0</code></summary>
@@ -239,18 +321,34 @@ No other changes yet.
239
321
  </details>
240
322
 
241
323
  ```grain
242
- clear : (queue: Queue<a>) => Void
324
+ toList: (queue: Queue<a>) => List<a>
243
325
  ```
244
326
 
245
- Clears the queue by removing all of its elements
327
+ Converts a queue into a list of its elements.
246
328
 
247
329
  Parameters:
248
330
 
249
- |param|type|description|
250
- |-----|----|-----------|
251
- |`queue`|`Queue<a>`|The queue to clear|
331
+ | param | type | description |
332
+ | ------- | ---------- | -------------------- |
333
+ | `queue` | `Queue<a>` | The queue to convert |
252
334
 
253
- ### Queue.**copy**
335
+ Returns:
336
+
337
+ | type | description |
338
+ | --------- | ---------------------------------- |
339
+ | `List<a>` | A list containing all queue values |
340
+
341
+ Examples:
342
+
343
+ ```grain
344
+ let queue = Queue.make()
345
+ Queue.push(0, queue)
346
+ Queue.push(1, queue)
347
+ Queue.push(2, queue)
348
+ assert Queue.toList(queue) == [0, 1, 2]
349
+ ```
350
+
351
+ ### Queue.**fromList**
254
352
 
255
353
  <details disabled>
256
354
  <summary tabindex="-1">Added in <code>0.6.0</code></summary>
@@ -258,22 +356,30 @@ No other changes yet.
258
356
  </details>
259
357
 
260
358
  ```grain
261
- copy : (queue: Queue<a>) => Queue<a>
359
+ fromList: (list: List<a>) => Queue<a>
262
360
  ```
263
361
 
264
- Produces a shallow copy of the input queue.
362
+ Creates a queue from a list.
265
363
 
266
364
  Parameters:
267
365
 
268
- |param|type|description|
269
- |-----|----|-----------|
270
- |`queue`|`Queue<a>`|The queue to copy|
366
+ | param | type | description |
367
+ | ------ | --------- | ------------------- |
368
+ | `list` | `List<a>` | The list to convert |
271
369
 
272
370
  Returns:
273
371
 
274
- |type|description|
275
- |----|-----------|
276
- |`Queue<a>`|A new queue containing the elements from the input|
372
+ | type | description |
373
+ | ---------- | ---------------------------------- |
374
+ | `Queue<a>` | A queue containing all list values |
375
+
376
+ Examples:
377
+
378
+ ```grain
379
+ let queue = Queue.fromList([0, 1])
380
+ assert Queue.pop(queue) == Some(0)
381
+ assert Queue.pop(queue) == Some(1)
382
+ ```
277
383
 
278
384
  ### Queue.**toArray**
279
385
 
@@ -283,22 +389,32 @@ No other changes yet.
283
389
  </details>
284
390
 
285
391
  ```grain
286
- toArray : (queue: Queue<a>) => Array<a>
392
+ toArray: (queue: Queue<a>) => Array<a>
287
393
  ```
288
394
 
289
395
  Converts a queue into an array of its values.
290
396
 
291
397
  Parameters:
292
398
 
293
- |param|type|description|
294
- |-----|----|-----------|
295
- |`queue`|`Queue<a>`|The queue to convert|
399
+ | param | type | description |
400
+ | ------- | ---------- | -------------------- |
401
+ | `queue` | `Queue<a>` | The queue to convert |
296
402
 
297
403
  Returns:
298
404
 
299
- |type|description|
300
- |----|-----------|
301
- |`Array<a>`|An array containing all values from the given queue|
405
+ | type | description |
406
+ | ---------- | --------------------------------------------------- |
407
+ | `Array<a>` | An array containing all values from the given queue |
408
+
409
+ Examples:
410
+
411
+ ```grain
412
+ let queue = Queue.make()
413
+ Queue.push(0, queue)
414
+ Queue.push(1, queue)
415
+ Queue.push(2, queue)
416
+ assert Queue.toArray(queue) == [> 0, 1, 2]
417
+ ```
302
418
 
303
419
  ### Queue.**fromArray**
304
420
 
@@ -308,22 +424,30 @@ No other changes yet.
308
424
  </details>
309
425
 
310
426
  ```grain
311
- fromArray : (arr: Array<a>) => Queue<a>
427
+ fromArray: (arr: Array<a>) => Queue<a>
312
428
  ```
313
429
 
314
430
  Creates a queue from an array.
315
431
 
316
432
  Parameters:
317
433
 
318
- |param|type|description|
319
- |-----|----|-----------|
320
- |`arr`|`Array<a>`|The array to convert|
434
+ | param | type | description |
435
+ | ----- | ---------- | -------------------- |
436
+ | `arr` | `Array<a>` | The array to convert |
321
437
 
322
438
  Returns:
323
439
 
324
- |type|description|
325
- |----|-----------|
326
- |`Queue<a>`|A queue containing all values from the array|
440
+ | type | description |
441
+ | ---------- | -------------------------------------------- |
442
+ | `Queue<a>` | A queue containing all values from the array |
443
+
444
+ Examples:
445
+
446
+ ```grain
447
+ let queue = Queue.fromArray([> 0, 1])
448
+ assert Queue.pop(queue) == Some(0)
449
+ assert Queue.pop(queue) == Some(1)
450
+ ```
327
451
 
328
452
  ### Queue.**(==)**
329
453
 
@@ -333,34 +457,77 @@ No other changes yet.
333
457
  </details>
334
458
 
335
459
  ```grain
336
- (==) : (queue1: Queue<a>, queue2: Queue<a>) => Bool
460
+ (==): (queue1: Queue<a>, queue2: Queue<a>) => Bool
337
461
  ```
338
462
 
339
463
  Checks if two queues are equivalent by value.
340
464
 
341
465
  Parameters:
342
466
 
343
- |param|type|description|
344
- |-----|----|-----------|
345
- |`queue1`|`Queue<a>`|The first queue to compare|
346
- |`queue2`|`Queue<a>`|The second queue to compare|
467
+ | param | type | description |
468
+ | -------- | ---------- | --------------------------- |
469
+ | `queue1` | `Queue<a>` | The first queue to compare |
470
+ | `queue2` | `Queue<a>` | The second queue to compare |
347
471
 
348
472
  Returns:
349
473
 
350
- |type|description|
351
- |----|-----------|
352
- |`Bool`|`true` if the queues are equivalent or `false` otherwise|
474
+ | type | description |
475
+ | ------ | -------------------------------------------------------- |
476
+ | `Bool` | `true` if the queues are equivalent or `false` otherwise |
477
+
478
+ Examples:
479
+
480
+ ```grain
481
+ use Queue.{ (==) }
482
+ let queue1 = Queue.fromList([0, 1, 2])
483
+ let queue2 = Queue.fromList([0, 1, 2])
484
+ assert queue1 == queue2
485
+ ```
486
+
487
+ ```grain
488
+ use Queue.{ (==) }
489
+ let queue1 = Queue.fromList([0, 1, 2])
490
+ let queue2 = Queue.fromList([0, 1, 3])
491
+ assert !(queue1 == queue2)
492
+ ```
353
493
 
354
494
  ## Queue.Immutable
355
495
 
356
496
  An immutable queue implementation.
357
497
 
498
+ <details disabled>
499
+ <summary tabindex="-1">Added in <code>0.6.0</code></summary>
500
+ No other changes yet.
501
+ </details>
502
+
503
+ ```grain
504
+ let queue = Immutable.Queue.fromList([0, 1])
505
+ let queue = Immutable.Queue.push(2, queue)
506
+ assert Immutable.Queue.peek(queue) == Some(0)
507
+ let queue = Immutable.Queue.pop(queue)
508
+ assert Immutable.Queue.peek(queue) == Some(1)
509
+ ignore(Queue.Immutable.pop(queue)) // Does not affect the original queue
510
+ assert Immutable.Queue.peek(queue) == Some(1)
511
+ ```
512
+
358
513
  ### Types
359
514
 
360
515
  Type declarations included in the Queue.Immutable module.
361
516
 
362
517
  #### Queue.Immutable.**ImmutableQueue**
363
518
 
519
+ <details>
520
+ <summary>Added in <code>0.6.0</code></summary>
521
+ <table>
522
+ <thead>
523
+ <tr><th>version</th><th>changes</th></tr>
524
+ </thead>
525
+ <tbody>
526
+ <tr><td><code>0.5.4</code></td><td>Originally a module root API</td></tr>
527
+ </tbody>
528
+ </table>
529
+ </details>
530
+
364
531
  ```grain
365
532
  type ImmutableQueue<a>
366
533
  ```
@@ -386,11 +553,18 @@ Functions and constants included in the Queue.Immutable module.
386
553
  </details>
387
554
 
388
555
  ```grain
389
- empty : ImmutableQueue<a>
556
+ empty: ImmutableQueue<a>
390
557
  ```
391
558
 
392
559
  An empty queue.
393
560
 
561
+ Examples:
562
+
563
+ ```grain
564
+ let queue = Queue.Immutable.empty
565
+ assert Queue.Immutable.isEmpty(queue)
566
+ ```
567
+
394
568
  #### Queue.Immutable.**isEmpty**
395
569
 
396
570
  <details>
@@ -406,22 +580,32 @@ An empty queue.
406
580
  </details>
407
581
 
408
582
  ```grain
409
- isEmpty : (queue: ImmutableQueue<a>) => Bool
583
+ isEmpty: (queue: ImmutableQueue<a>) => Bool
410
584
  ```
411
585
 
412
586
  Checks if the given queue contains any values.
413
587
 
414
588
  Parameters:
415
589
 
416
- |param|type|description|
417
- |-----|----|-----------|
418
- |`queue`|`ImmutableQueue<a>`|The queue to check|
590
+ | param | type | description |
591
+ | ------- | ------------------- | ------------------ |
592
+ | `queue` | `ImmutableQueue<a>` | The queue to check |
419
593
 
420
594
  Returns:
421
595
 
422
- |type|description|
423
- |----|-----------|
424
- |`Bool`|`true` if the given queue is empty or `false` otherwise|
596
+ | type | description |
597
+ | ------ | ------------------------------------------------------- |
598
+ | `Bool` | `true` if the given queue is empty or `false` otherwise |
599
+
600
+ Examples:
601
+
602
+ ```grain
603
+ Queue.Immutable.isEmpty(Queue.Immutable.empty) == true
604
+ ```
605
+
606
+ ```grain
607
+ Queue.Immutable.isEmpty(Queue.Immutable.fromList([1, 2])) == false
608
+ ```
425
609
 
426
610
  #### Queue.Immutable.**peek**
427
611
 
@@ -441,22 +625,34 @@ Returns:
441
625
  </details>
442
626
 
443
627
  ```grain
444
- peek : (queue: ImmutableQueue<a>) => Option<a>
628
+ peek: (queue: ImmutableQueue<a>) => Option<a>
445
629
  ```
446
630
 
447
631
  Returns the value at the beginning of the queue. It is not removed from the queue.
448
632
 
449
633
  Parameters:
450
634
 
451
- |param|type|description|
452
- |-----|----|-----------|
453
- |`queue`|`ImmutableQueue<a>`|The queue to inspect|
635
+ | param | type | description |
636
+ | ------- | ------------------- | -------------------- |
637
+ | `queue` | `ImmutableQueue<a>` | The queue to inspect |
454
638
 
455
639
  Returns:
456
640
 
457
- |type|description|
458
- |----|-----------|
459
- |`Option<a>`|`Some(value)` containing the value at the beginning of the queue, or `None` if the queue is empty|
641
+ | type | description |
642
+ | ----------- | ------------------------------------------------------------------------------------------------- |
643
+ | `Option<a>` | `Some(value)` containing the value at the beginning of the queue, or `None` if the queue is empty |
644
+
645
+ Examples:
646
+
647
+ ```grain
648
+ let queue = Queue.Immutable.fromList([1, 2, 3])
649
+ assert Queue.Immutable.peek(queue) == Some(1)
650
+ ```
651
+
652
+ ```grain
653
+ let queue = Queue.Immutable.empty
654
+ assert Queue.Immutable.peek(queue) == None
655
+ ```
460
656
 
461
657
  #### Queue.Immutable.**push**
462
658
 
@@ -476,23 +672,32 @@ Returns:
476
672
  </details>
477
673
 
478
674
  ```grain
479
- push : (value: a, queue: ImmutableQueue<a>) => ImmutableQueue<a>
675
+ push: (value: a, queue: ImmutableQueue<a>) => ImmutableQueue<a>
480
676
  ```
481
677
 
482
678
  Adds a value to the end of the queue.
483
679
 
484
680
  Parameters:
485
681
 
486
- |param|type|description|
487
- |-----|----|-----------|
488
- |`value`|`a`|The value to append|
489
- |`queue`|`ImmutableQueue<a>`|The queue to update|
682
+ | param | type | description |
683
+ | ------- | ------------------- | ------------------- |
684
+ | `value` | `a` | The value to append |
685
+ | `queue` | `ImmutableQueue<a>` | The queue to update |
490
686
 
491
687
  Returns:
492
688
 
493
- |type|description|
494
- |----|-----------|
495
- |`ImmutableQueue<a>`|An updated queue|
689
+ | type | description |
690
+ | ------------------- | ---------------- |
691
+ | `ImmutableQueue<a>` | An updated queue |
692
+
693
+ Examples:
694
+
695
+ ```grain
696
+ let queue = Queue.Immutable.fromList([1])
697
+ assert Queue.Immutable.size(queue) == 1
698
+ let queue = Queue.Immutable.push(2, queue)
699
+ assert Queue.Immutable.size(queue) == 2
700
+ ```
496
701
 
497
702
  #### Queue.Immutable.**pop**
498
703
 
@@ -512,22 +717,36 @@ Returns:
512
717
  </details>
513
718
 
514
719
  ```grain
515
- pop : (queue: ImmutableQueue<a>) => ImmutableQueue<a>
720
+ pop: (queue: ImmutableQueue<a>) => ImmutableQueue<a>
516
721
  ```
517
722
 
518
723
  Dequeues the next value in the queue.
519
724
 
520
725
  Parameters:
521
726
 
522
- |param|type|description|
523
- |-----|----|-----------|
524
- |`queue`|`ImmutableQueue<a>`|The queue to change|
727
+ | param | type | description |
728
+ | ------- | ------------------- | ------------------- |
729
+ | `queue` | `ImmutableQueue<a>` | The queue to change |
525
730
 
526
731
  Returns:
527
732
 
528
- |type|description|
529
- |----|-----------|
530
- |`ImmutableQueue<a>`|An updated queue|
733
+ | type | description |
734
+ | ------------------- | ---------------- |
735
+ | `ImmutableQueue<a>` | An updated queue |
736
+
737
+ Examples:
738
+
739
+ ```grain
740
+ let queue = Queue.Immutable.fromList([1, 2, 3])
741
+ let queue = Queue.Immutable.pop(queue)
742
+ assert Queue.Immutable.peek(queue) == Some(2)
743
+ ```
744
+
745
+ ```grain
746
+ let queue = Queue.Immutable.empty
747
+ let queue = Queue.Immutable.pop(queue)
748
+ assert Queue.Immutable.isEmpty(queue)
749
+ ```
531
750
 
532
751
  #### Queue.Immutable.**size**
533
752
 
@@ -544,22 +763,32 @@ Returns:
544
763
  </details>
545
764
 
546
765
  ```grain
547
- size : (queue: ImmutableQueue<a>) => Number
766
+ size: (queue: ImmutableQueue<a>) => Number
548
767
  ```
549
768
 
550
769
  Get the number of values in a queue.
551
770
 
552
771
  Parameters:
553
772
 
554
- |param|type|description|
555
- |-----|----|-----------|
556
- |`queue`|`ImmutableQueue<a>`|The queue to inspect|
773
+ | param | type | description |
774
+ | ------- | ------------------- | -------------------- |
775
+ | `queue` | `ImmutableQueue<a>` | The queue to inspect |
557
776
 
558
777
  Returns:
559
778
 
560
- |type|description|
561
- |----|-----------|
562
- |`Number`|The number of values in the queue|
779
+ | type | description |
780
+ | -------- | --------------------------------- |
781
+ | `Number` | The number of values in the queue |
782
+
783
+ Examples:
784
+
785
+ ```grain
786
+ Queue.Immutable.size(Queue.Immutable.empty) == 0
787
+ ```
788
+
789
+ ```grain
790
+ Queue.Immutable.size(Queue.Immutable.fromList([1, 2])) == 2
791
+ ```
563
792
 
564
793
  #### Queue.Immutable.**toList**
565
794
 
@@ -569,22 +798,41 @@ No other changes yet.
569
798
  </details>
570
799
 
571
800
  ```grain
572
- toList : (queue: ImmutableQueue<a>) => List<a>
801
+ toList: (queue: ImmutableQueue<a>) => List<a>
573
802
  ```
574
803
 
575
804
  Converts a queue into a list of its elements.
576
805
 
577
806
  Parameters:
578
807
 
579
- |param|type|description|
580
- |-----|----|-----------|
581
- |`queue`|`ImmutableQueue<a>`|The queue to convert|
808
+ | param | type | description |
809
+ | ------- | ------------------- | -------------------- |
810
+ | `queue` | `ImmutableQueue<a>` | The queue to convert |
582
811
 
583
812
  Returns:
584
813
 
585
- |type|description|
586
- |----|-----------|
587
- |`List<a>`|A list containing all queue values|
814
+ | type | description |
815
+ | --------- | ---------------------------------- |
816
+ | `List<a>` | A list containing all queue values |
817
+
818
+ Examples:
819
+
820
+ ```grain
821
+ let queue = Queue.Immutable.empty
822
+ let queue = Queue.Immutable.push(1, queue)
823
+ let queue = Queue.Immutable.push(2, queue)
824
+ assert Queue.Immutable.toList(queue) == [1, 2]
825
+ ```
826
+
827
+ ```grain
828
+ let queue = Queue.Immutable.fromList([1, 2, 3])
829
+ assert Queue.Immutable.toList(queue) == [1, 2, 3]
830
+ ```
831
+
832
+ ```grain
833
+ let queue = Queue.Immutable.empty
834
+ assert Queue.Immutable.toList(queue) == []
835
+ ```
588
836
 
589
837
  #### Queue.Immutable.**fromList**
590
838
 
@@ -594,20 +842,28 @@ No other changes yet.
594
842
  </details>
595
843
 
596
844
  ```grain
597
- fromList : (list: List<a>) => ImmutableQueue<a>
845
+ fromList: (list: List<a>) => ImmutableQueue<a>
598
846
  ```
599
847
 
600
848
  Creates a queue from a list.
601
849
 
602
850
  Parameters:
603
851
 
604
- |param|type|description|
605
- |-----|----|-----------|
606
- |`list`|`List<a>`|The list to convert|
852
+ | param | type | description |
853
+ | ------ | --------- | ------------------- |
854
+ | `list` | `List<a>` | The list to convert |
607
855
 
608
856
  Returns:
609
857
 
610
- |type|description|
611
- |----|-----------|
612
- |`ImmutableQueue<a>`|A queue containing all list values|
858
+ | type | description |
859
+ | ------------------- | ---------------------------------- |
860
+ | `ImmutableQueue<a>` | A queue containing all list values |
861
+
862
+ Examples:
863
+
864
+ ```grain
865
+ let queue = Queue.Immutable.fromList([1, 2, 3])
866
+ assert Queue.Immutable.peek(queue) == Some(1)
867
+ assert Queue.Immutable.size(queue) == 3
868
+ ```
613
869