@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.
Files changed (137) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/array.gr +55 -7
  5. package/array.md +123 -77
  6. package/bigint.md +30 -30
  7. package/buffer.gr +20 -53
  8. package/buffer.md +47 -47
  9. package/bytes.gr +111 -35
  10. package/bytes.md +111 -32
  11. package/char.gr +201 -99
  12. package/char.md +361 -34
  13. package/exception.gr +11 -11
  14. package/exception.md +26 -1
  15. package/float32.gr +327 -3
  16. package/float32.md +606 -19
  17. package/float64.gr +320 -3
  18. package/float64.md +606 -19
  19. package/fs.gr +1082 -0
  20. package/fs.md +630 -0
  21. package/hash.gr +142 -88
  22. package/hash.md +102 -14
  23. package/int16.md +23 -23
  24. package/int32.gr +25 -4
  25. package/int32.md +65 -30
  26. package/int64.gr +26 -1
  27. package/int64.md +65 -30
  28. package/int8.md +23 -23
  29. package/json.gr +366 -51
  30. package/json.md +418 -2
  31. package/list.gr +328 -31
  32. package/list.md +492 -69
  33. package/map.gr +20 -12
  34. package/map.md +44 -38
  35. package/marshal.gr +41 -40
  36. package/marshal.md +2 -2
  37. package/number.gr +159 -30
  38. package/number.md +215 -38
  39. package/option.md +21 -21
  40. package/package.json +5 -3
  41. package/path.gr +48 -0
  42. package/path.md +103 -12
  43. package/pervasives.gr +2 -2
  44. package/pervasives.md +37 -37
  45. package/priorityqueue.gr +7 -7
  46. package/priorityqueue.md +19 -19
  47. package/queue.gr +183 -29
  48. package/queue.md +296 -40
  49. package/random.md +6 -6
  50. package/range.gr +4 -4
  51. package/range.md +6 -6
  52. package/rational.md +16 -16
  53. package/regex.gr +52 -51
  54. package/regex.md +11 -11
  55. package/result.md +16 -16
  56. package/runtime/atof/common.md +39 -39
  57. package/runtime/atof/decimal.gr +6 -6
  58. package/runtime/atof/decimal.md +8 -8
  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 +1 -1
  71. package/runtime/dataStructures.md +33 -33
  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 +1 -1
  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 +4 -4
  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 +79 -73
  98. package/runtime/string.gr +37 -105
  99. package/runtime/string.md +3 -9
  100. package/runtime/unsafe/constants.md +24 -24
  101. package/runtime/unsafe/conv.md +13 -13
  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 +138 -138
  117. package/set.gr +18 -11
  118. package/set.md +42 -36
  119. package/stack.gr +171 -2
  120. package/stack.md +297 -15
  121. package/string.gr +352 -557
  122. package/string.md +77 -34
  123. package/uint16.md +22 -22
  124. package/uint32.gr +25 -4
  125. package/uint32.md +63 -28
  126. package/uint64.gr +25 -5
  127. package/uint64.md +63 -28
  128. package/uint8.md +22 -22
  129. package/uri.gr +57 -53
  130. package/uri.md +11 -12
  131. package/wasi/file.gr +67 -59
  132. package/wasi/file.md +39 -39
  133. package/wasi/process.md +5 -5
  134. package/wasi/random.md +3 -3
  135. package/wasi/time.md +4 -4
  136. package/runtime/utils/printing.gr +0 -60
  137. package/runtime/utils/printing.md +0 -26
package/priorityqueue.md CHANGED
@@ -46,7 +46,7 @@ Functions and constants included in the PriorityQueue module.
46
46
  </details>
47
47
 
48
48
  ```grain
49
- make : (?compare: ((a, a) => Number), ?size: Number) => PriorityQueue<a>
49
+ make: (?compare: ((a, a) => Number), ?size: Number) => PriorityQueue<a>
50
50
  ```
51
51
 
52
52
  Creates a new priority queue with a given internal storage size and a
@@ -93,7 +93,7 @@ No other changes yet.
93
93
  </details>
94
94
 
95
95
  ```grain
96
- size : (pq: PriorityQueue<a>) => Number
96
+ size: (pq: PriorityQueue<a>) => Number
97
97
  ```
98
98
 
99
99
  Gets the number of elements in a priority queue.
@@ -118,7 +118,7 @@ No other changes yet.
118
118
  </details>
119
119
 
