@grain/stdlib 0.5.13 → 0.6.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 (155) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +47 -37
  21. package/hash.md +21 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2084 -0
  31. package/json.md +608 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +191 -172
  92. package/runtime/numberUtils.md +17 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +540 -242
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
package/map.md CHANGED
@@ -4,13 +4,15 @@ title: Map
4
4
 
5
5
  A Map holds key-value pairs. Any value may be used as a key or value. Operations on a Map mutate the internal state, so it never needs to be re-assigned.
6
6
 
7
+ An immutable map implementation is available in the `Immutable` submodule.
8
+
7
9
  <details disabled>
8
10
  <summary tabindex="-1">Added in <code>0.2.0</code></summary>
9
11
  No other changes yet.
10
12
  </details>
11
13
 
12
14
  ```grain
13
- import Map from "map"
15
+ from "map" include Map
14
16
  ```
15
17
 
16
18
  ## Types
@@ -23,28 +25,49 @@ Type declarations included in the Map module.
23
25
  type Map<k, v>
24
26
  ```
25
27
 
28
+ ### Map.**InternalMapStats**
29
+
30
+ ```grain
31
+ record InternalMapStats {
32
+ currentSize: Number,
33
+ bucketCount: Number,
34
+ }
35
+ ```
36
+
37
+ Represents the internal state of a map.
38
+
26
39
  ## Values
27
40
 
28
- Functions for working with Maps.
41
+ Functions and constants included in the Map module.
29
42
 
30
- ### Map.**makeSized**
43
+ ### Map.**make**
31
44
 
32
- <details disabled>
33
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
34
- No other changes yet.
45
+ <details>
46
+ <summary>Added in <code>0.2.0</code></summary>
47
+ <table>
48
+ <thead>
49
+ <tr><th>version</th><th>changes</th></tr>
50
+ </thead>
51
+ <tbody>
52
+ <tr><td><code>0.6.0</code></td><td>Merged with `makeSized`; modified signature to accept size</td></tr>
53
+ </tbody>
54
+ </table>
35
55
  </details>
36
56
 
37
57
  ```grain
38
- makeSized : Number -> Map<a, b>
58
+ make : (?size: Number) => Map<a, b>
39
59
  ```
40
60
 
41
- Creates a new empty map with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won't need to care about the storage size of your map and can use `Map.make()` instead.
61
+ Creates a new empty map with an initial storage of the given size. As
62
+ values are added or removed, the internal storage may grow or shrink.
63
+ Generally, you won't need to care about the storage size of your map and
64
+ can use the default size.
42
65
 
43
66
  Parameters:
44
67
 
45
68
  |param|type|description|
46
69
  |-----|----|-----------|
47
- |`size`|`Number`|The initial storage size of the map|
70
+ |`?size`|`Number`|The initial storage size of the map|
48
71
 
49
72
  Returns:
50
73
 
@@ -52,25 +75,6 @@ Returns:
52
75
  |----|-----------|
53
76
  |`Map<a, b>`|An empty map with the given initial storage size|
54
77
 
55
- ### Map.**make**
56
-
57
- <details disabled>
58
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
59
- No other changes yet.
60
- </details>
61
-
62
- ```grain
63
- make : () -> Map<a, b>
64
- ```
65
-
66
- Creates a new, empty map.
67
-
68
- Returns:
69
-
70
- |type|description|
71
- |----|-----------|
72
- |`Map<a, b>`|An empty map|
73
-
74
78
  ### Map.**set**
75
79
 
76
80
  <details disabled>
@@ -79,7 +83,7 @@ No other changes yet.
79
83
  </details>
80
84
 
81
85
  ```grain
82
- set : (a, b, Map<a, b>) -> Void
86
+ set : (key: a, value: b, map: Map<a, b>) => Void
83
87
  ```
84
88
 
85
89
  Adds a new key-value pair to the map. If the key already exists in the map, the value is replaced.
@@ -100,7 +104,7 @@ No other changes yet.
100
104
  </details>
101
105
 
102
106
  ```grain
