@grain/stdlib 0.5.3 → 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.
- package/CHANGELOG.md +38 -0
- package/array.gr +5 -0
- package/array.md +30 -0
- package/char.gr +2 -2
- package/immutablemap.gr +493 -0
- package/immutablemap.md +479 -0
- package/immutablepriorityqueue.gr +33 -5
- package/immutablepriorityqueue.md +44 -1
- package/immutableset.gr +498 -0
- package/immutableset.md +449 -0
- package/list.gr +2 -2
- package/marshal.gr +4 -4
- package/number.gr +648 -23
- package/number.md +284 -24
- package/package.json +1 -1
- package/priorityqueue.gr +25 -5
- package/priorityqueue.md +30 -0
- package/queue.gr +14 -1
- package/queue.md +16 -1
- package/regex.gr +85 -62
- package/runtime/bigint.gr +4 -4
- package/runtime/compare.gr +2 -1
- package/runtime/equal.gr +2 -1
- package/runtime/exception.gr +9 -5
- package/runtime/exception.md +8 -2
- package/runtime/gc.gr +2 -1
- package/runtime/malloc.gr +1 -3
- package/runtime/numberUtils.gr +11 -11
- package/runtime/numbers.gr +120 -36
- package/runtime/numbers.md +26 -0
- package/runtime/string.gr +4 -2
- package/set.gr +25 -25
- package/stack.gr +12 -0
- package/stack.md +15 -0
- package/string.gr +312 -38
- package/string.md +99 -0
- package/sys/file.gr +1 -1
package/immutableset.md
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ImmutableSet
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
An ImmutableSet is a collection of unique values. Operations on an ImmutableSet do not mutate the set'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 ImmutableSet from "immutableset"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Types
|
|
17
|
+
|
|
18
|
+
Type declarations included in the ImmutableSet module.
|
|
19
|
+
|
|
20
|
+
### ImmutableSet.**ImmutableSet**
|
|
21
|
+
|
|
22
|
+
```grain
|
|
23
|
+
type ImmutableSet<a>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Values
|
|
27
|
+
|
|
28
|
+
Functions and constants for working with ImmutableSets.
|
|
29
|
+
|
|
30
|
+
### ImmutableSet.**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 : ImmutableSet<a>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
An empty set
|
|
42
|
+
|
|
43
|
+
### ImmutableSet.**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 : ImmutableSet<a> -> Number
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Provides the count of values within the set.
|
|
55
|
+
|
|
56
|
+
Parameters:
|
|
57
|
+
|
|
58
|
+
|param|type|description|
|
|
59
|
+
|-----|----|-----------|
|
|
60
|
+
|`set`|`ImmutableSet<a>`|The set to inspect|
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
|
|
64
|
+
|type|description|
|
|
65
|
+
|----|-----------|
|
|
66
|
+
|`Number`|The count of elements in the set|
|
|
67
|
+
|
|
68
|
+
### ImmutableSet.**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 : ImmutableSet<a> -> Bool
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Determines if the set contains no elements.
|
|
80
|
+
|
|
81
|
+
Parameters:
|
|
82
|
+
|
|
83
|
+
|param|type|description|
|
|
84
|
+
|-----|----|-----------|
|
|
85
|
+
|`set`|`ImmutableSet<a>`|The set to inspect|
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
|
|
89
|
+
|type|description|
|
|
90
|
+
|----|-----------|
|
|
91
|
+
|`Bool`|`true` if the given set is empty or `false` otherwise|
|
|
92
|
+
|
|
93
|
+
### ImmutableSet.**add**
|
|
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
|
+
add : (a, ImmutableSet<a>) -> ImmutableSet<a>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Produces a new set by inserting the given value into the set. If the value
|
|
105
|
+
already exists, the new set will have the same elements as the input set.
|
|
106
|
+
|
|
107
|
+
Parameters:
|
|
108
|
+
|
|
109
|
+
|param|type|description|
|
|
110
|
+
|-----|----|-----------|
|
|
111
|
+
|`key`|`a`|The value to add|
|
|
112
|
+
|`set`|`ImmutableSet<a>`|The base set|
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
|
|
116
|
+
|type|description|
|
|
117
|
+
|----|-----------|
|
|
118
|
+
|`ImmutableSet<a>`|A new set containing the new element|
|
|
119
|
+
|
|
120
|
+
### ImmutableSet.**contains**
|
|
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
|
+
contains : (a, ImmutableSet<a>) -> Bool
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Determines if the set contains the given value.
|
|
132
|
+
|
|
133
|
+
Parameters:
|
|
134
|
+
|
|
135
|
+
|param|type|description|
|
|
136
|
+
|-----|----|-----------|
|
|
137
|
+
|`key`|`a`|The value to search for|
|
|
138
|
+
|`set`|`ImmutableSet<a>`|The set to search|
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
|
|
142
|
+
|type|description|
|
|
143
|
+
|----|-----------|
|
|
144
|
+
|`Bool`|`true` if the set contains the given value or `false` otherwise|
|
|
145
|
+
|
|
146
|
+
### ImmutableSet.**remove**
|
|
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
|
+
remove : (a, ImmutableSet<a>) -> ImmutableSet<a>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Produces a new set without the given element. If the value doesn't exist in
|
|
158
|
+
the set, the set will be returned unmodified.
|
|
159
|
+
|
|
160
|
+
Parameters:
|
|
161
|
+
|
|
162
|
+
|param|type|description|
|
|
163
|
+
|-----|----|-----------|
|
|
164
|
+
|`key`|`a`|The value to exclude|
|
|
165
|
+
|`set`|`ImmutableSet<a>`|The set to exclude from|
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
|
|
169
|
+
|type|description|
|
|
170
|
+
|----|-----------|
|
|
171
|
+
|`ImmutableSet<a>`|A new set without the excluded element|
|
|
172
|
+
|
|
173
|
+
### ImmutableSet.**forEach**
|
|
174
|
+
|
|
175
|
+
<details disabled>
|
|
176
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
177
|
+
No other changes yet.
|
|
178
|
+
</details>
|
|
179
|
+
|
|
180
|
+
```grain
|
|
181
|
+
forEach : ((a -> Void), ImmutableSet<a>) -> Void
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Iterates the set, calling an iterator function on each element.
|
|
185
|
+
|
|
186
|
+
Parameters:
|
|
187
|
+
|
|
188
|
+
|param|type|description|
|
|
189
|
+
|-----|----|-----------|
|
|
190
|
+
|`fn`|`a -> Void`|The iterator function to call with each element|
|
|
191
|
+
|`set`|`ImmutableSet<a>`|The set to iterate|
|
|
192
|
+
|
|
193
|
+
### ImmutableSet.**reduce**
|
|
194
|
+
|
|
195
|
+
<details disabled>
|
|
196
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
197
|
+
No other changes yet.
|
|
198
|
+
</details>
|
|
199
|
+
|
|
200
|
+
```grain
|
|
201
|
+
reduce : (((a, b) -> a), a, ImmutableSet<b>) -> a
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Combines all elements of a set using a reducer function.
|
|
205
|
+
|
|
206
|
+
Parameters:
|
|
207
|
+
|
|
208
|
+
|param|type|description|
|
|
209
|
+
|-----|----|-----------|
|
|
210
|
+
|`fn`|`(a, b) -> a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
|
|
211
|
+
|`init`|`a`|The initial value to use for the accumulator on the first iteration|
|
|
212
|
+
|`set`|`ImmutableSet<b>`|The set to iterate|
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
|
|
216
|
+
|type|description|
|
|
217
|
+
|----|-----------|
|
|
218
|
+
|`a`|The final accumulator returned from `fn`|
|
|
219
|
+
|
|
220
|
+
### ImmutableSet.**filter**
|
|
221
|
+
|
|
222
|
+
<details disabled>
|
|
223
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
224
|
+
No other changes yet.
|
|
225
|
+
</details>
|
|
226
|
+
|
|
227
|
+
```grain
|
|
228
|
+
filter : ((a -> Bool), ImmutableSet<a>) -> ImmutableSet<a>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Produces a new set without the elements from the input set where a predicate function returns `false`.
|
|
232
|
+
|
|
233
|
+
Parameters:
|
|
234
|
+
|
|
235
|
+
|param|type|description|
|
|
236
|
+
|-----|----|-----------|
|
|
237
|
+
|`fn`|`a -> Bool`|The predicate function to indicate which elements to exclude from the set, where returning `false` indicates the value should be excluded|
|
|
238
|
+
|`set`|`ImmutableSet<a>`|The set to iterate|
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
|
|
242
|
+
|type|description|
|
|
243
|
+
|----|-----------|
|
|
244
|
+
|`ImmutableSet<a>`|A new set excluding the elements not fulfilling the predicate|
|
|
245
|
+
|
|
246
|
+
### ImmutableSet.**reject**
|
|
247
|
+
|
|
248
|
+
<details disabled>
|
|
249
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
250
|
+
No other changes yet.
|
|
251
|
+
</details>
|
|
252
|
+
|
|
253
|
+
```grain
|
|
254
|
+
reject : ((a -> Bool), ImmutableSet<a>) -> ImmutableSet<a>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Produces a new set without the elements from the input set where a predicate function returns `true`.
|
|
258
|
+
|
|
259
|
+
Parameters:
|
|
260
|
+
|
|
261
|
+
|param|type|description|
|
|
262
|
+
|-----|----|-----------|
|
|
263
|
+
|`fn`|`a -> Bool`|The predicate function to indicate which elements to exclude from the set, where returning `true` indicates the value should be excluded|
|
|
264
|
+
|`set`|`ImmutableSet<a>`|The set to iterate|
|
|
265
|
+
|
|
266
|
+
Returns:
|
|
267
|
+
|
|
268
|
+
|type|description|
|
|
269
|
+
|----|-----------|
|
|
270
|
+
|`ImmutableSet<a>`|A new set excluding the elements fulfilling the predicate|
|
|
271
|
+
|
|
272
|
+
### ImmutableSet.**union**
|
|
273
|
+
|
|
274
|
+
<details disabled>
|
|
275
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
276
|
+
No other changes yet.
|
|
277
|
+
</details>
|
|
278
|
+
|
|
279
|
+
```grain
|
|
280
|
+
union : (ImmutableSet<a>, ImmutableSet<a>) -> ImmutableSet<a>
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Combines two sets into a single set containing all elements from both sets.
|
|
284
|
+
|
|
285
|
+
Parameters:
|
|
286
|
+
|
|
287
|
+
|param|type|description|
|
|
288
|
+
|-----|----|-----------|
|
|
289
|
+
|`set1`|`ImmutableSet<a>`|The first set to combine|
|
|
290
|
+
|`set2`|`ImmutableSet<a>`|The second set to combine|
|
|
291
|
+
|
|
292
|
+
Returns:
|
|
293
|
+
|
|
294
|
+
|type|description|
|
|
295
|
+
|----|-----------|
|
|
296
|
+
|`ImmutableSet<a>`|A set containing all elements of both sets|
|
|
297
|
+
|
|
298
|
+
### ImmutableSet.**diff**
|
|
299
|
+
|
|
300
|
+
<details disabled>
|
|
301
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
302
|
+
No other changes yet.
|
|
303
|
+
</details>
|
|
304
|
+
|
|
305
|
+
```grain
|
|
306
|
+
diff : (ImmutableSet<a>, ImmutableSet<a>) -> ImmutableSet<a>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Combines two sets into a single set containing only the elements not shared between both sets.
|
|
310
|
+
|
|
311
|
+
Parameters:
|
|
312
|
+
|
|
313
|
+
|param|type|description|
|
|
314
|
+
|-----|----|-----------|
|
|
315
|
+
|`set1`|`ImmutableSet<a>`|The first set to combine|
|
|
316
|
+
|`set2`|`ImmutableSet<a>`|The second set to combine|
|
|
317
|
+
|
|
318
|
+
Returns:
|
|
319
|
+
|
|
320
|
+
|type|description|
|
|
321
|
+
|----|-----------|
|
|
322
|
+
|`ImmutableSet<a>`|A set containing only unshared elements from both sets|
|
|
323
|
+
|
|
324
|
+
### ImmutableSet.**intersect**
|
|
325
|
+
|
|
326
|
+
<details disabled>
|
|
327
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
328
|
+
No other changes yet.
|
|
329
|
+
</details>
|
|
330
|
+
|
|
331
|
+
```grain
|
|
332
|
+
intersect : (ImmutableSet<a>, ImmutableSet<a>) -> ImmutableSet<a>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Combines two sets into a single set containing only the elements shared between both sets.
|
|
336
|
+
|
|
337
|
+
Parameters:
|
|
338
|
+
|
|
339
|
+
|param|type|description|
|
|
340
|
+
|-----|----|-----------|
|
|
341
|
+
|`set1`|`ImmutableSet<a>`|The first set to combine|
|
|
342
|
+
|`set2`|`ImmutableSet<a>`|The second set to combine|
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
|
|
346
|
+
|type|description|
|
|
347
|
+
|----|-----------|
|
|
348
|
+
|`ImmutableSet<a>`|A set containing only shared elements from both sets|
|
|
349
|
+
|
|
350
|
+
### ImmutableSet.**fromList**
|
|
351
|
+
|
|
352
|
+
<details disabled>
|
|
353
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
354
|
+
No other changes yet.
|
|
355
|
+
</details>
|
|
356
|
+
|
|
357
|
+
```grain
|
|
358
|
+
fromList : List<a> -> ImmutableSet<a>
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Creates a set from a list.
|
|
362
|
+
|
|
363
|
+
Parameters:
|
|
364
|
+
|
|
365
|
+
|param|type|description|
|
|
366
|
+
|-----|----|-----------|
|
|
367
|
+
|`list`|`List<a>`|The list to convert|
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
|
|
371
|
+
|type|description|
|
|
372
|
+
|----|-----------|
|
|
373
|
+
|`ImmutableSet<a>`|A set containing all list values|
|
|
374
|
+
|
|
375
|
+
### ImmutableSet.**toList**
|
|
376
|
+
|
|
377
|
+
<details disabled>
|
|
378
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
379
|
+
No other changes yet.
|
|
380
|
+
</details>
|
|
381
|
+
|
|
382
|
+
```grain
|
|
383
|
+
toList : ImmutableSet<a> -> List<a>
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Converts a set into a list of its elements.
|
|
387
|
+
|
|
388
|
+
Parameters:
|
|
389
|
+
|
|
390
|
+
|param|type|description|
|
|
391
|
+
|-----|----|-----------|
|
|
392
|
+
|`set`|`ImmutableSet<a>`|The set to convert|
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
|
|
396
|
+
|type|description|
|
|
397
|
+
|----|-----------|
|
|
398
|
+
|`List<a>`|A list containing all set values|
|
|
399
|
+
|
|
400
|
+
### ImmutableSet.**fromArray**
|
|
401
|
+
|
|
402
|
+
<details disabled>
|
|
403
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
404
|
+
No other changes yet.
|
|
405
|
+
</details>
|
|
406
|
+
|
|
407
|
+
```grain
|
|
408
|
+
fromArray : Array<a> -> ImmutableSet<a>
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Creates a set from an array.
|
|
412
|
+
|
|
413
|
+
Parameters:
|
|
414
|
+
|
|
415
|
+
|param|type|description|
|
|
416
|
+
|-----|----|-----------|
|
|
417
|
+
|`array`|`Array<a>`|The array to convert|
|
|
418
|
+
|
|
419
|
+
Returns:
|
|
420
|
+
|
|
421
|
+
|type|description|
|
|
422
|
+
|----|-----------|
|
|
423
|
+
|`ImmutableSet<a>`|A set containing all array values|
|
|
424
|
+
|
|
425
|
+
### ImmutableSet.**toArray**
|
|
426
|
+
|
|
427
|
+
<details disabled>
|
|
428
|
+
<summary tabindex="-1">Added in <code>0.5.4</code></summary>
|
|
429
|
+
No other changes yet.
|
|
430
|
+
</details>
|
|
431
|
+
|
|
432
|
+
```grain
|
|
433
|
+
toArray : ImmutableSet<a> -> Array<a>
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
Converts a set into an array of its elements.
|
|
437
|
+
|
|
438
|
+
Parameters:
|
|
439
|
+
|
|
440
|
+
|param|type|description|
|
|
441
|
+
|-----|----|-----------|
|
|
442
|
+
|`set`|`ImmutableSet<a>`|The set to convert|
|
|
443
|
+
|
|
444
|
+
Returns:
|
|
445
|
+
|
|
446
|
+
|type|description|
|
|
447
|
+
|----|-----------|
|
|
448
|
+
|`Array<a>`|An array containing all set values|
|
|
449
|
+
|
package/list.gr
CHANGED
|
@@ -520,8 +520,8 @@ export let part = (count, list) => {
|
|
|
520
520
|
* @since v0.1.0
|
|
521
521
|
*/
|
|
522
522
|
export let rotate = (count, list) => {
|
|
523
|
-
let (beginning, end) =
|
|
524
|
-
else part(length(list) + count, list)
|
|
523
|
+
let (beginning, end) =
|
|
524
|
+
if (count >= 0) part(count, list) else part(length(list) + count, list)
|
|
525
525
|
append(end, beginning)
|
|
526
526
|
}
|
|
527
527
|
|
package/marshal.gr
CHANGED
|
@@ -54,7 +54,7 @@ let roundTo8 = n => {
|
|
|
54
54
|
@unsafe
|
|
55
55
|
let isHeapPtr = value =>
|
|
56
56
|
(value & Tags._GRAIN_GENERIC_TAG_MASK) ==
|
|
57
|
-
|
|
57
|
+
Tags._GRAIN_GENERIC_HEAP_TAG_TYPE
|
|
58
58
|
|
|
59
59
|
@unsafe
|
|
60
60
|
let rec size = (value, acc, valuesSeen, toplevel) => {
|
|
@@ -157,9 +157,9 @@ let rec size = (value, acc, valuesSeen, toplevel) => {
|
|
|
157
157
|
},
|
|
158
158
|
t when t == Tags._GRAIN_RATIONAL_BOXED_NUM_TAG => {
|
|
159
159
|
acc +
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
16n +
|
|
161
|
+
size(load(value, 8n), 0n, valuesSeen, false) +
|
|
162
|
+
size(load(value, 12n), 0n, valuesSeen, false)
|
|
163
163
|
},
|
|
164
164
|
_ => {
|
|
165
165
|
fail "Unknown number type"
|