@grain/stdlib 0.5.2 → 0.5.4

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 (54) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/array.gr +61 -1
  3. package/array.md +113 -0
  4. package/bigint.md +30 -30
  5. package/buffer.gr +24 -22
  6. package/char.gr +2 -2
  7. package/float32.md +3 -3
  8. package/float64.md +3 -3
  9. package/immutablemap.gr +493 -0
  10. package/immutablemap.md +479 -0
  11. package/immutablepriorityqueue.gr +360 -0
  12. package/immutablepriorityqueue.md +291 -0
  13. package/immutableset.gr +498 -0
  14. package/immutableset.md +449 -0
  15. package/list.gr +75 -2
  16. package/list.md +110 -0
  17. package/map.gr +1 -2
  18. package/marshal.gr +1058 -0
  19. package/marshal.md +76 -0
  20. package/number.gr +689 -23
  21. package/number.md +362 -27
  22. package/package.json +1 -1
  23. package/pervasives.gr +16 -5
  24. package/pervasives.md +28 -0
  25. package/priorityqueue.gr +261 -0
  26. package/priorityqueue.md +309 -0
  27. package/queue.gr +14 -1
  28. package/queue.md +16 -1
  29. package/regex.gr +90 -67
  30. package/runtime/bigint.gr +4 -4
  31. package/runtime/compare.gr +179 -0
  32. package/runtime/compare.md +6 -0
  33. package/runtime/equal.gr +3 -3
  34. package/runtime/exception.gr +9 -5
  35. package/runtime/exception.md +8 -2
  36. package/runtime/gc.gr +2 -1
  37. package/runtime/malloc.gr +1 -3
  38. package/runtime/numberUtils.gr +11 -11
  39. package/runtime/numbers.gr +423 -100
  40. package/runtime/numbers.md +50 -0
  41. package/runtime/string.gr +4 -2
  42. package/set.gr +26 -27
  43. package/stack.gr +12 -0
  44. package/stack.md +15 -0
  45. package/string.gr +409 -53
  46. package/string.md +164 -1
  47. package/sys/file.gr +4 -4
  48. package/sys/file.md +3 -3
  49. package/sys/process.gr +3 -3
  50. package/sys/process.md +3 -3
  51. package/sys/random.gr +2 -2
  52. package/sys/random.md +2 -2
  53. package/sys/time.gr +2 -2
  54. package/sys/time.md +2 -2
