@grain/stdlib 0.6.6 → 0.7.0
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.
- package/CHANGELOG.md +57 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +123 -77
- package/bigint.md +30 -30
- package/buffer.gr +20 -53
- package/buffer.md +47 -47
- package/bytes.gr +111 -35
- package/bytes.md +111 -32
- package/char.gr +201 -99
- package/char.md +361 -34
- package/exception.gr +11 -11
- package/exception.md +26 -1
- package/float32.gr +327 -3
- package/float32.md +606 -19
- package/float64.gr +320 -3
- package/float64.md +606 -19
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +102 -14
- package/int16.md +23 -23
- package/int32.gr +25 -4
- package/int32.md +65 -30
- package/int64.gr +26 -1
- package/int64.md +65 -30
- package/int8.md +23 -23
- package/json.gr +366 -51
- package/json.md +418 -2
- package/list.gr +328 -31
- package/list.md +492 -69
- package/map.gr +20 -12
- package/map.md +44 -38
- package/marshal.gr +41 -40
- package/marshal.md +2 -2
- package/number.gr +159 -30
- package/number.md +215 -38
- package/option.md +21 -21
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +103 -12
- package/pervasives.gr +2 -2
- package/pervasives.md +37 -37
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +19 -19
- package/queue.gr +183 -29
- package/queue.md +296 -40
- package/random.md +6 -6
- package/range.gr +4 -4
- package/range.md +6 -6
- package/rational.md +16 -16
- package/regex.gr +52 -51
- package/regex.md +11 -11
- package/result.md +16 -16
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +8 -8
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +1 -1
- package/runtime/dataStructures.md +33 -33
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +1 -1
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +4 -4
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +79 -73
- package/runtime/string.gr +37 -105
- package/runtime/string.md +3 -9
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +13 -13
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +138 -138
- package/set.gr +18 -11
- package/set.md +42 -36
- package/stack.gr +171 -2
- package/stack.md +297 -15
- package/string.gr +352 -557
- package/string.md +77 -34
- package/uint16.md +22 -22
- package/uint32.gr +25 -4
- package/uint32.md +63 -28
- package/uint64.gr +25 -5
- package/uint64.md +63 -28
- package/uint8.md +22 -22
- package/uri.gr +57 -53
- package/uri.md +11 -12
- package/wasi/file.gr +67 -59
- package/wasi/file.md +39 -39
- package/wasi/process.md +5 -5
- package/wasi/random.md +3 -3
- package/wasi/time.md +4 -4
- package/runtime/utils/printing.gr +0 -60
- 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,12 +49,12 @@ No other changes yet.
|
|
|
41
49
|
</details>
|
|
42
50
|
|
|
43
51
|
```grain
|
|
44
|
-
make
|
|
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
|
|
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:
|
|
@@ -61,6 +69,16 @@ Returns:
|
|
|
61
69
|
|----|-----------|
|
|
62
70
|
|`Queue<a>`|An empty queue|
|
|
63
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
|
+
```
|
|
81
|
+
|
|
64
82
|
### Queue.**isEmpty**
|
|
65
83
|
|
|
66
84
|
<details disabled>
|
|
@@ -69,7 +87,7 @@ No other changes yet.
|
|
|
69
87
|
</details>
|
|
70
88
|
|
|
71
89
|
```grain
|
|
72
|
-
isEmpty
|
|
90
|
+
isEmpty: (queue: Queue<a>) => Bool
|
|
73
91
|
```
|
|
74
92
|
|
|
75
93
|
Checks if the given queue contains no items.
|
|
@@ -86,6 +104,16 @@ Returns:
|
|
|
86
104
|
|----|-----------|
|
|
87
105
|
|`Bool`|`true` if the queue has no items or `false` otherwise|
|
|
88
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
|
+
```
|
|
116
|
+
|
|
89
117
|
### Queue.**size**
|
|
90
118
|
|
|
91
119
|
<details disabled>
|
|
@@ -94,7 +122,7 @@ No other changes yet.
|
|
|
94
122
|
</details>
|
|
95
123
|
|
|
96
124
|
```grain
|
|
97
|
-
size
|
|
125
|
+
size: (queue: Queue<a>) => Number
|
|
98
126
|
```
|
|
99
127
|
|
|
100
128
|
Computes the size of the input queue.
|
|
@@ -111,6 +139,16 @@ Returns:
|
|
|
111
139
|
|----|-----------|
|
|
112
140
|
|`Number`|The count of the items in the queue|
|
|
113
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
|
+
```
|
|
151
|
+
|
|
114
152
|
### Queue.**peek**
|
|
115
153
|
|
|
116
154
|
<details disabled>
|
|
@@ -119,7 +157,7 @@ No other changes yet.
|
|
|
119
157
|
</details>
|
|
120
158
|
|
|
121
159
|
```grain
|
|
122
|
-
peek
|
|
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.
|
|
@@ -136,6 +174,18 @@ Returns:
|
|
|
136
174
|
|----|-----------|
|
|
137
175
|
|`Option<a>`|`Some(value)` containing the value at the beginning of the queue or `None` otherwise.|
|
|
138
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
|
+
```
|
|
188
|
+
|
|
139
189
|
### Queue.**push**
|
|
140
190
|
|
|
141
191
|
<details disabled>
|
|
@@ -144,7 +194,7 @@ No other changes yet.
|
|
|
144
194
|
</details>
|
|
145
195
|
|
|
146
196
|
```grain
|
|
147
|
-
push
|
|
197
|
+
push: (value: a, queue: Queue<a>) => Void
|
|
148
198
|
```
|
|
149
199
|
|
|
150
200
|
Adds a new item to the end of the queue.
|
|
@@ -156,6 +206,15 @@ Parameters:
|
|
|
156
206
|
|`value`|`a`|The item to be added|
|
|
157
207
|
|`queue`|`Queue<a>`|The queue being updated|
|
|
158
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
|
+
```
|
|
217
|
+
|
|
159
218
|
### Queue.**pop**
|
|
160
219
|
|
|
161
220
|
<details disabled>
|
|
@@ -164,7 +223,7 @@ No other changes yet.
|
|
|
164
223
|
</details>
|
|
165
224
|
|
|
166
225
|
```grain
|
|
167
|
-
pop
|
|
226
|
+
pop: (queue: Queue<a>) => Option<a>
|
|
168
227
|
```
|
|
169
228
|
|
|
170
229
|
Removes the item at the beginning of the queue.
|
|
@@ -181,7 +240,16 @@ Returns:
|
|
|
181
240
|
|----|-----------|
|
|
182
241
|
|`Option<a>`|The element removed from the queue|
|
|
183
242
|
|
|
184
|
-
|
|
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
|
-
|
|
260
|
+
clear: (queue: Queue<a>) => Void
|
|
193
261
|
```
|
|
194
262
|
|
|
195
|
-
|
|
263
|
+
Clears the queue by removing all of its elements.
|
|
196
264
|
|
|
197
265
|
Parameters:
|
|
198
266
|
|
|
199
267
|
|param|type|description|
|
|
200
268
|
|-----|----|-----------|
|
|
201
|
-
|`queue`|`Queue<a>`|The queue to
|
|
269
|
+
|`queue`|`Queue<a>`|The queue to clear|
|
|
202
270
|
|
|
203
|
-
|
|
271
|
+
Examples:
|
|
204
272
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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.**
|
|
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
|
-
|
|
289
|
+
copy: (queue: Queue<a>) => Queue<a>
|
|
218
290
|
```
|
|
219
291
|
|
|
220
|
-
|
|
292
|
+
Produces a shallow copy of the input queue.
|
|
221
293
|
|
|
222
294
|
Parameters:
|
|
223
295
|
|
|
224
296
|
|param|type|description|
|
|
225
297
|
|-----|----|-----------|
|
|
226
|
-
|`
|
|
298
|
+
|`queue`|`Queue<a>`|The queue to copy|
|
|
227
299
|
|
|
228
300
|
Returns:
|
|
229
301
|
|
|
230
302
|
|type|description|
|
|
231
303
|
|----|-----------|
|
|
232
|
-
|`Queue<a>`|A queue containing
|
|
304
|
+
|`Queue<a>`|A new queue containing the elements from the input|
|
|
233
305
|
|
|
234
|
-
|
|
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
|
-
|
|
324
|
+
toList: (queue: Queue<a>) => List<a>
|
|
243
325
|
```
|
|
244
326
|
|
|
245
|
-
|
|
327
|
+
Converts a queue into a list of its elements.
|
|
246
328
|
|
|
247
329
|
Parameters:
|
|
248
330
|
|
|
249
331
|
|param|type|description|
|
|
250
332
|
|-----|----|-----------|
|
|
251
|
-
|`queue`|`Queue<a>`|The queue to
|
|
333
|
+
|`queue`|`Queue<a>`|The queue to convert|
|
|
252
334
|
|
|
253
|
-
|
|
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
|
-
|
|
359
|
+
fromList: (list: List<a>) => Queue<a>
|
|
262
360
|
```
|
|
263
361
|
|
|
264
|
-
|
|
362
|
+
Creates a queue from a list.
|
|
265
363
|
|
|
266
364
|
Parameters:
|
|
267
365
|
|
|
268
366
|
|param|type|description|
|
|
269
367
|
|-----|----|-----------|
|
|
270
|
-
|`
|
|
368
|
+
|`list`|`List<a>`|The list to convert|
|
|
271
369
|
|
|
272
370
|
Returns:
|
|
273
371
|
|
|
274
372
|
|type|description|
|
|
275
373
|
|----|-----------|
|
|
276
|
-
|`Queue<a>`|A
|
|
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,7 +389,7 @@ No other changes yet.
|
|
|
283
389
|
</details>
|
|
284
390
|
|
|
285
391
|
```grain
|
|
286
|
-
toArray
|
|
392
|
+
toArray: (queue: Queue<a>) => Array<a>
|
|
287
393
|
```
|
|
288
394
|
|
|
289
395
|
Converts a queue into an array of its values.
|
|
@@ -300,6 +406,16 @@ Returns:
|
|
|
300
406
|
|----|-----------|
|
|
301
407
|
|`Array<a>`|An array containing all values from the given queue|
|
|
302
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
|
+
```
|
|
418
|
+
|
|
303
419
|
### Queue.**fromArray**
|
|
304
420
|
|
|
305
421
|
<details disabled>
|
|
@@ -308,7 +424,7 @@ No other changes yet.
|
|
|
308
424
|
</details>
|
|
309
425
|
|
|
310
426
|
```grain
|
|
311
|
-
fromArray
|
|
427
|
+
fromArray: (arr: Array<a>) => Queue<a>
|
|
312
428
|
```
|
|
313
429
|
|
|
314
430
|
Creates a queue from an array.
|
|
@@ -325,6 +441,14 @@ Returns:
|
|
|
325
441
|
|----|-----------|
|
|
326
442
|
|`Queue<a>`|A queue containing all values from the array|
|
|
327
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
|
+
```
|
|
451
|
+
|
|
328
452
|
### Queue.**(==)**
|
|
329
453
|
|
|
330
454
|
<details disabled>
|
|
@@ -333,7 +457,7 @@ No other changes yet.
|
|
|
333
457
|
</details>
|
|
334
458
|
|
|
335
459
|
```grain
|
|
336
|
-
(==)
|
|
460
|
+
(==): (queue1: Queue<a>, queue2: Queue<a>) => Bool
|
|
337
461
|
```
|
|
338
462
|
|
|
339
463
|
Checks if two queues are equivalent by value.
|
|
@@ -351,16 +475,59 @@ Returns:
|
|
|
351
475
|
|----|-----------|
|
|
352
476
|
|`Bool`|`true` if the queues are equivalent or `false` otherwise|
|
|
353
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
|
+
```
|
|
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
|
|
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,7 +580,7 @@ An empty queue.
|
|
|
406
580
|
</details>
|
|
407
581
|
|
|
408
582
|
```grain
|
|
409
|
-
isEmpty
|
|
583
|
+
isEmpty: (queue: ImmutableQueue<a>) => Bool
|
|
410
584
|
```
|
|
411
585
|
|
|
412
586
|
Checks if the given queue contains any values.
|
|
@@ -423,6 +597,16 @@ Returns:
|
|
|
423
597
|
|----|-----------|
|
|
424
598
|
|`Bool`|`true` if the given queue is empty or `false` otherwise|
|
|
425
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
|
+
```
|
|
609
|
+
|
|
426
610
|
#### Queue.Immutable.**peek**
|
|
427
611
|
|
|
428
612
|
<details>
|
|
@@ -441,7 +625,7 @@ Returns:
|
|
|
441
625
|
</details>
|
|
442
626
|
|
|
443
627
|
```grain
|
|
444
|
-
peek
|
|
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.
|
|
@@ -458,6 +642,18 @@ Returns:
|
|
|
458
642
|
|----|-----------|
|
|
459
643
|
|`Option<a>`|`Some(value)` containing the value at the beginning of the queue, or `None` if the queue is empty|
|
|
460
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
|
+
```
|
|
656
|
+
|
|
461
657
|
#### Queue.Immutable.**push**
|
|
462
658
|
|
|
463
659
|
<details>
|
|
@@ -476,7 +672,7 @@ Returns:
|
|
|
476
672
|
</details>
|
|
477
673
|
|
|
478
674
|
```grain
|
|
479
|
-
push
|
|
675
|
+
push: (value: a, queue: ImmutableQueue<a>) => ImmutableQueue<a>
|
|
480
676
|
```
|
|
481
677
|
|
|
482
678
|
Adds a value to the end of the queue.
|
|
@@ -494,6 +690,15 @@ Returns:
|
|
|
494
690
|
|----|-----------|
|
|
495
691
|
|`ImmutableQueue<a>`|An updated queue|
|
|
496
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
|
+
```
|
|
701
|
+
|
|
497
702
|
#### Queue.Immutable.**pop**
|
|
498
703
|
|
|
499
704
|
<details>
|
|
@@ -512,7 +717,7 @@ Returns:
|
|
|
512
717
|
</details>
|
|
513
718
|
|
|
514
719
|
```grain
|
|
515
|
-
pop
|
|
720
|
+
pop: (queue: ImmutableQueue<a>) => ImmutableQueue<a>
|
|
516
721
|
```
|
|
517
722
|
|
|
518
723
|
Dequeues the next value in the queue.
|
|
@@ -529,6 +734,20 @@ Returns:
|
|
|
529
734
|
|----|-----------|
|
|
530
735
|
|`ImmutableQueue<a>`|An updated queue|
|
|
531
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
|
+
```
|
|
750
|
+
|
|
532
751
|
#### Queue.Immutable.**size**
|
|
533
752
|
|
|
534
753
|
<details>
|
|
@@ -544,7 +763,7 @@ Returns:
|
|
|
544
763
|
</details>
|
|
545
764
|
|
|
546
765
|
```grain
|
|
547
|
-
size
|
|
766
|
+
size: (queue: ImmutableQueue<a>) => Number
|
|
548
767
|
```
|
|
549
768
|
|
|
550
769
|
Get the number of values in a queue.
|
|
@@ -561,6 +780,16 @@ Returns:
|
|
|
561
780
|
|----|-----------|
|
|
562
781
|
|`Number`|The number of values in the queue|
|
|
563
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
|
+
```
|
|
792
|
+
|
|
564
793
|
#### Queue.Immutable.**toList**
|
|
565
794
|
|
|
566
795
|
<details disabled>
|
|
@@ -569,7 +798,7 @@ No other changes yet.
|
|
|
569
798
|
</details>
|
|
570
799
|
|
|
571
800
|
```grain
|
|
572
|
-
toList
|
|
801
|
+
toList: (queue: ImmutableQueue<a>) => List<a>
|
|
573
802
|
```
|
|
574
803
|
|
|
575
804
|
Converts a queue into a list of its elements.
|
|
@@ -586,6 +815,25 @@ Returns:
|
|
|
586
815
|
|----|-----------|
|
|
587
816
|
|`List<a>`|A list containing all queue values|
|
|
588
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
|
+
```
|
|
836
|
+
|
|
589
837
|
#### Queue.Immutable.**fromList**
|
|
590
838
|
|
|
591
839
|
<details disabled>
|
|
@@ -594,7 +842,7 @@ No other changes yet.
|
|
|
594
842
|
</details>
|
|
595
843
|
|
|
596
844
|
```grain
|
|
597
|
-
fromList
|
|
845
|
+
fromList: (list: List<a>) => ImmutableQueue<a>
|
|
598
846
|
```
|
|
599
847
|
|
|
600
848
|
Creates a queue from a list.
|
|
@@ -611,3 +859,11 @@ Returns:
|
|
|
611
859
|
|----|-----------|
|
|
612
860
|
|`ImmutableQueue<a>`|A queue containing all list values|
|
|
613
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
|
+
```
|
|
869
|
+
|
package/random.md
CHANGED
|
@@ -35,7 +35,7 @@ No other changes yet.
|
|
|
35
35
|
</details>
|
|
36
36
|
|
|
37
37
|
```grain
|
|
38
|
-
make
|
|
38
|
+
make: (seed: Uint64) => Random
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Creates a new pseudo-random number generator with the given seed.
|
|
@@ -60,7 +60,7 @@ No other changes yet.
|
|
|
60
60
|
</details>
|
|
61
61
|
|
|
62
62
|
```grain
|
|
63
|
-
makeUnseeded
|
|
63
|
+
makeUnseeded: () => Result<Random, Exception>
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
Creates a new pseudo-random number generator with a random seed.
|
|
@@ -86,7 +86,7 @@ Returns:
|
|
|
86
86
|
</details>
|
|
87
87
|
|
|
88
88
|
```grain
|
|
89
|
-
nextUint32
|
|
89
|
+
nextUint32: (random: Random) => Uint32
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
Generates a random 32-bit integer from the given pseudo-random number generator.
|
|
@@ -118,7 +118,7 @@ Returns:
|
|
|
118
118
|
</details>
|
|
119
119
|
|
|
120
120
|
```grain
|
|
121
|
-
nextUint64
|
|
121
|
+
nextUint64: (random: Random) => Uint64
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
Generates a random 64-bit integer from the given pseudo-random number generator.
|
|
@@ -150,7 +150,7 @@ Returns:
|
|
|
150
150
|
</details>
|
|
151
151
|
|
|
152
152
|
```grain
|
|
153
|
-
nextUint32InRange
|
|
153
|
+
nextUint32InRange: (random: Random, low: Uint32, high: Uint32) => Uint32
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
Generates a random 32-bit integer from the given pseudo-random number generator
|
|
@@ -185,7 +185,7 @@ Returns:
|
|
|
185
185
|
</details>
|
|
186
186
|
|
|
187
187
|
```grain
|
|
188
|
-
nextUint64InRange
|
|
188
|
+
nextUint64InRange: (random: Random, low: Uint64, high: Uint64) => Uint64
|
|
189
189
|
```
|
|
190
190
|
|
|
191
191
|
Generates a random 64-bit integer from the given pseudo-random number generator
|
package/range.gr
CHANGED
|
@@ -123,10 +123,10 @@ provide module Inclusive {
|
|
|
123
123
|
*/
|
|
124
124
|
provide let inRange = (value, range) => {
|
|
125
125
|
match (range) {
|
|
126
|
-
{ rangeStart: lower, rangeEnd: upper } when value >= lower
|
|
127
|
-
value <= upper => true,
|
|
128
|
-
{ rangeStart: upper, rangeEnd: lower } when value >= lower
|
|
129
|
-
value <= upper => true,
|
|
126
|
+
{ rangeStart: lower, rangeEnd: upper } when value >= lower
|
|
127
|
+
&& value <= upper => true,
|
|
128
|
+
{ rangeStart: upper, rangeEnd: lower } when value >= lower
|
|
129
|
+
&& value <= upper => true,
|
|
130
130
|
_ => false,
|
|
131
131
|
}
|
|
132
132
|
}
|