@grain/stdlib 0.5.3 → 0.5.5

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 (77) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/array.gr +65 -57
  3. package/array.md +54 -6
  4. package/buffer.gr +71 -1
  5. package/buffer.md +142 -0
  6. package/bytes.gr +52 -3
  7. package/bytes.md +117 -0
  8. package/char.gr +23 -20
  9. package/char.md +18 -3
  10. package/immutablemap.gr +493 -0
  11. package/immutablemap.md +479 -0
  12. package/immutablepriorityqueue.gr +44 -16
  13. package/immutablepriorityqueue.md +44 -1
  14. package/immutableset.gr +498 -0
  15. package/immutableset.md +449 -0
  16. package/int32.gr +39 -37
  17. package/int32.md +6 -0
  18. package/int64.gr +39 -37
  19. package/int64.md +6 -0
  20. package/list.gr +33 -24
  21. package/list.md +39 -10
  22. package/map.gr +19 -28
  23. package/marshal.gr +4 -4
  24. package/number.gr +727 -26
  25. package/number.md +345 -23
  26. package/option.gr +30 -26
  27. package/option.md +12 -0
  28. package/package.json +1 -1
  29. package/path.gr +787 -0
  30. package/path.md +727 -0
  31. package/pervasives.gr +3 -4
  32. package/pervasives.md +6 -1
  33. package/priorityqueue.gr +25 -5
  34. package/priorityqueue.md +30 -0
  35. package/queue.gr +22 -7
  36. package/queue.md +18 -1
  37. package/regex.gr +161 -65
  38. package/regex.md +70 -0
  39. package/result.gr +24 -20
  40. package/result.md +12 -0
  41. package/runtime/atof/common.gr +198 -0
  42. package/runtime/atof/common.md +243 -0
  43. package/runtime/atof/decimal.gr +663 -0
  44. package/runtime/atof/decimal.md +59 -0
  45. package/runtime/atof/lemire.gr +264 -0
  46. package/runtime/atof/lemire.md +6 -0
  47. package/runtime/atof/parse.gr +615 -0
  48. package/runtime/atof/parse.md +12 -0
  49. package/runtime/atof/slow.gr +238 -0
  50. package/runtime/atof/slow.md +6 -0
  51. package/runtime/atof/table.gr +2016 -0
  52. package/runtime/atof/table.md +12 -0
  53. package/runtime/{stringUtils.gr → atoi/parse.gr} +1 -1
  54. package/runtime/{stringUtils.md → atoi/parse.md} +1 -1
  55. package/runtime/bigint.gr +7 -7
  56. package/runtime/compare.gr +2 -1
  57. package/runtime/equal.gr +3 -2
  58. package/runtime/exception.gr +9 -5
  59. package/runtime/exception.md +8 -2
  60. package/runtime/gc.gr +2 -1
  61. package/runtime/malloc.gr +1 -3
  62. package/runtime/numberUtils.gr +13 -13
  63. package/runtime/numberUtils.md +6 -0
  64. package/runtime/numbers.gr +123 -39
  65. package/runtime/numbers.md +26 -0
  66. package/runtime/string.gr +4 -2
  67. package/runtime/unsafe/conv.gr +21 -41
  68. package/runtime/unsafe/conv.md +0 -3
  69. package/runtime/unsafe/printWasm.gr +4 -40
  70. package/runtime/utils/printing.gr +3 -3
  71. package/set.gr +25 -25
  72. package/stack.gr +14 -0
  73. package/stack.md +17 -0
  74. package/string.gr +313 -39
  75. package/string.md +99 -0
  76. package/sys/file.gr +1 -1
  77. package/sys/time.gr +4 -4