120
120
  ```grain
121
- isEmpty : (pq: PriorityQueue<a>) => Bool
121
+ isEmpty: (pq: PriorityQueue<a>) => Bool
122
122
  ```
123
123
 
124
124
  Determines if the priority queue contains no elements.
@@ -143,7 +143,7 @@ No other changes yet.
143
143
  </details>
144
144
 
145
145
  ```grain
146
- push : (val: a, pq: PriorityQueue<a>) => Void
146
+ push: (val: a, pq: PriorityQueue<a>) => Void
147
147
  ```
148
148
 
149
149
  Adds a new element to the priority queue.
@@ -163,7 +163,7 @@ No other changes yet.
163
163
  </details>
164
164
 
165
165
  ```grain
166
- peek : (pq: PriorityQueue<a>) => Option<a>
166
+ peek: (pq: PriorityQueue<a>) => Option<a>
167
167
  ```
168
168
 
169
169
  Retrieves the highest priority element in the priority queue. It is not
@@ -189,7 +189,7 @@ No other changes yet.
189
189
  </details>
190
190
 
191
191
  ```grain
192
- pop : (pq: PriorityQueue<a>) => Option<a>
192
+ pop: (pq: PriorityQueue<a>) => Option<a>
193
193
  ```
194
194
 
195
195
  Removes and retrieves the highest priority element in the priority queue.
@@ -214,7 +214,7 @@ No other changes yet.
214
214
  </details>
215
215
 
216
216
  ```grain
217
- drain : (pq: PriorityQueue<a>) => List<a>
217
+ drain: (pq: PriorityQueue<a>) => List<a>
218
218
  ```
219
219
 
220
220
  Clears the priority queue and produces a list of all of the elements in the priority
@@ -247,7 +247,7 @@ Returns:
247
247
  </details>
248
248
 
249
249
  ```grain
250
- fromArray :
250
+ fromArray:
251
251
  (array: Array<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
252
252
  ```
253
253
 
@@ -285,7 +285,7 @@ Returns:
285
285
  </details>
286
286
 
287
287
  ```grain
288
- fromList : (list: List<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
288
+ fromList: (list: List<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
289
289
  ```
290
290
 
291
291
  Constructs a new priority queue initialized with the elements in the list
@@ -354,7 +354,7 @@ Functions and constants included in the PriorityQueue.Immutable module.
354
354
  </details>
355
355
 
356
356
  ```grain
357
- empty : PriorityQueue<a>
357
+ empty: PriorityQueue<a>
358
358
  ```
359
359
 
360
360
  An empty priority queue with the default `compare` comparator.
@@ -374,7 +374,7 @@ An empty priority queue with the default `compare` comparator.
374
374
  </details>
375
375
 
376
376
  ```grain
377
- make : (?compare: ((a, a) => Number)) => PriorityQueue<a>
377
+ make: (?compare: ((a, a) => Number)) => PriorityQueue<a>
378
378
  ```
379
379
 
380
380
  Creates a new priority queue with a comparator function, which is used to
@@ -419,7 +419,7 @@ PriorityQueue.Immutable.make((a, b) => String.length(b) - String.length(a)) // c
419
419
  </details>
420
420
 
421
421
  ```grain
422
- size : (pq: PriorityQueue<a>) => Number
422
+ size: (pq: PriorityQueue<a>) => Number
423
423
  ```
424
424
 
425
425
  Gets the number of elements in a priority queue.
@@ -451,7 +451,7 @@ Returns:
451
451
  </details>
452
452
 
453
453
  ```grain
454
- isEmpty : (pq: PriorityQueue<a>) => Bool
454
+ isEmpty: (pq: PriorityQueue<a>) => Bool
455
455
  ```
456
456
 
457
457
  Determines if the priority queue contains no elements.
@@ -483,7 +483,7 @@ Returns:
483
483
  </details>
484
484
 
485
485
  ```grain
486
- push : (val: a, pq: PriorityQueue<a>) => PriorityQueue<a>
486
+ push: (val: a, pq: PriorityQueue<a>) => PriorityQueue<a>
487
487
  ```
488
488
 
489
489
  Produces a new priority queue by inserting the given element into the given priority queue.
@@ -516,7 +516,7 @@ Returns:
516
516
  </details>
517
517
 
518
518
  ```grain
519
- peek : (pq: PriorityQueue<a>) => Option<a>
519
+ peek: (pq: PriorityQueue<a>) => Option<a>
520
520
  ```