@@ -0,0 +1,360 @@
1
+ /**
2
+ * @module ImmutablePriorityQueue: An immutable priority queue. A priority queue is a data structure that maintains elements in a priority order. Elements with higher priority are served before elements with lower priority when extracting from the priority queue.
3
+ *
4
+ * @example import ImmutablePriorityQueue from "immutablepriorityqueue"
5
+ *
6
+ * @since v0.5.3
7
+ */
8
+
9
+ import List from "list"
10
+ import Array from "array"
11
+
12
+ // implementation based on immutable skew binomial queue with global root optimization
13
+ // as described in the paper "Optimal Purely Functional Priority Queues" by Chris Okasaki.
14
+
15
+ // rank is a stand-in for height of this skew binomial tree
16
+ record Node<a> {
17
+ val: a,
18
+ rank: Number,
19
+ children: List<Node<a>>,
20
+ }
21
+
22
+ // an optimization over binomial queue that allows keeping track of the root value
23
+
24
+ // a skew binomial queue is defined as a forest of heap-ordered skew binomial trees
25
+ record PQRoot<a> {
26
+ rootVal: a,
27
+ pq: List<Node<a>>,
28
+ }
29
+
30
+ /**
31
+ * @section Types: Type declarations included in the ImmutablePriorityQueue module.
32
+ */
33
+
34
+ /**
35
+ * Immutable data structure which maintains a priority order for its elements.
36
+ */
37
+ record ImmutablePriorityQueue<a> {
38
+ comp: (a, a) -> Number,
39
+ size: Number,
40
+ root: Option<PQRoot<a>>,
41
+ }
42
+
43
+ /**
44
+ * @section Values: Functions and constants for working with ImmutablePriorityQueues.
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
+
57
+ /**
58
+ * Creates a new priority queue with a comparator function, which is used to
59
+ * determine priority of elements. The comparator function takes two elements
60
+ * and must return 0 if both share priority, a positive number if the first
61
+ * has greater priority, and a negative number if the first has less priority.
62
+ *
63
+ * @param comp: The comparator function used to indicate priority order
64
+ * @returns An empty priority queue
65
+ *
66
+ * @example ImmutablePriorityQueue.make(compare) // creates a min priority queue of numbers using the compare pervasive
67
+ * @example ImmutablePriorityQueue.make((a, b) => String.length(b) - String.length(a)) // creates a priority queue by string length (longest to shortest)
68
+ *
69
+ * @since v0.5.3
70
+ */
71
+ export let make = comp => {
72
+ { comp, size: 0, root: None }
73
+ }
74
+
75
+ /**
76
+ * Gets the number of elements in a priority queue.
77
+ *
78
+ * @param pq: The priority queue to inspect
79
+ * @returns The number of elements in the priority queue
80
+ *
81
+ * @since v0.5.3
82
+ */
83
+ export let size = pq => {
84
+ pq.size
85
+ }
86
+
87
+ /**
88
+ * Determines if the priority queue contains no elements.
89
+ *
90
+ * @param pq: The priority queue to check
91
+ * @returns `true` if the priority queue is empty and `false` otherwise
92
+ *
93
+ * @since v0.5.3
94
+ */
95
+ export let isEmpty = pq => {
96
+ pq.size == 0
97
+ }
98
+
99
+ let skewLinkNodes = (comp, newNode, node1, node2) => {
100
+ // make the two nodes with larger values children of the node with the smallest value
101
+ if (comp(node1.val, newNode.val) <= 0 && comp(node1.val, node2.val) <= 0) {
102
+ {
103
+ val: node1.val,
104
+ rank: node1.rank + 1,
105
+ children: [newNode, node2, ...node1.children],
106
+ }
107
+ } else if (
108
+ comp(node2.val, newNode.val) <= 0 && comp(node2.val, node1.val) <= 0
109
+ ) {
110
+ {
111
+ val: node2.val,
112
+ rank: node2.rank + 1,
113
+ children: [newNode, node1, ...node2.children],
114
+ }
115
+ } else {
116
+ { val: newNode.val, rank: node1.rank + 1, children: [node1, node2] }
117
+ }
118
+ }
119
+
120
+ let skewInsert = (comp, val, pq) => {
121
+ let newNode = { val, rank: 0, children: [] }
122
+ match (pq) {
123
+ // the only time two trees will have the same rank is if they are the
124
+ // smallest-ranked trees in the queue, in which case we should link
125
+ // them with the new node
126
+ [node1, node2, ...rest] when node1.rank == node2.rank =>
127
+ [skewLinkNodes(comp, newNode, node1, node2), ...rest],
128
+ _ => [newNode, ...pq],
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Produces a new priority queue by inserting the given element into the given priority queue.
134
+ *
135
+ * @param val: The value to add into the priority queue
136
+ * @param pq: The priority queue
137
+ * @returns A new priority queue with the given element inserted
138
+ */
139
+ export let push = (val, pq) => {
140
+ let { comp, size, root } = pq
141
+ match (root) {
142
+ None => { comp, size: 1, root: Some({ rootVal: val, pq: [] }) },
143
+ Some({ rootVal, pq }) => {
144
+ // make the new value the root if it has higher priority than the highest priority value
145
+ let (morePriorityVal, lessPriorityVal) =
146
+ if (comp(val, rootVal) <= 0) (val, rootVal) else (rootVal, val)
147
+
148
+ let newRoot = Some(
149
+ { rootVal: morePriorityVal, pq: skewInsert(comp, lessPriorityVal, pq) }
150
+ )
151
+ { comp, size: size + 1, root: newRoot }
152
+ },
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Retrieves the highest priority element in the priority queue. It is not
158
+ * removed from the queue.
159
+ *
160
+ * @param pq: The priority queue to inspect
161
+ * @returns `Some(value)` containing the highest priority element or `None` if the priority queue is empty
162
+ *
163
+ * @since v0.5.3
164
+ */
165
+ export let peek = pq => {
166
+ match (pq.root) {
167
+ None => None,
168
+ Some({ rootVal, _ }) => Some(rootVal),
169
+ }
170
+ }
171
+
172
+ let linkNodes = (comp, node1, node2) => {
173
+ // make the node with higher priority the parent of the node with smaller
174
+ // priority to presere heap-ordering
175
+ let (morePriority, lessPriority) =
176
+ if (comp(node1.val, node2.val) <= 0) (node1, node2) else (node2, node1)
177
+ {
178
+ val: morePriority.val,
179
+ rank: morePriority.rank + 1,
180
+ children: [lessPriority, ...morePriority.children],
181
+ }
182
+ }
183
+
184
+ // step through the trees in the priority queue in increasing rank order until we
185
+ // find a missing rank, linking trees of equal rank as we go
186
+ let rec ins = (comp, node, pq) => {
187
+ match (pq) {
188
+ [] => [node],
189
+ [firstNode, ...rest] => {
190
+ if (node.rank < firstNode.rank) {
191
+ [node, firstNode, ...rest]
192
+ } else {
193
+ ins(comp, linkNodes(comp, node, firstNode), rest)
194
+ }
195
+ },
196
+ }
197
+ }
198
+
199
+ let uniquify = (comp, pq) => {
200
+ match (pq) {
201
+ [] => [],
202
+ [node, ...rest] => ins(comp, node, rest),
203
+ }
204
+ }
205
+
206
+ // step through the trees of two priority queues in increasing rank order,
207
+ // performing a simple link whenever we find two trees of equal rank
208
+ let rec mergeUniq = (comp, pq1, pq2) => {
209
+ match ((pq1, pq2)) {
210
+ ([], ts) | (ts, []) => ts,
211
+ ([node1, ...rest1], [node2, ...rest2]) => {
212
+ if (node1.rank < node2.rank) {
213
+ [node1, ...mergeUniq(comp, rest1, pq2)]
214
+ } else if (node2.rank < node1.rank) {
215
+ [node2, ...mergeUniq(comp, pq1, rest2)]
216
+ } else {
217
+ ins(comp, linkNodes(comp, node1, node2), mergeUniq(comp, rest1, rest2))
218
+ }
219
+ },
220
+ }
221
+ }
222
+
223
+ let merge = (comp, pq1, pq2) =>
224
+ mergeUniq(comp, uniquify(comp, pq1), uniquify(comp, pq2))
225
+
226
+ // splits the node with the minimum value out from the rest of the nodes
227
+ let rec separateHighestPriority = (comp, pq) => {
228
+ match (pq) {
229
+ // empty list case should never happen; this is here just to satisfy the compiler
230
+ [] => fail "getHighestPriority called with empty PQ",
231
+ [node] => (node, []),
232
+ [node, ...rest] => {
233
+ let (currMinNode, currNonMinNodes) = separateHighestPriority(comp, rest)
234
+ if (comp(node.val, currMinNode.val) <= 0) {
235
+ (node, rest)
236
+ } else {
237
+ (currMinNode, [node, ...currNonMinNodes])
238
+ }
239
+ },
240
+ }
241
+ }
242
+
243
+ // splits the nodes of rank 0 out from the other nodes
244
+ let rec splitRankZero = (rankZeroVals, nonRankZeroNodes, pq) => {
245
+ match (pq) {
246
+ [] => (rankZeroVals, nonRankZeroNodes),
247
+ [node, ...rest] => {
248
+ if (node.rank == 0) {
249
+ splitRankZero([node.val, ...rankZeroVals], nonRankZeroNodes, rest)
250
+ } else {
251
+ splitRankZero(rankZeroVals, [node, ...nonRankZeroNodes], rest)
252
+ }
253
+ },
254
+ }
255
+ }
256
+
257
+ let withoutHighestPriority = (comp, pq) => {
258
+ // split out the node with the highest priority
259
+ let (hpNode, nonHpNodes) = separateHighestPriority(comp, pq)
260
+ // split out the values with nodes of rank 0, which will all be singleton nodes
261
+ let (rankZeroVals, nonRankZeroNodes) = splitRankZero([], [], hpNode.children)
262
+
263
+ let mergedPq = merge(comp, nonHpNodes, nonRankZeroNodes)
264
+ List.reduce((pq, val) => skewInsert(comp, val, pq), mergedPq, rankZeroVals)
265
+ }
266
+
267
+ let rec findHighestPriority = (comp, pq) => {
268
+ match (pq) {
269
+ // empty list case should never happen; this is here just to satisfy the compiler
270
+ [] => fail "findHighestPriority with empty PQ",
271
+ [node] => node.val,
272
+ [node, ...rest] => {
273
+ let currMin = findHighestPriority(comp, rest)
274
+ if (comp(node.val, currMin) <= 0) node.val else currMin
275
+ },
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Produces a new priority queue without the highest priority element in the
281
+ * given priority queue. If the input priority queue is empty, this function will
282
+ * return it.
283
+ *
284
+ * @param pq: The priority queue
285
+ * @returns A new priority queue without the highest priority element
286
+ *
287
+ * @since v0.5.3
288
+ */
289
+ export let pop = pq => {
290
+ let pqWithRoot = pq
291
+ let { comp, size, root } = pq
292
+ match (root) {
293
+ None => pq,
294
+ Some({ pq, rootVal }) => {
295
+ let newRoot = if (pq == []) {
296
+ None
297
+ } else {
298
+ Some(
299
+ {
300
+ rootVal: findHighestPriority(comp, pq),
301
+ pq: withoutHighestPriority(comp, pq),
302
+ }
303
+ )
304
+ }
305
+ { comp, size: size - 1, root: newRoot }
306
+ },
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Produces a list of all elements in the priority queue in priority order.
312
+ *
313
+ * @param pq: The priority queue to drain
314
+ * @returns A list of all elements in the priority in priority order
315
+ *
316
+ * @since v0.5.3
317
+ */
318
+ export let drain = pq => {
319
+ let rec drainRec = (acc, pq) => {
320
+ match (pq.root) {
321
+ None => acc,
322
+ Some(root) => drainRec([root.rootVal, ...acc], pop(pq)),
323
+ }
324
+ }
325
+ List.reverse(drainRec([], pq))
326
+ }
327
+
328
+ /**
329
+ * Constructs a new priority queue initialized with the elements in the list
330
+ * using a custom comparator function, which is used to determine priority of
331
+ * elements. The comparator function takes two elements and must return 0 if
332
+ * both share priority, a positive number if the first has greater priority,
333
+ * and a negative number if the first has less priority.
334
+ *
335
+ * @param list: A list of values used to initialize the priority queue
336
+ * @param comp: A comparator function used to assign priority to elements
337
+ * @returns A priority queue containing the elements from the list
338
+ *
339
+ * @since v0.5.3
340
+ */
341
+ export let fromList = (list, comp) => {
342
+ List.reduce((pq, val) => push(val, pq), make(comp), list)
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
+ }
@@ -0,0 +1,291 @@
1
+ ---
2
+ title: ImmutablePriorityQueue
3
+ ---
4
+
5
+ An immutable priority queue. A priority queue is a data structure that maintains elements in a priority order. Elements with higher priority are served before elements with lower priority when extracting from the priority queue.
6
+
7
+ <details disabled>
8
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
9
+ No other changes yet.
10
+ </details>
11
+
12
+ ```grain
13
+ import ImmutablePriorityQueue from "immutablepriorityqueue"
14
+ ```
15
+
16
+ ## Types
17
+
18
+ Type declarations included in the ImmutablePriorityQueue module.
19
+
20
+ ### ImmutablePriorityQueue.**ImmutablePriorityQueue**
21
+
22
+ ```grain
23
+ type ImmutablePriorityQueue<a>
24
+ ```
25
+
26
+ Immutable data structure which maintains a priority order for its elements.
27
+
28
+ ## Values
29
+
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.
44
+
45
+ ### ImmutablePriorityQueue.**make**
46
+
47
+ <details disabled>
48
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
49
+ No other changes yet.
50
+ </details>
51
+
52
+ ```grain
53
+ make : ((a, a) -> Number) -> ImmutablePriorityQueue<a>
54
+ ```
55
+
56
+ Creates a new priority queue with a comparator function, which is used to
57
+ determine priority of elements. The comparator function takes two elements
58
+ and must return 0 if both share priority, a positive number if the first
59
+ has greater priority, and a negative number if the first has less priority.
60
+
61
+ Parameters:
62
+
63
+ |param|type|description|
64
+ |-----|----|-----------|
65
+ |`comp`|`(a, a) -> Number`|The comparator function used to indicate priority order|
66
+
67
+ Returns:
68
+
69
+ |type|description|
70
+ |----|-----------|
71
+ |`ImmutablePriorityQueue<a>`|An empty priority queue|
72
+
73
+ Examples:
74
+
75
+ ```grain
76
+ ImmutablePriorityQueue.make(compare) // creates a min priority queue of numbers using the compare pervasive
77
+ ```
78
+
79
+ ```grain
80
+ ImmutablePriorityQueue.make((a, b) => String.length(b) - String.length(a)) // creates a priority queue by string length (longest to shortest)
81
+ ```
82
+
83
+ ### ImmutablePriorityQueue.**size**
84
+
85
+ <details disabled>
86
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
87
+ No other changes yet.
88
+ </details>
89
+
90
+ ```grain
91
+ size : ImmutablePriorityQueue<a> -> Number
92
+ ```
93
+
94
+ Gets the number of elements in a priority queue.
95
+
96
+ Parameters:
97
+
98
+ |param|type|description|
99
+ |-----|----|-----------|
100
+ |`pq`|`ImmutablePriorityQueue<a>`|The priority queue to inspect|
101
+
102
+ Returns:
103
+
104
+ |type|description|
105
+ |----|-----------|
106
+ |`Number`|The number of elements in the priority queue|
107
+
108
+ ### ImmutablePriorityQueue.**isEmpty**
109
+
110
+ <details disabled>
111
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
112
+ No other changes yet.
113
+ </details>
114
+
115
+ ```grain
116
+ isEmpty : ImmutablePriorityQueue<a> -> Bool
117
+ ```
118
+
119
+ Determines if the priority queue contains no elements.
120
+
121
+ Parameters:
122
+
123
+ |param|type|description|
124
+ |-----|----|-----------|
125
+ |`pq`|`ImmutablePriorityQueue<a>`|The priority queue to check|
126
+
127
+ Returns:
128
+
129
+ |type|description|
130
+ |----|-----------|
131
+ |`Bool`|`true` if the priority queue is empty and `false` otherwise|
132
+
133
+ ### ImmutablePriorityQueue.**push**
134
+
135
+ ```grain
136
+ push : (a, ImmutablePriorityQueue<a>) -> ImmutablePriorityQueue<a>
137
+ ```
138
+
139
+ Produces a new priority queue by inserting the given element into the given priority queue.
140
+
141
+ Parameters:
142
+
143
+ |param|type|description|
144
+ |-----|----|-----------|
145
+ |`val`|`a`|The value to add into the priority queue|
146
+ |`pq`|`ImmutablePriorityQueue<a>`|The priority queue|
147
+
148
+ Returns:
149
+
150
+ |type|description|
151
+ |----|-----------|
152
+ |`ImmutablePriorityQueue<a>`|A new priority queue with the given element inserted|
153
+
154
+ ### ImmutablePriorityQueue.**peek**
155
+
156
+ <details disabled>
157
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
158
+ No other changes yet.
159
+ </details>
160
+
161
+ ```grain
162
+ peek : ImmutablePriorityQueue<a> -> Option<a>
163
+ ```
164
+
165
+ Retrieves the highest priority element in the priority queue. It is not
166
+ removed from the queue.
167
+
168
+ Parameters:
169
+
170
+ |param|type|description|
171
+ |-----|----|-----------|
172
+ |`pq`|`ImmutablePriorityQueue<a>`|The priority queue to inspect|
173
+
174
+ Returns:
175
+
176
+ |type|description|
177
+ |----|-----------|
178
+ |`Option<a>`|`Some(value)` containing the highest priority element or `None` if the priority queue is empty|
179
+
180
+ ### ImmutablePriorityQueue.**pop**
181
+
182
+ <details disabled>
183
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
184
+ No other changes yet.
185
+ </details>
186
+
187
+ ```grain
188
+ pop : ImmutablePriorityQueue<a> -> ImmutablePriorityQueue<a>
189
+ ```
190
+
191
+ Produces a new priority queue without the highest priority element in the
192
+ given priority queue. If the input priority queue is empty, this function will
193
+ return it.
194
+
195
+ Parameters:
196
+
197
+ |param|type|description|
198
+ |-----|----|-----------|
199
+ |`pq`|`ImmutablePriorityQueue<a>`|The priority queue|
200
+
201
+ Returns:
202
+
203
+ |type|description|
204
+ |----|-----------|
205
+ |`ImmutablePriorityQueue<a>`|A new priority queue without the highest priority element|
206
+
207
+ ### ImmutablePriorityQueue.**drain**
208
+
209
+ <details disabled>
210
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
211
+ No other changes yet.
212
+ </details>
213
+
214
+ ```grain
215
+ drain : ImmutablePriorityQueue<a> -> List<a>
216
+ ```
217
+
218
+ Produces a list of all elements in the priority queue in priority order.
219
+
220
+ Parameters:
221
+
222
+ |param|type|description|
223
+ |-----|----|-----------|
224
+ |`pq`|`ImmutablePriorityQueue<a>`|The priority queue to drain|
225
+
226
+ Returns:
227
+
228
+ |type|description|
229
+ |----|-----------|
230
+ |`List<a>`|A list of all elements in the priority in priority order|
231
+
232
+ ### ImmutablePriorityQueue.**fromList**
233
+
234
+ <details disabled>
235
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
236
+ No other changes yet.
237
+ </details>
238
+
239
+ ```grain
240
+ fromList : (List<a>, ((a, a) -> Number)) -> ImmutablePriorityQueue<a>
241
+ ```
242
+
243
+ Constructs a new priority queue initialized with the elements in the list
244
+ using a custom comparator function, which is used to determine priority of
245
+ elements. The comparator function takes two elements and must return 0 if
246
+ both share priority, a positive number if the first has greater priority,
247
+ and a negative number if the first has less priority.
248
+
249
+ Parameters:
250
+
251
+ |param|type|description|
252
+ |-----|----|-----------|
253
+ |`list`|`List<a>`|A list of values used to initialize the priority queue|
254
+ |`comp`|`(a, a) -> Number`|A comparator function used to assign priority to elements|
255
+
256
+ Returns:
257
+
258
+ |type|description|
259
+ |----|-----------|
260
+ |`ImmutablePriorityQueue<a>`|A priority queue containing the elements from the list|
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
+