@@ -0,0 +1,479 @@
1
+ ---
2
+ title: ImmutableMap
3
+ ---
4
+
5
+ An ImmutableMap holds key-value pairs. Any value may be used as a key or value. Operations on an ImmutableMap do not mutate the map's internal state.
6
+
7
+ <details disabled>
8
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
9
+ No other changes yet.
10
+ </details>
11
+
12
+ ```grain
13
+ import ImmutableMap from "immutablemap"
14
+ ```
15
+
16
+ ## Types
17
+
18
+ Type declarations included in the ImmutableMap module.
19
+
20
+ ### ImmutableMap.**ImmutableMap**
21
+
22
+ ```grain
23
+ type ImmutableMap<k, v>
24
+ ```
25
+
26
+ ## Values
27
+
28
+ Functions and constants for working with ImmutableMaps.
29
+
30
+ ### ImmutableMap.**empty**
31
+
32
+ <details disabled>
33
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
34
+ No other changes yet.
35
+ </details>
36
+
37
+ ```grain
38
+ empty : ImmutableMap<a, b>
39
+ ```
40
+
41
+ An empty map
42
+
43
+ ### ImmutableMap.**size**
44
+
45
+ <details disabled>
46
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
47
+ No other changes yet.
48
+ </details>
49
+
50
+ ```grain
51
+ size : ImmutableMap<a, b> -> Number
52
+ ```
53
+
54
+ Provides the count of key-value pairs stored within the map.
55
+
56
+ Parameters:
57
+
58
+ |param|type|description|
59
+ |-----|----|-----------|
60
+ |`map`|`ImmutableMap<a, b>`|The map to inspect|
61
+
62
+ Returns:
63
+
64
+ |type|description|
65
+ |----|-----------|
66
+ |`Number`|The count of key-value pairs in the map|
67
+
68
+ ### ImmutableMap.**isEmpty**
69
+
70
+ <details disabled>
71
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
72
+ No other changes yet.
73
+ </details>
74
+
75
+ ```grain
76
+ isEmpty : ImmutableMap<a, b> -> Bool
77
+ ```
78
+
79
+ Determines if the map contains no key-value pairs.
80
+
81
+ Parameters:
82
+
83
+ |param|type|description|
84
+ |-----|----|-----------|
85
+ |`map`|`ImmutableMap<a, b>`|The map to inspect|
86
+
87
+ Returns:
88
+
89
+ |type|description|
90
+ |----|-----------|
91
+ |`Bool`|`true` if the given map is empty or `false` otherwise|
92
+
93
+ ### ImmutableMap.**set**
94
+
95
+ <details disabled>
96
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
97
+ No other changes yet.
98
+ </details>
99
+
100
+ ```grain
101
+ set : (a, b, ImmutableMap<a, b>) -> ImmutableMap<a, b>
102
+ ```
103
+
104
+ Produces a new map containing a new key-value pair. If the key already exists in the map, the value is replaced.
105
+
106
+ Parameters:
107
+
108
+ |param|type|description|
109
+ |-----|----|-----------|
110
+ |`key`|`a`|The unique key in the map|
111
+ |`value`|`b`|The value to store|
112
+ |`map`|`ImmutableMap<a, b>`|The base map|
113
+
114
+ Returns:
115
+
116
+ |type|description|
117
+ |----|-----------|
118
+ |`ImmutableMap<a, b>`|A new map containing the new key-value pair|
119
+
120
+ ### ImmutableMap.**get**
121
+
122
+ <details disabled>
123
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
124
+ No other changes yet.
125
+ </details>
126
+
127
+ ```grain
128
+ get : (a, ImmutableMap<a, b>) -> Option<b>
129
+ ```
130
+
131
+ Retrieves the value for the given key.
132
+
133
+ Parameters:
134
+
135
+ |param|type|description|
136
+ |-----|----|-----------|
137
+ |`key`|`a`|The key to access|
138
+ |`map`|`ImmutableMap<a, b>`|The map to access|
139
+
140
+ Returns:
141
+
142
+ |type|description|
143
+ |----|-----------|
144
+ |`Option<b>`|`Some(value)` if the key exists in the map or `None` otherwise|
145
+
146
+ ### ImmutableMap.**contains**
147
+
148
+ <details disabled>
149
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
150
+ No other changes yet.
151
+ </details>
152
+
153
+ ```grain
154
+ contains : (a, ImmutableMap<a, b>) -> Bool
155
+ ```
156
+
157
+ Determines if the map contains the given key. In such a case, it will always contain a value for the given key.
158
+
159
+ Parameters:
160
+
161
+ |param|type|description|
162
+ |-----|----|-----------|
163
+ |`key`|`a`|The key to search for|
164
+ |`map`|`ImmutableMap<a, b>`|The map to search|
165
+
166
+ Returns:
167
+
168
+ |type|description|
169
+ |----|-----------|
170
+ |`Bool`|`true` if the map contains the given key or `false` otherwise|
171
+
172
+ ### ImmutableMap.**remove**
173
+
174
+ <details disabled>
175
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
176
+ No other changes yet.
177
+ </details>
178
+
179
+ ```grain
180
+ remove : (a, ImmutableMap<a, b>) -> ImmutableMap<a, b>
181
+ ```
182
+
183
+ Produces a new map without the key-value pair corresponding to the given
184
+ key. If the key doesn't exist in the map, the map will be returned unmodified.
185
+
186
+ Parameters:
187
+
188
+ |param|type|description|
189
+ |-----|----|-----------|
190
+ |`key`|`a`|The key to exclude|
191
+ |`map`|`ImmutableMap<a, b>`|The map to exclude from|
192
+
193
+ Returns:
194
+
195
+ |type|description|
196
+ |----|-----------|
197
+ |`ImmutableMap<a, b>`|A new map without the given key|
198
+
199
+ ### ImmutableMap.**update**
200
+
201
+ <details disabled>
202
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
203
+ No other changes yet.
204
+ </details>
205
+
206
+ ```grain
207
+ update :
208
+ (a, (Option<b> -> Option<b>), ImmutableMap<a, b>) -> ImmutableMap<a, b>
209
+ ```
210
+
211
+ Produces a new map by calling an updater function that receives the
212
+ previously stored value as an `Option` and returns the new value to be
213
+ stored as an `Option`. If the key didn't exist previously, the value
214
+ will be `None`. If `None` is returned from the updater function, the
215
+ key-value pair is excluded.
216
+
217
+ Parameters:
218
+
219
+ |param|type|description|
220
+ |-----|----|-----------|
221
+ |`key`|`a`|The unique key in the map|
222
+ |`fn`|`Option<b> -> Option<b>`|The updater function|
223
+ |`map`|`ImmutableMap<a, b>`|The base map|
224
+
225
+ Returns:
226
+
227
+ |type|description|
228
+ |----|-----------|
229
+ |`ImmutableMap<a, b>`|A new map with the value at the given key modified according to the function's output|
230
+
231
+ ### ImmutableMap.**forEach**
232
+
233
+ <details disabled>
234
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
235
+ No other changes yet.
236
+ </details>
237
+
238
+ ```grain
239
+ forEach : (((a, b) -> Void), ImmutableMap<a, b>) -> Void
240
+ ```
241
+
242
+ Iterates the map, calling an iterator function with each key and value.
243
+
244
+ Parameters:
245
+
246
+ |param|type|description|
247
+ |-----|----|-----------|
248
+ |`fn`|`(a, b) -> Void`|The iterator function to call with each key and value|
249
+ |`map`|`ImmutableMap<a, b>`|The map to iterate|
250
+
251
+ ### ImmutableMap.**reduce**
252
+
253
+ <details disabled>
254
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
255
+ No other changes yet.
256
+ </details>
257
+
258
+ ```grain
259
+ reduce : (((a, b, c) -> a), a, ImmutableMap<b, c>) -> a
260
+ ```
261
+
262
+ Combines all key-value pairs of a map using a reducer function.
263
+
264
+ Parameters:
265
+
266
+ |param|type|description|
267
+ |-----|----|-----------|
268
+ |`fn`|`(a, b, c) -> a`|The reducer function to call on each key and value, where the value returned will be the next accumulator value|
269
+ |`init`|`a`|The initial value to use for the accumulator on the first iteration|
270
+ |`map`|`ImmutableMap<b, c>`|The map to iterate|
271
+
272
+ Returns:
273
+
274
+ |type|description|
275
+ |----|-----------|
276
+ |`a`|The final accumulator returned from `fn`|
277
+
278
+ ### ImmutableMap.**keys**
279
+
280
+ <details disabled>
281
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
282
+ No other changes yet.
283
+ </details>
284
+
285
+ ```grain
286
+ keys : ImmutableMap<a, b> -> List<a>
287
+ ```
288
+
289
+ Enumerates all keys in the given map.
290
+
291
+ Parameters:
292
+
293
+ |param|type|description|
294
+ |-----|----|-----------|
295
+ |`map`|`ImmutableMap<a, b>`|The map to enumerate|
296
+
297
+ Returns:
298
+
299
+ |type|description|
300
+ |----|-----------|
301
+ |`List<a>`|A list containing all keys from the given map|
302
+
303
+ ### ImmutableMap.**values**
304
+
305
+ <details disabled>
306
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
307
+ No other changes yet.
308
+ </details>
309
+
310
+ ```grain
311
+ values : ImmutableMap<a, b> -> List<b>
312
+ ```
313
+
314
+ Enumerates all values in the given map.
315
+
316
+ Parameters:
317
+
318
+ |param|type|description|
319
+ |-----|----|-----------|
320
+ |`map`|`ImmutableMap<a, b>`|The map to enumerate|
321
+
322
+ Returns:
323
+
324
+ |type|description|
325
+ |----|-----------|
326
+ |`List<b>`|A list containing all values from the given map|
327
+
328
+ ### ImmutableMap.**filter**
329
+
330
+ <details disabled>
331
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
332
+ No other changes yet.
333
+ </details>
334
+
335
+ ```grain
336
+ filter : (((a, b) -> Bool), ImmutableMap<a, b>) -> ImmutableMap<a, b>
337
+ ```
338
+
339
+ Produces a new map excluding the key-value pairs where a predicate function returns `false`.
340
+
341
+ Parameters:
342
+
343
+ |param|type|description|
344
+ |-----|----|-----------|
345
+ |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to exclude from the map, where returning `false` indicates the key-value pair should be excluded|
346
+ |`map`|`ImmutableMap<a, b>`|The map to iterate|
347
+
348
+ Returns:
349
+
350
+ |type|description|
351
+ |----|-----------|
352
+ |`ImmutableMap<a, b>`|A new map excluding the key-value pairs not fulfilling the predicate|
353
+
354
+ ### ImmutableMap.**reject**
355
+
356
+ <details disabled>
357
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
358
+ No other changes yet.
359
+ </details>
360
+
361
+ ```grain
362
+ reject : (((a, b) -> Bool), ImmutableMap<a, b>) -> ImmutableMap<a, b>
363
+ ```
364
+
365
+ Produces a new map excluding the key-value pairs where a predicate function returns `true`.
366
+
367
+ Parameters:
368
+
369
+ |param|type|description|
370
+ |-----|----|-----------|
371
+ |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to exclude from the map, where returning `true` indicates the key-value pair should be excluded|
372
+ |`map`|`ImmutableMap<a, b>`|The map to iterate|
373
+
374
+ Returns:
375
+
376
+ |type|description|
377
+ |----|-----------|
378
+ |`ImmutableMap<a, b>`|A new map excluding the key-value pairs fulfilling the predicate|
379
+
380
+ ### ImmutableMap.**fromList**
381
+
382
+ <details disabled>
383
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
384
+ No other changes yet.
385
+ </details>
386
+
387
+ ```grain
388
+ fromList : List<(a, b)> -> ImmutableMap<a, b>
389
+ ```
390
+
391
+ Creates a map from a list.
392
+
393
+ Parameters:
394
+
395
+ |param|type|description|
396
+ |-----|----|-----------|
397
+ |`list`|`List<(a, b)>`|The list to convert|
398
+
399
+ Returns:
400
+
401
+ |type|description|
402
+ |----|-----------|
403
+ |`ImmutableMap<a, b>`|A map containing all key-value pairs from the list|
404
+
405
+ ### ImmutableMap.**toList**
406
+
407
+ <details disabled>
408
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
409
+ No other changes yet.
410
+ </details>
411
+
412
+ ```grain
413
+ toList : ImmutableMap<a, b> -> List<(a, b)>
414
+ ```
415
+
416
+ Enumerates all key-value pairs in the given map.
417
+
418
+ Parameters:
419
+
420
+ |param|type|description|
421
+ |-----|----|-----------|
422
+ |`map`|`ImmutableMap<a, b>`|The map to enumerate|
423
+
424
+ Returns:
425
+
426
+ |type|description|
427
+ |----|-----------|
428
+ |`List<(a, b)>`|A list containing all key-value pairs from the given map|
429
+
430
+ ### ImmutableMap.**fromArray**
431
+
432
+ <details disabled>
433
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
434
+ No other changes yet.
435
+ </details>
436
+
437
+ ```grain
438
+ fromArray : Array<(a, b)> -> ImmutableMap<a, b>
439
+ ```
440
+
441
+ Creates a map from an array.
442
+
443
+ Parameters:
444
+
445
+ |param|type|description|
446
+ |-----|----|-----------|
447
+ |`array`|`Array<(a, b)>`|The array to convert|
448
+
449
+ Returns:
450
+
451
+ |type|description|
452
+ |----|-----------|
453
+ |`ImmutableMap<a, b>`|A map containing all key-value pairs from the array|
454
+
455
+ ### ImmutableMap.**toArray**
456
+
457
+ <details disabled>
458
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
459
+ No other changes yet.
460
+ </details>
461
+
462
+ ```grain
463
+ toArray : ImmutableMap<a, b> -> Array<(a, b)>
464
+ ```
465
+
466
+ Converts a map into an array of its key-value pairs.
467
+
468
+ Parameters:
469
+
470
+ |param|type|description|
471
+ |-----|----|-----------|
472
+ |`map`|`ImmutableMap<a, b>`|The map to convert|
473
+
474
+ Returns:
475
+
476
+ |type|description|
477
+ |----|-----------|
478
+ |`Array<(a, b)>`|An array containing all key-value pairs from the given map|
479
+
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import List from "list"
10
+ import Array from "array"
10
11
 