521
521
 
522
522
  Retrieves the highest priority element in the priority queue. It is not
@@ -549,7 +549,7 @@ Returns:
549
549
  </details>
550
550
 
551
551
  ```grain
552
- pop : (pq: PriorityQueue<a>) => PriorityQueue<a>
552
+ pop: (pq: PriorityQueue<a>) => PriorityQueue<a>
553
553
  ```
554
554
 
555
555
  Produces a new priority queue without the highest priority element in the
@@ -583,7 +583,7 @@ Returns:
583
583
  </details>
584
584
 
585
585
  ```grain
586
- drain : (pq: PriorityQueue<a>) => List<a>
586
+ drain: (pq: PriorityQueue<a>) => List<a>
587
587
  ```
588
588
 
589
589
  Produces a list of all elements in the priority queue in priority order.
@@ -615,7 +615,7 @@ Returns:
615
615
  </details>
616
616
 
617
617
  ```grain
618
- fromList : (list: List<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
618
+ fromList: (list: List<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
619
619
  ```
620
620
 
621
621
  Constructs a new priority queue initialized with the elements in the list
@@ -652,7 +652,7 @@ Returns:
652
652
  </details>
653
653
 
654
654
  ```grain
655
- fromArray :
655
+ fromArray:
656
656
  (array: Array<a>, ?compare: ((a, a) => Number)) => PriorityQueue<a>
657
657
  ```
658
658
 
package/queue.gr CHANGED
@@ -7,6 +7,13 @@
7
7
  *
8
8
  * @example from "queue" include Queue
9
9
  *
10
+ * @example
11
+ * let queue = Queue.fromList([0, 1])
12
+ * Queue.push(2, queue)
13
+ * assert Queue.pop(queue) == Some(0)
14
+ * assert Queue.pop(queue) == Some(1)
15
+ * assert Queue.pop(queue) == Some(2)
16
+ *
10
17
  * @since v0.2.0
11
18
  */
12
19
  module Queue