103
- get : (a, Map<a, b>) -> Option<b>
107
+ get : (key: a, map: Map<a, b>) => Option<b>
104
108
  ```
105
109
 
106
110
  Retrieves the value for the given key.
@@ -126,7 +130,7 @@ No other changes yet.
126
130
  </details>
127
131
 
128
132
  ```grain
129
- contains : (a, Map<a, b>) -> Bool
133
+ contains : (key: a, map: Map<a, b>) => Bool
130
134
  ```
131
135
 
132
136
  Determines if the map contains the given key. In such a case, it will always contain a value for the given key.
@@ -152,7 +156,7 @@ No other changes yet.
152
156
  </details>
153
157
 
154
158
  ```grain
155
- remove : (a, Map<a, b>) -> Void
159
+ remove : (key: a, map: Map<a, b>) => Void
156
160
  ```
157
161
 
158
162
  Removes the given key from the map, which also removes the value. If the key pair doesn't exist, nothing happens.
@@ -172,7 +176,7 @@ No other changes yet.
172
176
  </details>
173
177
 
174
178
  ```grain
175
- update : (a, (Option<b> -> Option<b>), Map<a, b>) -> Void
179
+ update : (key: a, fn: (Option<b> => Option<b>), map: Map<a, b>) => Void
176
180
  ```
177
181
 
178
182
  Updates a value in the map by calling an updater function that receives the previously stored value as an `Option` and returns the new value to be stored as an `Option`. If the key didn't exist previously, the value will be `None`. If `None` is returned from the updater function, the key-value pair is removed.
@@ -182,7 +186,7 @@ Parameters:
182
186
  |param|type|description|
183
187
  |-----|----|-----------|
184
188
  |`key`|`a`|The unique key in the map|
185
- |`fn`|`Option<b> -> Option<b>`|The updater function|
189
+ |`fn`|`Option<b> => Option<b>`|The updater function|
186
190
  |`map`|`Map<a, b>`|The map to modify|
187
191
 
188
192
  ### Map.**size**
@@ -193,7 +197,7 @@ No other changes yet.
193
197
  </details>
194
198
 
195
199
  ```grain
196
- size : Map<a, b> -> Number
200
+ size : (map: Map<a, b>) => Number
197
201
  ```
198
202
 
199
203
  Provides the count of key-value pairs stored within the map.
@@ -218,7 +222,7 @@ No other changes yet.
218
222
  </details>
219
223
 
220
224
  ```grain
221
- isEmpty : Map<a, b> -> Bool
225
+ isEmpty : (map: Map<a, b>) => Bool
222
226
  ```
223
227
 
224
228
  Determines if the map contains no key-value pairs.
@@ -243,7 +247,7 @@ No other changes yet.
243
247
  </details>
244
248
 
245
249
  ```grain
246
- clear : Map<a, b> -> Void
250
+ clear : (map: Map<a, b>) => Void
247
251
  ```
248
252
 
249
253
  Resets the map by removing all key-value pairs.
@@ -269,7 +273,7 @@ Parameters:
269
273
  </details>
270
274
 
271
275
  ```grain
272
- forEach : (((a, b) -> Void), Map<a, b>) -> Void
276
+ forEach : (fn: ((a, b) => Void), map: Map<a, b>) => Void
273
277
  ```
274
278
 
275
279
  Iterates the map, calling an iterator function with each key and value.
@@ -278,7 +282,7 @@ Parameters:
278
282
 
279
283
  |param|type|description|
280
284
  |-----|----|-----------|
281
- |`fn`|`(a, b) -> Void`|The iterator function to call with each key and value|
285
+ |`fn`|`(a, b) => Void`|The iterator function to call with each key and value|
282
286
  |`map`|`Map<a, b>`|The map to iterate|
283
287
 
284
288
  ### Map.**reduce**
@@ -289,7 +293,7 @@ No other changes yet.
289
293
  </details>
290
294
 
291
295
  ```grain