11
12
  // implementation based on immutable skew binomial queue with global root optimization
12
13
  // as described in the paper "Optimal Purely Functional Priority Queues" by Chris Okasaki.
@@ -40,18 +41,28 @@ record ImmutablePriorityQueue<a> {
40
41
  }
41
42
 
42
43
  /**
43
- * @section Values: Functions for working with ImmutablePriorityQueues.
44
+ * @section Values: Functions and constants for working with ImmutablePriorityQueues.
44
45
  */
45
46
 
47
+ /**
48
+ * An empty priority queue with the default `compare` comparator.
49
+ *
50
+ * @since v0.5.4
51
+ */
52
+ export let empty = {
53
+ let empty = { comp: compare, size: 0, root: None }
54
+ empty
55
+ }
56
+
46
57
  /**
47
58
  * Creates a new priority queue with a comparator function, which is used to
48
59
  * determine priority of elements. The comparator function takes two elements
49
60
  * and must return 0 if both share priority, a positive number if the first
50
61
  * has greater priority, and a negative number if the first has less priority.
51
- *
62
+ *
52
63
  * @param comp: The comparator function used to indicate priority order
53
64
  * @returns An empty priority queue
54
- *
65
+ *
55
66
  * @example ImmutablePriorityQueue.make(compare) // creates a min priority queue of numbers using the compare pervasive
56
67
  * @example ImmutablePriorityQueue.make((a, b) => String.length(b) - String.length(a)) // creates a priority queue by string length (longest to shortest)
57
68
  *
@@ -63,7 +74,7 @@ export let make = comp => {
63
74
 
64
75
  /**
65
76
  * Gets the number of elements in a priority queue.
66
- *
77
+ *
67
78
  * @param pq: The priority queue to inspect
68
79
  * @returns The number of elements in the priority queue
69
80
  *
@@ -75,7 +86,7 @@ export let size = pq => {
75
86
 
76
87
  /**
77
88
  * Determines if the priority queue contains no elements.
78
- *
89
+ *
79
90
  * @param pq: The priority queue to check
80
91
  * @returns `true` if the priority queue is empty and `false` otherwise
81
92
  *
@@ -120,7 +131,7 @@ let skewInsert = (comp, val, pq) => {
120
131
 
121
132
  /**
122
133
  * Produces a new priority queue by inserting the given element into the given priority queue.
123
- *
134
+ *
124
135
  * @param val: The value to add into the priority queue
125
136
  * @param pq: The priority queue
126
137
  * @returns A new priority queue with the given element inserted
@@ -131,8 +142,8 @@ export let push = (val, pq) => {
131
142
  None => { comp, size: 1, root: Some({ rootVal: val, pq: [] }) },
132
143
  Some({ rootVal, pq }) => {
133
144
  // make the new value the root if it has higher priority than the highest priority value
134
- let (morePriorityVal, lessPriorityVal) = if (comp(val, rootVal) <= 0)
135
- (val, rootVal) else (rootVal, val)
145
+ let (morePriorityVal, lessPriorityVal) =
146
+ if (comp(val, rootVal) <= 0) (val, rootVal) else (rootVal, val)
136
147
 
137
148
  let newRoot = Some(
138
149
  { rootVal: morePriorityVal, pq: skewInsert(comp, lessPriorityVal, pq) }
@@ -145,7 +156,7 @@ export let push = (val, pq) => {
145
156
  /**
146
157
  * Retrieves the highest priority element in the priority queue. It is not
147
158
  * removed from the queue.
148
- *
159
+ *
149
160
  * @param pq: The priority queue to inspect
150
161
  * @returns `Some(value)` containing the highest priority element or `None` if the priority queue is empty
151
162
  *
@@ -161,8 +172,8 @@ export let peek = pq => {
161
172
  let linkNodes = (comp, node1, node2) => {
162
173
  // make the node with higher priority the parent of the node with smaller
163
174
  // priority to presere heap-ordering
164
- let (morePriority, lessPriority) = if (comp(node1.val, node2.val) <= 0)
165
- (node1, node2) else (node2, node1)
175
+ let (morePriority, lessPriority) =
176
+ if (comp(node1.val, node2.val) <= 0) (node1, node2) else (node2, node1)
166
177
  {
167
178
  val: morePriority.val,
168
179
  rank: morePriority.rank + 1,
@@ -216,7 +227,7 @@ let merge = (comp, pq1, pq2) =>
216
227
  let rec separateHighestPriority = (comp, pq) => {
217
228
  match (pq) {
218
229
  // empty list case should never happen; this is here just to satisfy the compiler
219
- [] => fail "getHighestPriority called with empty PQ",
230
+ [] => fail "Impossible: getHighestPriority called with empty PQ",
220
231
  [node] => (node, []),
221
232
  [node, ...rest] => {
222
233
  let (currMinNode, currNonMinNodes) = separateHighestPriority(comp, rest)
@@ -256,7 +267,7 @@ let withoutHighestPriority = (comp, pq) => {
256
267
  let rec findHighestPriority = (comp, pq) => {
257
268
  match (pq) {
258
269
  // empty list case should never happen; this is here just to satisfy the compiler
259
- [] => fail "findHighestPriority with empty PQ",
270
+ [] => fail "Impossible: findHighestPriority with empty PQ",
260
271
  [node] => node.val,
261
272
  [node, ...rest] => {
262
273
  let currMin = findHighestPriority(comp, rest)
@@ -269,7 +280,7 @@ let rec findHighestPriority = (comp, pq) => {
269
280
  * Produces a new priority queue without the highest priority element in the
270
281
  * given priority queue. If the input priority queue is empty, this function will
271
282
  * return it.
272
- *
283
+ *
273
284
  * @param pq: The priority queue
274
285
  * @returns A new priority queue without the highest priority element
275
286
  *
@@ -298,7 +309,7 @@ export let pop = pq => {
298
309
 
299
310
  /**
300
311
  * Produces a list of all elements in the priority queue in priority order.
301
- *
312
+ *
302
313
  * @param pq: The priority queue to drain
303
314
  * @returns A list of all elements in the priority in priority order
304
315
  *
@@ -320,7 +331,7 @@ export let drain = pq => {
320
331
  * elements. The comparator function takes two elements and must return 0 if
321
332
  * both share priority, a positive number if the first has greater priority,
322
333
  * and a negative number if the first has less priority.
323
- *
334
+ *
324
335
  * @param list: A list of values used to initialize the priority queue
325
336
  * @param comp: A comparator function used to assign priority to elements
326
337
  * @returns A priority queue containing the elements from the list
@@ -330,3 +341,20 @@ export let drain = pq => {
330
341
  export let fromList = (list, comp) => {
331
342
  List.reduce((pq, val) => push(val, pq), make(comp), list)
332
343
  }
344
+
345
+ /**
346
+ * Constructs a new priority queue initialized with the elements in the array
347
+ * using a custom comparator function, which is used to determine priority of
348
+ * elements. The comparator function takes two elements and must return 0 if
349
+ * both share priority, a positive number if the first has greater priority,
350
+ * and a negative number if the first has less priority.
351
+ *
352
+ * @param array: An array of values used to initialize the priority queue
353
+ * @param comp: A comparator function used to assign priority to elements
354
+ * @returns A priority queue containing the elements from the array
355
+ *
356
+ * @since v0.5.4
357
+ */
358
+ export let fromArray = (array, comp) => {
359
+ Array.reduce((pq, val) => push(val, pq), make(comp), array)
360
+ }
@@ -27,7 +27,20 @@ Immutable data structure which maintains a priority order for its elements.
27
27
 
