@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.
- package/CHANGELOG.md +59 -0
- package/array.gr +61 -1
- package/array.md +113 -0
- package/bigint.md +30 -30
- package/buffer.gr +24 -22
- package/char.gr +2 -2
- package/float32.md +3 -3
- package/float64.md +3 -3
- package/immutablemap.gr +493 -0
- package/immutablemap.md +479 -0
- package/immutablepriorityqueue.gr +360 -0
- package/immutablepriorityqueue.md +291 -0
- package/immutableset.gr +498 -0
- package/immutableset.md +449 -0
- package/list.gr +75 -2
- package/list.md +110 -0
- package/map.gr +1 -2
- package/marshal.gr +1058 -0
- package/marshal.md +76 -0
- package/number.gr +689 -23
- package/number.md +362 -27
- package/package.json +1 -1
- package/pervasives.gr +16 -5
- package/pervasives.md +28 -0
- package/priorityqueue.gr +261 -0
- package/priorityqueue.md +309 -0
- package/queue.gr +14 -1
- package/queue.md +16 -1
- package/regex.gr +90 -67
- package/runtime/bigint.gr +4 -4
- package/runtime/compare.gr +179 -0
- package/runtime/compare.md +6 -0
- package/runtime/equal.gr +3 -3
- 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 +423 -100
- package/runtime/numbers.md +50 -0
- package/runtime/string.gr +4 -2
- package/set.gr +26 -27
- package/stack.gr +12 -0
- package/stack.md +15 -0
- package/string.gr +409 -53
- package/string.md +164 -1
- package/sys/file.gr +4 -4
- package/sys/file.md +3 -3
- package/sys/process.gr +3 -3
- package/sys/process.md +3 -3
- package/sys/random.gr +2 -2
- package/sys/random.md +2 -2
- package/sys/time.gr +2 -2
- package/sys/time.md +2 -2
package/immutablemap.md
ADDED
|
@@ -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
|
+
|