292
- reduce : (((a, b, c) -> a), a, Map<b, c>) -> a
296
+ reduce : (fn: ((a, b, c) => a), init: a, map: Map<b, c>) => a
293
297
  ```
294
298
 
295
299
  Combines all key-value pairs of a map using a reducer function.
@@ -298,7 +302,7 @@ Parameters:
298
302
 
299
303
  |param|type|description|
300
304
  |-----|----|-----------|
301
- |`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|
305
+ |`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|
302
306
  |`init`|`a`|The initial value to use for the accumulator on the first iteration|
303
307
  |`map`|`Map<b, c>`|The map to iterate|
304
308
 
@@ -316,7 +320,7 @@ No other changes yet.
316
320
  </details>
317
321
 
318
322
  ```grain
319
- keys : Map<a, b> -> List<a>
323
+ keys : (map: Map<a, b>) => List<a>
320
324
  ```
321
325
 
322
326
  Enumerates all keys in the given map.
@@ -341,7 +345,7 @@ No other changes yet.
341
345
  </details>
342
346
 
343
347
  ```grain
344
- values : Map<a, b> -> List<b>
348
+ values : (map: Map<a, b>) => List<b>
345
349
  ```
346
350
 
347
351
  Enumerates all values in the given map.
@@ -366,7 +370,7 @@ No other changes yet.
366
370
  </details>
367
371
 
368
372
  ```grain
369
- toList : Map<a, b> -> List<(a, b)>
373
+ toList : (map: Map<a, b>) => List<(a, b)>
370
374
  ```
371
375
 
372
376
  Enumerates all key-value pairs in the given map.
@@ -391,7 +395,7 @@ No other changes yet.
391
395
  </details>
392
396
 
393
397
  ```grain
394
- fromList : List<(a, b)> -> Map<a, b>
398
+ fromList : (list: List<(a, b)>) => Map<a, b>
395
399
  ```
396
400
 
397
401
  Creates a map from a list.
@@ -416,7 +420,7 @@ No other changes yet.
416
420
  </details>
417
421
 
418
422
  ```grain
419
- toArray : Map<a, b> -> Array<(a, b)>
423
+ toArray : (map: Map<a, b>) => Array<(a, b)>
420
424
  ```
421
425
 
422
426
  Converts a map into an array of its key-value pairs.
@@ -441,7 +445,7 @@ No other changes yet.
441
445
  </details>
442
446
 
443
447
  ```grain
444
- fromArray : Array<(a, b)> -> Map<a, b>
448
+ fromArray : (array: Array<(a, b)>) => Map<a, b>
445
449
  ```
446
450
 
447
451
  Creates a map from an array.
@@ -466,7 +470,7 @@ No other changes yet.
466
470
  </details>
467
471
 
468
472
  ```grain
469
- filter : (((a, b) -> Bool), Map<a, b>) -> Void
473
+ filter : (fn: ((a, b) => Bool), map: Map<a, b>) => Void
470
474
  ```
471
475
 
472
476
  Removes key-value pairs from a map where a predicate function returns `false`.
@@ -475,7 +479,7 @@ Parameters:
475
479
 
476
480
  |param|type|description|
477
481
  |-----|----|-----------|
478
- |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `false` indicates the key-value pair should be removed|
482
+ |`fn`|`(a, b) => Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `false` indicates the key-value pair should be removed|
479
483
  |`map`|`Map<a, b>`|The map to iterate|
480
484
 
481
485
  ### Map.**reject**
@@ -486,7 +490,7 @@ No other changes yet.
486
490
  </details>
487
491
 
488
492
  ```grain
489
- reject : (((a, b) -> Bool), Map<a, b>) -> Void
493
+ reject : (fn: ((a, b) => Bool), map: Map<a, b>) => Void
490
494
  ```
491
495
 
492
496
  Removes key-value pairs from a map where a predicate function returns `true`.
@@ -495,18 +499,25 @@ Parameters:
495
499
 
496
500
  |param|type|description|