@@ -27,12 +34,15 @@ abstract record Queue<a> {
27
34
  /**
28
35
  * Creates a new queue with an initial storage of the given size. As values are
29
36
  * added or removed, the internal storage may grow or shrink. Generally, you
30
- * won’t need to care about the storage size of your map and can use the
37
+ * won’t need to care about the storage size of your queue and can use the
31
38
  * default size.
32
39
  *
33
40
  * @param size: The initial storage size of the queue
34
41
  * @returns An empty queue
35
42
  *
43
+ * @example Queue.make() // Creates a new queue
44
+ * @example Queue.make(size=16) // Creates a new queue with an initial size of 16
45
+ *
36
46
  * @since v0.6.0
37
47
  */
38
48
  provide let make = (size=16) => {
@@ -45,6 +55,9 @@ provide let make = (size=16) => {
45
55
  * @param queue: The queue to check
46
56
  * @returns `true` if the queue has no items or `false` otherwise
47
57
  *
58
+ * @example Queue.isEmpty(Queue.make()) == true
59
+ * @example Queue.isEmpty(Queue.fromList([1, 2])) == false
60
+ *
48
61
  * @since v0.6.0
49
62
  */
50
63
  provide let isEmpty = queue => queue.size == 0
@@ -55,6 +68,9 @@ provide let isEmpty = queue => queue.size == 0
55
68
  * @param queue: The queue to inspect
56
69
  * @returns The count of the items in the queue
57
70
  *
71
+ * @example Queue.size(Queue.make()) == 0
72
+ * @example Queue.size(Queue.fromList([1, 2])) == 2
73
+ *
58
74
  * @since v0.6.0
59
75
  */
60
76
  provide let size = queue => queue.size
@@ -65,6 +81,12 @@ provide let size = queue => queue.size
65
81
  * @param queue: The queue to inspect
66
82
  * @returns `Some(value)` containing the value at the beginning of the queue or `None` otherwise.
67
83
  *
84
+ * @example Queue.peek(Queue.make()) == None
85
+ * @example
86
+ * let queue = Queue.make()
87
+ * Queue.push(1, queue)
88
+ * assert Queue.peek(queue) == Some(1)
89
+ *
68
90
  * @since v0.6.0
69
91
  */
70
92
  provide let peek = queue => {
@@ -77,6 +99,12 @@ provide let peek = queue => {
77
99
  * @param value: The item to be added
78
100
  * @param queue: The queue being updated
79
101
  *
102
+ * @example
103
+ * let queue = Queue.make()
104
+ * assert Queue.peek(queue) == None
105
+ * Queue.push(1, queue)
106
+ * assert Queue.peek(queue) == Some(1)
107
+ *
80
108
  * @since v0.6.0
81
109
  */
82
110
  provide let push = (value, queue) => {
@@ -111,6 +139,12 @@ provide let push = (value, queue) => {
111
139
  * @param queue: The queue being updated
112
140
  * @returns The element removed from the queue
113
141
  *
142
+ * @example
143
+ * let queue = Queue.make()
144
+ * Queue.push(1, queue)
145
+ * assert Queue.pop(queue) == Some(1)
146
+ * assert Queue.pop(queue) == None
147
+ *
114
148
  * @since v0.6.0
115
149
  */
116
150
  provide let pop = queue => {
@@ -125,12 +159,60 @@ provide let pop = queue => {
125
159
  }
126
160
  }
127
161
 
162
+ /**
163
+ * Clears the queue by removing all of its elements.
164
+ *
165
+ * @param queue: The queue to clear
166
+ *
167
+ * @example
168
+ * let queue = Queue.make()
169
+ * Queue.push(1, queue)
170
+ * assert Queue.size(queue) == 1
171
+ * Queue.clear(queue)
172
+ * assert Queue.size(queue) == 0
173
+ *
174
+ * @since v0.6.0
175
+ */
176
+ provide let clear = queue => {
177
+ queue.size = 0
178
+ Array.fill(None, queue.array)
179
+ queue.headIndex = 0
180
+ queue.tailIndex = 0
181
+ }
182
+
183
+ /**
184
+ * Produces a shallow copy of the input queue.
185
+ *
186
+ * @param queue: The queue to copy
187
+ * @returns A new queue containing the elements from the input
188
+ *
189
+ * @example
190
+ * let queue = Queue.make()
191
+ * Queue.push(1, queue)
192
+ * let copiedQueue = Queue.copy(queue)
193
+ * Queue.push(2, queue) // Does not affect copiedQueue
194
+ * assert Queue.pop(copiedQueue) == Some(1)
195
+ *
196
+ * @since v0.6.0
197
+ */
198
+ provide let copy = queue => {
199
+ let { size, array, headIndex, tailIndex } = queue
200
+ { size, array: Array.copy(array), headIndex, tailIndex }
201
+ }
202
+
128
203
  /**
129
204
  * Converts a queue into a list of its elements.
130
205
  *
131
206
  * @param queue: The queue to convert
132
207
  * @returns A list containing all queue values
133
208
  *
209
+ * @example
210
+ * let queue = Queue.make()
211
+ * Queue.push(0, queue)
212
+ * Queue.push(1, queue)
213
+ * Queue.push(2, queue)
214
+ * assert Queue.toList(queue) == [0, 1, 2]
215
+ *
134
216
  * @since v0.6.0
135
217
  */
136
218
  provide let toList = queue => {
@@ -152,6 +234,11 @@ provide let toList = queue => {
152
234
  * @param list: The list to convert
153
235
  * @returns A queue containing all list values
154
236
  *
237
+ * @example
238
+ * let queue = Queue.fromList([0, 1])
239
+ * assert Queue.pop(queue) == Some(0)
240
+ * assert Queue.pop(queue) == Some(1)
241
+ *
155
242
  * @since v0.6.0
156
243
  */
157
244
  provide let fromList = list => {
@@ -160,39 +247,19 @@ provide let fromList = list => {
160
247
  queue
161
248
  }
162
249
 
163
- /**
164
- * Clears the queue by removing all of its elements
165
- *
166
- * @param queue: The queue to clear
167
- *
168
- * @since v0.6.0
169
- */
170
- provide let clear = queue => {
171
- queue.size = 0
172
- Array.fill(None, queue.array)
173
- queue.headIndex = 0
174
- queue.tailIndex = 0
175
- }
176
-
177
- /**
178
- * Produces a shallow copy of the input queue.
179
- *
180
- * @param queue: The queue to copy
181
- * @returns A new queue containing the elements from the input
182
- *
183
- * @since v0.6.0
184
- */
185
- provide let copy = queue => {
186
- let { size, array, headIndex, tailIndex } = queue
187
- { size, array: Array.copy(array), headIndex, tailIndex }
188
- }
189
-
190
250
  /**
191
251
  * Converts a queue into an array of its values.
192
252
  *
193
253
  * @param queue: The queue to convert
194
254
  * @returns An array containing all values from the given queue
195
255
  *
256
+ * @example
257
+ * let queue = Queue.make()
258
+ * Queue.push(0, queue)
259
+ * Queue.push(1, queue)
260
+ * Queue.push(2, queue)
261
+ * assert Queue.toArray(queue) == [> 0, 1, 2]
262
+ *
196
263
  * @since v0.6.0
197
264
  */
198
265
  provide let toArray = queue => {
@@ -230,6 +297,11 @@ provide let toArray = queue => {
230
297
  * @param arr: The array to convert
231
298
  * @returns A queue containing all values from the array
232
299
  *
300
+ * @example
301
+ * let queue = Queue.fromArray([> 0, 1])
302
+ * assert Queue.pop(queue) == Some(0)
303
+ * assert Queue.pop(queue) == Some(1)
304
+ *
233
305
  * @since v0.6.0
234
306
  */
235
307
  provide let fromArray = arr => {
@@ -255,6 +327,18 @@ provide let fromArray = arr => {
255
327
  * @param queue2: The second queue to compare
256
328
  * @returns `true` if the queues are equivalent or `false` otherwise
257
329
  *
330
+ * @example
331
+ * use Queue.{ (==) }
332
+ * let queue1 = Queue.fromList([0, 1, 2])
333
+ * let queue2 = Queue.fromList([0, 1, 2])
334
+ * assert queue1 == queue2
335
+ *
336
+ * @example
337
+ * use Queue.{ (==) }
338
+ * let queue1 = Queue.fromList([0, 1, 2])
339
+ * let queue2 = Queue.fromList([0, 1, 3])
340
+ * assert !(queue1 == queue2)
341
+ *
258
342
  * @since v0.6.0
259
343
  */
260
344
  provide let (==) = (queue1, queue2) => {
@@ -276,10 +360,24 @@ provide let (==) = (queue1, queue2) => {
276
360
 
277
361
  /**
278
362
  * An immutable queue implementation.
363
+ *
364
+ * @example
365
+ * let queue = Immutable.Queue.fromList([0, 1])
366
+ * let queue = Immutable.Queue.push(2, queue)
367
+ * assert Immutable.Queue.peek(queue) == Some(0)
368
+ * let queue = Immutable.Queue.pop(queue)
369
+ * assert Immutable.Queue.peek(queue) == Some(1)
370
+ * ignore(Queue.Immutable.pop(queue)) // Does not affect the original queue
371
+ * assert Immutable.Queue.peek(queue) == Some(1)
372
+ *
373
+ * @since v0.6.0
279
374
  */
280
375
  provide module Immutable {
281
376
  /**
282
377
  * An immutable FIFO (first-in-first-out) data structure.
378
+ *
379
+ * @since v0.6.0
380
+ * @history v0.5.4: Originally a module root API
283
381
  */
284
382
  abstract record ImmutableQueue<a> {
285
383
  forwards: List<a>,
@@ -289,6 +387,10 @@ provide module Immutable {
289
387
  /**
290
388
  * An empty queue.
291
389
  *
390
+ * @example
391
+ * let queue = Queue.Immutable.empty
392
+ * assert Queue.Immutable.isEmpty(queue)
393
+ *
292
394
  * @since v0.6.0
293
395
  * @history v0.5.4: Originally a module root API
294
396
  */
@@ -303,6 +405,10 @@ provide module Immutable {
303
405
  * @param queue: The queue to check
304
406
  * @returns `true` if the given queue is empty or `false` otherwise
305
407
  *
408
+ * @example Queue.Immutable.isEmpty(Queue.Immutable.empty) == true
409
+ *
410
+ * @example Queue.Immutable.isEmpty(Queue.Immutable.fromList([1, 2])) == false
411
+ *
306
412
  * @since v0.6.0
307
413
  * @history v0.2.0: Originally a module root API
308
414
  */
@@ -319,6 +425,14 @@ provide module Immutable {
319
425
  * @param queue: The queue to inspect
320
426
  * @returns `Some(value)` containing the value at the beginning of the queue, or `None` if the queue is empty
321
427
  *
428
+ * @example
429
+ * let queue = Queue.Immutable.fromList([1, 2, 3])
430
+ * assert Queue.Immutable.peek(queue) == Some(1)
431
+ *
432
+ * @example
433
+ * let queue = Queue.Immutable.empty
434
+ * assert Queue.Immutable.peek(queue) == None
435
+ *
322
436
  * @since v0.6.0
323
437
  * @history v0.2.0: Originally named `head`
324
438
  * @history v0.3.2: Deprecated `head` function
@@ -339,6 +453,12 @@ provide module Immutable {
339
453
  * @param queue: The queue to update
340
454
  * @returns An updated queue
341
455
  *
456
+ * @example
457
+ * let queue = Queue.Immutable.fromList([1])
458
+ * assert Queue.Immutable.size(queue) == 1
459
+ * let queue = Queue.Immutable.push(2, queue)
460
+ * assert Queue.Immutable.size(queue) == 2
461
+ *
342
462
  * @since v0.6.0
343
463
  * @history v0.2.0: Originally named `enqueue`
344
464
  * @history v0.3.2: Deprecated `enqueue` function
@@ -358,13 +478,23 @@ provide module Immutable {
358
478
  * @param queue: The queue to change
359
479
  * @returns An updated queue
360
480
  *
481
+ * @example
482
+ * let queue = Queue.Immutable.fromList([1, 2, 3])
483
+ * let queue = Queue.Immutable.pop(queue)
484
+ * assert Queue.Immutable.peek(queue) == Some(2)
485
+ *
486
+ * @example
487
+ * let queue = Queue.Immutable.empty
488
+ * let queue = Queue.Immutable.pop(queue)
489
+ * assert Queue.Immutable.isEmpty(queue)
490
+ *
361
491
  * @since v0.6.0
362
492
  * @history v0.2.0: Originally named `dequeue`
363
493
  * @history v0.3.2: Deprecated `dequeue` function
364
494
  * @history v0.3.2: Originally a module root API
365
495
  * @history v0.4.0: Removed `dequeue` function
366
496
  */
367
- provide let pop = queue => {
497
+ provide let rec pop = queue => {
368
498
  match (queue) {
369
499
  { forwards: [], backwards: [] } => queue,
370
500
  { forwards: [head], backwards: [] } => { forwards: [], backwards: [] },
@@ -372,6 +502,8 @@ provide module Immutable {
372
502
  { forwards: List.reverse(backwards), backwards: [] },
373
503
  { forwards: [head, ...ftail], backwards } =>
374
504
  { forwards: ftail, backwards },
505
+ { forwards: [], backwards } =>
506
+ pop({ forwards: List.reverse(backwards), backwards: [] }),
375
507
  }
376
508
  }
377
509
 
@@ -381,6 +513,9 @@ provide module Immutable {
381
513
  * @param queue: The queue to inspect
382
514
  * @returns The number of values in the queue
383
515
  *
516
+ * @example Queue.Immutable.size(Queue.Immutable.empty) == 0
517
+ * @example Queue.Immutable.size(Queue.Immutable.fromList([1, 2])) == 2
518
+ *
384
519
  * @since v0.6.0
385
520
  * @history v0.3.2: Originally a module root API
386
521
  */
@@ -399,6 +534,20 @@ provide module Immutable {
399
534
  * @param queue: The queue to convert
400
535
  * @returns A list containing all queue values
401
536
  *
537
+ * @example
538
+ * let queue = Queue.Immutable.empty
539
+ * let queue = Queue.Immutable.push(1, queue)
540
+ * let queue = Queue.Immutable.push(2, queue)
541
+ * assert Queue.Immutable.toList(queue) == [1, 2]
542
+ *
543
+ * @example
544
+ * let queue = Queue.Immutable.fromList([1, 2, 3])
545
+ * assert Queue.Immutable.toList(queue) == [1, 2, 3]
546
+ *
547
+ * @example
548
+ * let queue = Queue.Immutable.empty
549
+ * assert Queue.Immutable.toList(queue) == []
550
+ *
402
551
  * @since v0.6.0
403
552
  */
404
553
  provide let toList = queue => {
@@ -411,6 +560,11 @@ provide module Immutable {
411
560
  * @param list: The list to convert
412
561
  * @returns A queue containing all list values
413
562
  *
563
+ * @example
564
+ * let queue = Queue.Immutable.fromList([1, 2, 3])
565
+ * assert Queue.Immutable.peek(queue) == Some(1)
566
+ * assert Queue.Immutable.size(queue) == 3
567
+ *
414
568
  * @since v0.6.0
415
569
  */
416
570
  provide let fromList = list => {