28
28
  ## Values
29
29
 
30
- Functions for working with ImmutablePriorityQueues.
30
+ Functions and constants for working with ImmutablePriorityQueues.
31
+
32
+ ### ImmutablePriorityQueue.**empty**
33
+
34
+ <details disabled>
35
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
36
+ No other changes yet.
37
+ </details>
38
+
39
+ ```grain
40
+ empty : ImmutablePriorityQueue<a>
41
+ ```
42
+
43
+ An empty priority queue with the default `compare` comparator.
31
44
 
32
45
  ### ImmutablePriorityQueue.**make**
33
46
 
@@ -246,3 +259,33 @@ Returns:
246
259
  |----|-----------|
247
260
  |`ImmutablePriorityQueue<a>`|A priority queue containing the elements from the list|
248
261
 
262
+ ### ImmutablePriorityQueue.**fromArray**
263
+
264
+ <details disabled>
265
+ <summary tabindex="-1">Added in <code>0.5.4</code></summary>
266
+ No other changes yet.
267
+ </details>
268
+
269
+ ```grain
270
+ fromArray : (Array<a>, ((a, a) -> Number)) -> ImmutablePriorityQueue<a>
271
+ ```
272
+
273
+ Constructs a new priority queue initialized with the elements in the array
274
+ using a custom comparator function, which is used to determine priority of
275
+ elements. The comparator function takes two elements and must return 0 if
276
+ both share priority, a positive number if the first has greater priority,
277
+ and a negative number if the first has less priority.
278
+
279
+ Parameters:
280
+
281
+ |param|type|description|
282
+ |-----|----|-----------|
283
+ |`array`|`Array<a>`|An array of values used to initialize the priority queue|
284
+ |`comp`|`(a, a) -> Number`|A comparator function used to assign priority to elements|
285
+
286
+ Returns:
287
+
288
+ |type|description|
289
+ |----|-----------|
290
+ |`ImmutablePriorityQueue<a>`|A priority queue containing the elements from the array|
291
+