497
501
  |-----|----|-----------|
498
- |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `true` indicates the key-value pair should be removed|
502
+ |`fn`|`(a, b) => Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `true` indicates the key-value pair should be removed|
499
503
  |`map`|`Map<a, b>`|The map to iterate|
500
504
 
501
505
  ### Map.**getInternalStats**
502
506
 
503
- <details disabled>
504
- <summary tabindex="-1">Added in <code>0.2.0</code></summary>
505
- No other changes yet.
507
+ <details>
508
+ <summary>Added in <code>0.2.0</code></summary>
509
+ <table>
510
+ <thead>
511
+ <tr><th>version</th><th>changes</th></tr>
512
+ </thead>
513
+ <tbody>
514
+ <tr><td><code>0.6.0</code></td><td>Return `InternalMapStats` record instead of a tuple</td></tr>
515
+ </tbody>
516
+ </table>
506
517
  </details>
507
518
 
508
519
  ```grain
509
- getInternalStats : Map<a, b> -> (Number, Number)
520
+ getInternalStats : (map: Map<a, b>) => InternalMapStats
510
521
  ```
511
522
 
512
523
  Provides data representing the internal state state of the map.
@@ -521,5 +532,610 @@ Returns:
521
532
 
522
533
  |type|description|
523
534
  |----|-----------|
524
- |`(Number, Number)`|The internal state of the map|
535
+ |`InternalMapStats`|The internal state of the map|
536
+
537
+ ## Map.Immutable
538
+
539
+ An immutable map implementation.
540
+
541
+ <details>
542
+ <summary>Added in <code>0.6.0</code></summary>
543
+ <table>
544
+ <thead>
545
+ <tr><th>version</th><th>changes</th></tr>
546
+ </thead>
547
+ <tbody>
548
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
549
+ </tbody>
550
+ </table>
551
+ </details>
552
+
553
+ ### Types
554
+
555
+ Type declarations included in the Map.Immutable module.
556
+
557
+ #### Map.Immutable.**Map**
558
+
559
+ ```grain
560
+ type Map<k, v>
561
+ ```
562
+
563
+ ### Values
564
+
565
+ Functions and constants included in the Map.Immutable module.
566
+
567
+ #### Map.Immutable.**empty**
568
+
569
+ <details>
570
+ <summary>Added in <code>0.6.0</code></summary>
571
+ <table>
572
+ <thead>
573
+ <tr><th>version</th><th>changes</th></tr>
574
+ </thead>
575
+ <tbody>
576
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
577
+ </tbody>
578
+ </table>
579
+ </details>
580
+
581
+ ```grain
582
+ empty : Map<a, b>
583
+ ```
584
+
585
+ An empty map
586
+
587
+ #### Map.Immutable.**size**
588
+
589
+ <details>
590
+ <summary>Added in <code>0.6.0</code></summary>
591
+ <table>
592
+ <thead>
593
+ <tr><th>version</th><th>changes</th></tr>
594
+ </thead>
595
+ <tbody>
596
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
597
+ </tbody>
598
+ </table>
599
+ </details>
600
+
601
+ ```grain
602
+ size : (map: Map<a, b>) => Number
603
+ ```
604
+
605
+ Provides the count of key-value pairs stored within the map.
606
+
607
+ Parameters:
608
+
609
+ |param|type|description|
610
+ |-----|----|-----------|
611
+ |`map`|`Map<a, b>`|The map to inspect|
612
+
613
+ Returns:
614
+
615
+ |type|description|
616
+ |----|-----------|
617
+ |`Number`|The count of key-value pairs in the map|
618
+
619
+ #### Map.Immutable.**isEmpty**
620
+
621
+ <details>
622
+ <summary>Added in <code>0.6.0</code></summary>
623
+ <table>
624
+ <thead>
625
+ <tr><th>version</th><th>changes</th></tr>
626
+ </thead>
627
+ <tbody>
628
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
629
+ </tbody>
630
+ </table>
631
+ </details>
632
+
633
+ ```grain
634
+ isEmpty : (map: Map<a, b>) => Bool
635
+ ```
636
+
637
+ Determines if the map contains no key-value pairs.
638
+
639
+ Parameters:
640
+
641
+ |param|type|description|
642
+ |-----|----|-----------|
643
+ |`map`|`Map<a, b>`|The map to inspect|
644
+
645
+ Returns:
646
+
647
+ |type|description|
648
+ |----|-----------|
649
+ |`Bool`|`true` if the given map is empty or `false` otherwise|
650
+
651
+ #### Map.Immutable.**set**
652
+
653
+ <details>
654
+ <summary>Added in <code>0.6.0</code></summary>
655
+ <table>
656
+ <thead>
657
+ <tr><th>version</th><th>changes</th></tr>
658
+ </thead>
659
+ <tbody>
660
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
661
+ </tbody>
662
+ </table>
663
+ </details>
664
+
665
+ ```grain
666
+ set : (key: a, value: b, map: Map<a, b>) => Map<a, b>
667
+ ```
668
+
669
+ Produces a new map containing a new key-value pair. If the key already exists in the map, the value is replaced.
670
+
671
+ Parameters:
672
+
673
+ |param|type|description|
674
+ |-----|----|-----------|
675
+ |`key`|`a`|The unique key in the map|
676
+ |`value`|`b`|The value to store|
677
+ |`map`|`Map<a, b>`|The base map|
678
+
679
+ Returns:
680
+
681
+ |type|description|
682
+ |----|-----------|
683
+ |`Map<a, b>`|A new map containing the new key-value pair|
684
+
685
+ #### Map.Immutable.**get**
686
+
687
+ <details>
688
+ <summary>Added in <code>0.6.0</code></summary>
689
+ <table>
690
+ <thead>
691
+ <tr><th>version</th><th>changes</th></tr>
692
+ </thead>
693
+ <tbody>
694
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
695
+ </tbody>
696
+ </table>
697
+ </details>
698
+
699
+ ```grain
700
+ get : (key: a, map: Map<a, b>) => Option<b>
701
+ ```
702
+
703
+ Retrieves the value for the given key.
704
+
705
+ Parameters:
706
+
707
+ |param|type|description|
708
+ |-----|----|-----------|
709
+ |`key`|`a`|The key to access|
710
+ |`map`|`Map<a, b>`|The map to access|
711
+
712
+ Returns:
713
+
714
+ |type|description|
715
+ |----|-----------|
716
+ |`Option<b>`|`Some(value)` if the key exists in the map or `None` otherwise|
717
+
718
+ #### Map.Immutable.**contains**
719
+
720
+ <details>
721
+ <summary>Added in <code>0.6.0</code></summary>
722
+ <table>
723
+ <thead>
724
+ <tr><th>version</th><th>changes</th></tr>
725
+ </thead>
726
+ <tbody>
727
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
728
+ </tbody>
729
+ </table>
730
+ </details>
731
+
732
+ ```grain
733
+ contains : (key: a, map: Map<a, b>) => Bool
734
+ ```
735
+
736
+ Determines if the map contains the given key. In such a case, it will always contain a value for the given key.
737
+
738
+ Parameters:
739
+
740
+ |param|type|description|
741
+ |-----|----|-----------|
742
+ |`key`|`a`|The key to search for|
743
+ |`map`|`Map<a, b>`|The map to search|
744
+
745
+ Returns:
746
+
747
+ |type|description|
748
+ |----|-----------|
749
+ |`Bool`|`true` if the map contains the given key or `false` otherwise|
750
+
751
+ #### Map.Immutable.**remove**
752
+
753
+ <details>
754
+ <summary>Added in <code>0.6.0</code></summary>
755
+ <table>
756
+ <thead>
757
+ <tr><th>version</th><th>changes</th></tr>
758
+ </thead>
759
+ <tbody>
760
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
761
+ </tbody>
762
+ </table>
763
+ </details>
764
+
765
+ ```grain
766
+ remove : (key: a, map: Map<a, b>) => Map<a, b>
767
+ ```
768
+
769
+ Produces a new map without the key-value pair corresponding to the given
770
+ key. If the key doesn't exist in the map, the map will be returned unmodified.
771
+
772
+ Parameters:
773
+
774
+ |param|type|description|
775
+ |-----|----|-----------|
776
+ |`key`|`a`|The key to exclude|
777
+ |`map`|`Map<a, b>`|The map to exclude from|
778
+
779
+ Returns:
780
+
781
+ |type|description|
782
+ |----|-----------|
783
+ |`Map<a, b>`|A new map without the given key|
784
+
785
+ #### Map.Immutable.**update**
786
+
787
+ <details>
788
+ <summary>Added in <code>0.6.0</code></summary>
789
+ <table>
790
+ <thead>
791
+ <tr><th>version</th><th>changes</th></tr>
792
+ </thead>
793
+ <tbody>
794
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
795
+ </tbody>
796
+ </table>
797
+ </details>
798
+
799
+ ```grain
800
+ update : (key: a, fn: (Option<b> => Option<b>), map: Map<a, b>) => Map<a, b>
801
+ ```
802
+
803
+ Produces a new map by calling an updater function that receives the
804
+ previously stored value as an `Option` and returns the new value to be
805
+ stored as an `Option`. If the key didn't exist previously, the value
806
+ will be `None`. If `None` is returned from the updater function, the
807
+ key-value pair is excluded.
808
+
809
+ Parameters:
810
+
811
+ |param|type|description|
812
+ |-----|----|-----------|
813
+ |`key`|`a`|The unique key in the map|
814
+ |`fn`|`Option<b> => Option<b>`|The updater function|
815
+ |`map`|`Map<a, b>`|The base map|
816
+
817
+ Returns:
818
+
819
+ |type|description|
820
+ |----|-----------|
821
+ |`Map<a, b>`|A new map with the value at the given key modified according to the function's output|
822
+
823
+ #### Map.Immutable.**forEach**
824
+
825
+ <details>
826
+ <summary>Added in <code>0.6.0</code></summary>
827
+ <table>
828
+ <thead>
829
+ <tr><th>version</th><th>changes</th></tr>
830
+ </thead>
831
+ <tbody>
832
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
833
+ </tbody>
834
+ </table>
835
+ </details>
836
+
837
+ ```grain
838
+ forEach : (fn: ((a, b) => Void), map: Map<a, b>) => Void
839
+ ```
840
+
841
+ Iterates the map, calling an iterator function with each key and value.
842
+
843
+ Parameters:
844
+
845
+ |param|type|description|
846
+ |-----|----|-----------|
847
+ |`fn`|`(a, b) => Void`|The iterator function to call with each key and value|
848
+ |`map`|`Map<a, b>`|The map to iterate|
849
+
850
+ #### Map.Immutable.**reduce**
851
+
852
+ <details>
853
+ <summary>Added in <code>0.6.0</code></summary>
854
+ <table>
855
+ <thead>
856
+ <tr><th>version</th><th>changes</th></tr>
857
+ </thead>
858
+ <tbody>
859
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
860
+ </tbody>
861
+ </table>
862
+ </details>
863
+
864
+ ```grain
865
+ reduce : (fn: ((a, b, c) => a), init: a, map: Map<b, c>) => a
866
+ ```
867
+
868
+ Combines all key-value pairs of a map using a reducer function.
869
+
870
+ Parameters:
871
+
872
+ |param|type|description|
873
+ |-----|----|-----------|
874
+ |`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|
875
+ |`init`|`a`|The initial value to use for the accumulator on the first iteration|
876
+ |`map`|`Map<b, c>`|The map to iterate|
877
+
878
+ Returns:
879
+
880
+ |type|description|
881
+ |----|-----------|
882
+ |`a`|The final accumulator returned from `fn`|
883
+
884
+ #### Map.Immutable.**keys**
885
+
886
+ <details>
887
+ <summary>Added in <code>0.6.0</code></summary>
888
+ <table>
889
+ <thead>
890
+ <tr><th>version</th><th>changes</th></tr>
891
+ </thead>
892
+ <tbody>
893
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
894
+ </tbody>
895
+ </table>
896
+ </details>
897
+
898
+ ```grain
899
+ keys : (map: Map<a, b>) => List<a>
900
+ ```
901
+
902
+ Enumerates all keys in the given map.
903
+
904
+ Parameters:
905
+
906
+ |param|type|description|
907
+ |-----|----|-----------|
908
+ |`map`|`Map<a, b>`|The map to enumerate|
909
+
910
+ Returns:
911
+
912
+ |type|description|
913
+ |----|-----------|
914
+ |`List<a>`|A list containing all keys from the given map|
915
+
916
+ #### Map.Immutable.**values**
917
+
918
+ <details>
919
+ <summary>Added in <code>0.6.0</code></summary>
920
+ <table>
921
+ <thead>
922
+ <tr><th>version</th><th>changes</th></tr>
923
+ </thead>
924
+ <tbody>
925
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
926
+ </tbody>
927
+ </table>
928
+ </details>
929
+
930
+ ```grain
931
+ values : (map: Map<a, b>) => List<b>
932
+ ```
933
+
934
+ Enumerates all values in the given map.
935
+
936
+ Parameters:
937
+
938
+ |param|type|description|
939
+ |-----|----|-----------|
940
+ |`map`|`Map<a, b>`|The map to enumerate|
941
+
942
+ Returns:
943
+
944
+ |type|description|
945
+ |----|-----------|
946
+ |`List<b>`|A list containing all values from the given map|
947
+
948
+ #### Map.Immutable.**filter**
949
+
950
+ <details>
951
+ <summary>Added in <code>0.6.0</code></summary>
952
+ <table>
953
+ <thead>
954
+ <tr><th>version</th><th>changes</th></tr>
955
+ </thead>
956
+ <tbody>
957
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
958
+ </tbody>
959
+ </table>
960
+ </details>
961
+
962
+ ```grain
963
+ filter : (fn: ((a, b) => Bool), map: Map<a, b>) => Map<a, b>
964
+ ```
965
+
966
+ Produces a new map excluding the key-value pairs where a predicate function returns `false`.
967
+
968
+ Parameters:
969
+
970
+ |param|type|description|
971
+ |-----|----|-----------|
972
+ |`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|
973
+ |`map`|`Map<a, b>`|The map to iterate|
974
+
975
+ Returns:
976
+
977
+ |type|description|
978
+ |----|-----------|
979
+ |`Map<a, b>`|A new map excluding the key-value pairs not fulfilling the predicate|
980
+
981
+ #### Map.Immutable.**reject**
982
+
983
+ <details>
984
+ <summary>Added in <code>0.6.0</code></summary>
985
+ <table>
986
+ <thead>
987
+ <tr><th>version</th><th>changes</th></tr>
988
+ </thead>
989
+ <tbody>
990
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
991
+ </tbody>
992
+ </table>
993
+ </details>
994
+
995
+ ```grain
996
+ reject : (fn: ((a, b) => Bool), map: Map<a, b>) => Map<a, b>
997
+ ```
998
+
999
+ Produces a new map excluding the key-value pairs where a predicate function returns `true`.
1000
+
1001
+ Parameters:
1002
+
1003
+ |param|type|description|
1004
+ |-----|----|-----------|
1005
+ |`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|
1006
+ |`map`|`Map<a, b>`|The map to iterate|
1007
+
1008
+ Returns:
1009
+
1010
+ |type|description|
1011
+ |----|-----------|
1012
+ |`Map<a, b>`|A new map excluding the key-value pairs fulfilling the predicate|
1013
+
1014
+ #### Map.Immutable.**fromList**
1015
+
1016
+ <details>
1017
+ <summary>Added in <code>0.6.0</code></summary>
1018
+ <table>
1019
+ <thead>
1020
+ <tr><th>version</th><th>changes</th></tr>
1021
+ </thead>
1022
+ <tbody>
1023
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
1024
+ </tbody>
1025
+ </table>
1026
+ </details>
1027
+
1028
+ ```grain
1029
+ fromList : (list: List<(a, b)>) => Map<a, b>
1030
+ ```
1031
+
1032
+ Creates a map from a list.
1033
+
1034
+ Parameters:
1035
+
1036
+ |param|type|description|
1037
+ |-----|----|-----------|
1038
+ |`list`|`List<(a, b)>`|The list to convert|
1039
+
1040
+ Returns:
1041
+
1042
+ |type|description|
1043
+ |----|-----------|
1044
+ |`Map<a, b>`|A map containing all key-value pairs from the list|
1045
+
1046
+ #### Map.Immutable.**toList**
1047
+
1048
+ <details>
1049
+ <summary>Added in <code>0.6.0</code></summary>
1050
+ <table>
1051
+ <thead>
1052
+ <tr><th>version</th><th>changes</th></tr>
1053
+ </thead>
1054
+ <tbody>
1055
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
1056
+ </tbody>
1057
+ </table>
1058
+ </details>
1059
+
1060
+ ```grain
1061
+ toList : (map: Map<a, b>) => List<(a, b)>
1062
+ ```
1063
+
1064
+ Enumerates all key-value pairs in the given map.
1065
+
1066
+ Parameters:
1067
+
1068
+ |param|type|description|
1069
+ |-----|----|-----------|
1070
+ |`map`|`Map<a, b>`|The map to enumerate|
1071
+
1072
+ Returns:
1073
+
1074
+ |type|description|
1075
+ |----|-----------|
1076
+ |`List<(a, b)>`|A list containing all key-value pairs from the given map|
1077
+
1078
+ #### Map.Immutable.**fromArray**
1079
+
1080
+ <details>
1081
+ <summary>Added in <code>0.6.0</code></summary>
1082
+ <table>
1083
+ <thead>
1084
+ <tr><th>version</th><th>changes</th></tr>
1085
+ </thead>
1086
+ <tbody>
1087
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
1088
+ </tbody>
1089
+ </table>
1090
+ </details>
1091
+
1092
+ ```grain
1093
+ fromArray : (array: Array<(a, b)>) => Map<a, b>
1094
+ ```
1095
+
1096
+ Creates a map from an array.
1097
+
1098
+ Parameters:
1099
+
1100
+ |param|type|description|
1101
+ |-----|----|-----------|
1102
+ |`array`|`Array<(a, b)>`|The array to convert|
1103
+
1104
+ Returns:
1105
+
1106
+ |type|description|
1107
+ |----|-----------|
1108
+ |`Map<a, b>`|A map containing all key-value pairs from the array|
1109
+
1110
+ #### Map.Immutable.**toArray**
1111
+
1112
+ <details>
1113
+ <summary>Added in <code>0.6.0</code></summary>
1114
+ <table>
1115
+ <thead>
1116
+ <tr><th>version</th><th>changes</th></tr>
1117
+ </thead>
1118
+ <tbody>
1119
+ <tr><td><code>0.5.4</code></td><td>Originally in `"immutablemap"` module</td></tr>
1120
+ </tbody>
1121
+ </table>
1122
+ </details>
1123
+
1124
+ ```grain
1125
+ toArray : (map: Map<a, b>) => Array<(a, b)>
1126
+ ```
1127
+
1128
+ Converts a map into an array of its key-value pairs.
1129
+
1130
+ Parameters:
1131
+
1132
+ |param|type|description|
1133
+ |-----|----|-----------|
1134
+ |`map`|`Map<a, b>`|The map to convert|
1135
+
1136
+ Returns:
1137
+
1138
+ |type|description|
1139
+ |----|-----------|
1140
+ |`Array<(a, b)>`|An array containing all key-value pairs from the given map|
525
1141