@grain/stdlib 0.6.6 → 0.7.1
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 +67 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +606 -560
- package/bigint.md +228 -228
- package/buffer.gr +85 -53
- package/buffer.md +442 -319
- package/bytes.gr +112 -35
- package/bytes.md +299 -219
- package/char.gr +201 -99
- package/char.md +447 -120
- package/exception.gr +11 -11
- package/exception.md +29 -4
- package/float32.gr +327 -3
- package/float32.md +698 -111
- package/float64.gr +320 -3
- package/float64.md +698 -111
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +105 -17
- package/int16.md +178 -178
- package/int32.gr +26 -5
- package/int32.md +266 -231
- package/int64.gr +27 -2
- package/int64.md +266 -231
- package/int8.md +178 -178
- package/json.gr +366 -51
- package/json.md +431 -15
- package/list.gr +328 -31
- package/list.md +759 -336
- package/map.gr +20 -12
- package/map.md +266 -260
- package/marshal.gr +41 -40
- package/marshal.md +14 -14
- package/number.gr +278 -35
- package/number.md +688 -269
- package/option.md +162 -162
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +180 -89
- package/pervasives.gr +2 -2
- package/pervasives.md +275 -275
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +131 -131
- package/queue.gr +183 -29
- package/queue.md +404 -148
- package/random.md +43 -43
- package/range.gr +4 -4
- package/range.md +42 -42
- package/rational.md +123 -123
- package/regex.gr +52 -51
- package/regex.md +102 -102
- package/result.md +118 -118
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +14 -14
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +8 -8
- package/runtime/dataStructures.md +211 -211
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +8 -8
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +13 -13
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +348 -342
- package/runtime/string.gr +37 -105
- package/runtime/string.md +20 -26
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +19 -19
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +147 -147
- package/set.gr +18 -11
- package/set.md +253 -247
- package/stack.gr +171 -2
- package/stack.md +371 -89
- package/string.gr +352 -557
- package/string.md +298 -255
- package/uint16.md +170 -170
- package/uint32.gr +25 -4
- package/uint32.md +249 -214
- package/uint64.gr +25 -5
- package/uint64.md +249 -214
- package/uint8.md +170 -170
- package/uri.gr +57 -53
- package/uri.md +88 -89
- package/wasi/file.gr +67 -59
- package/wasi/file.md +308 -308
- package/wasi/process.md +26 -26
- package/wasi/random.md +12 -12
- package/wasi/time.md +16 -16
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/result.md
CHANGED
|
@@ -36,22 +36,22 @@ No other changes yet.
|
|
|
36
36
|
</details>
|
|
37
37
|
|
|
38
38
|
```grain
|
|
39
|
-
isOk
|
|
39
|
+
isOk: (result: Result<a, b>) => Bool
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Checks if the Result is the `Ok` variant.
|
|
43
43
|
|
|
44
44
|
Parameters:
|
|
45
45
|
|
|
46
|
-
|param|type|description|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
| param | type | description |
|
|
47
|
+
| -------- | -------------- | ------------------- |
|
|
48
|
+
| `result` | `Result<a, b>` | The result to check |
|
|
49
49
|
|
|
50
50
|
Returns:
|
|
51
51
|
|
|
52
|
-
|type|description|
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
| type | description |
|
|
53
|
+
| ------ | ------------------------------------------------------------- |
|
|
54
|
+
| `Bool` | `true` if the Result is the `Ok` variant or `false` otherwise |
|
|
55
55
|
|
|
56
56
|
### Result.**isErr**
|
|
57
57
|
|
|
@@ -61,22 +61,22 @@ No other changes yet.
|
|
|
61
61
|
</details>
|
|
62
62
|
|
|
63
63
|
```grain
|
|
64
|
-
isErr
|
|
64
|
+
isErr: (result: Result<a, b>) => Bool
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
Checks if the Result is the `Err` variant.
|
|
68
68
|
|
|
69
69
|
Parameters:
|
|
70
70
|
|
|
71
|
-
|param|type|description|
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
| param | type | description |
|
|
72
|
+
| -------- | -------------- | ------------------- |
|
|
73
|
+
| `result` | `Result<a, b>` | The result to check |
|
|
74
74
|
|
|
75
75
|
Returns:
|
|
76
76
|
|
|
77
|
-
|type|description|
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
| type | description |
|
|
78
|
+
| ------ | -------------------------------------------------------------- |
|
|
79
|
+
| `Bool` | `true` if the Result is the `Err` variant or `false` otherwise |
|
|
80
80
|
|
|
81
81
|
### Result.**toOption**
|
|
82
82
|
|
|
@@ -86,22 +86,22 @@ No other changes yet.
|
|
|
86
86
|
</details>
|
|
87
87
|
|
|
88
88
|
```grain
|
|
89
|
-
toOption
|
|
89
|
+
toOption: (result: Result<a, b>) => Option<a>
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
Converts the Result to an Option. An error value is discarded and replaced with `None`.
|
|
93
93
|
|
|
94
94
|
Parameters:
|
|
95
95
|
|
|
96
|
-
|param|type|description|
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
| param | type | description |
|
|
97
|
+
| -------- | -------------- | --------------------- |
|
|
98
|
+
| `result` | `Result<a, b>` | The result to convert |
|
|
99
99
|
|
|
100
100
|
Returns:
|
|
101
101
|
|
|
102
|
-
|type|description|
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
| type | description |
|
|
103
|
+
| ----------- | ------------------------------------------------------------------------------ |
|
|
104
|
+
| `Option<a>` | `Some(value)` if the Result is `Ok(value)` or `None` if the Result is an `Err` |
|
|
105
105
|
|
|
106
106
|
### Result.**flatMap**
|
|
107
107
|
|
|
@@ -111,23 +111,23 @@ No other changes yet.
|
|
|
111
111
|
</details>
|
|
112
112
|
|
|
113
113
|
```grain
|
|
114
|
-
flatMap
|
|
114
|
+
flatMap: (fn: (a => Result<b, c>), result: Result<a, c>) => Result<b, c>
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
If the Result is `Ok(value)`, applies the given function to the `value` to produce a new Result.
|
|
118
118
|
|
|
119
119
|
Parameters:
|
|
120
120
|
|
|
121
|
-
|param|type|description|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
| param | type | description |
|
|
122
|
+
| -------- | ------------------- | ---------------------------------------------------- |
|
|
123
|
+
| `fn` | `a => Result<b, c>` | The function to call on the value of an `Ok` variant |
|
|
124
|
+
| `result` | `Result<a, c>` | The result to map |
|
|
125
125
|
|
|
126
126
|
Returns:
|
|
127
127
|
|
|
128
|
-
|type|description|
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
| type | description |
|
|
129
|
+
| -------------- | ------------------------------------------------------------------------------------------------------- |
|
|
130
|
+
| `Result<b, c>` | A new Result produced by the mapping function if the variant was `Ok` or the unmodified `Err` otherwise |
|
|
131
131
|
|
|
132
132
|
### Result.**flatMapErr**
|
|
133
133
|
|
|
@@ -137,23 +137,23 @@ No other changes yet.
|
|
|
137
137
|
</details>
|
|
138
138
|
|
|
139
139
|
```grain
|
|
140
|
-
flatMapErr
|
|
140
|
+
flatMapErr: (fn: (a => Result<b, c>), result: Result<b, a>) => Result<b, c>
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
If the Result is an `Err(value)`, applies the given function to the `value` to produce a new Result.
|
|
144
144
|
|
|
145
145
|
Parameters:
|
|
146
146
|
|
|
147
|
-
|param|type|description|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
| param | type | description |
|
|
148
|
+
| -------- | ------------------- | ----------------------------------------------------- |
|
|
149
|
+
| `fn` | `a => Result<b, c>` | The function to call on the value of an `Err` variant |
|
|
150
|
+
| `result` | `Result<b, a>` | The result to map |
|
|
151
151
|
|
|
152
152
|
Returns:
|
|
153
153
|
|
|
154
|
-
|type|description|
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
| type | description |
|
|
155
|
+
| -------------- | ------------------------------------------------------------------------------------------------------- |
|
|
156
|
+
| `Result<b, c>` | A new Result produced by the mapping function if the variant was `Err` or the unmodified `Ok` otherwise |
|
|
157
157
|
|
|
158
158
|
### Result.**map**
|
|
159
159
|
|
|
@@ -163,23 +163,23 @@ No other changes yet.
|
|
|
163
163
|
</details>
|
|
164
164
|
|
|
165
165
|
```grain
|
|
166
|
-
map
|
|
166
|
+
map: (fn: (a => b), result: Result<a, c>) => Result<b, c>
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
If the Result is `Ok(value)`, applies the given function to the `value` and wraps the new value in an `Ok` variant.
|
|
170
170
|
|
|
171
171
|
Parameters:
|
|
172
172
|
|
|
173
|
-
|param|type|description|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
| param | type | description |
|
|
174
|
+
| -------- | -------------- | ---------------------------------------------------- |
|
|
175
|
+
| `fn` | `a => b` | The function to call on the value of an `Ok` variant |
|
|
176
|
+
| `result` | `Result<a, c>` | The result to map |
|
|
177
177
|
|
|
178
178
|
Returns:
|
|
179
179
|
|
|
180
|
-
|type|description|
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
| type | description |
|
|
181
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
182
|
+
| `Result<b, c>` | A new `Ok` variant produced by the mapping function if the variant was `Ok` or the unmodified `Err` otherwise |
|
|
183
183
|
|
|
184
184
|
### Result.**mapErr**
|
|
185
185
|
|
|
@@ -189,23 +189,23 @@ No other changes yet.
|
|
|
189
189
|
</details>
|
|
190
190
|
|
|
191
191
|
```grain
|
|
192
|
-
mapErr
|
|
192
|
+
mapErr: (fn: (a => b), result: Result<c, a>) => Result<c, b>
|
|
193
193
|
```
|
|
194
194
|
|
|
195
195
|
If the Result is `Err(value)`, applies the given function to the `value` and wraps the new value in an `Err` variant.
|
|
196
196
|
|
|
197
197
|
Parameters:
|
|
198
198
|
|
|
199
|
-
|param|type|description|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
| param | type | description |
|
|
200
|
+
| -------- | -------------- | ----------------------------------------------------- |
|
|
201
|
+
| `fn` | `a => b` | The function to call on the value of an `Err` variant |
|
|
202
|
+
| `result` | `Result<c, a>` | The result to map |
|
|
203
203
|
|
|
204
204
|
Returns:
|
|
205
205
|
|
|
206
|
-
|type|description|
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
| type | description |
|
|
207
|
+
| -------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
208
|
+
| `Result<c, b>` | A new `Err` variant produced by the mapping function if the variant was `Err` or the unmodified `Ok` otherwise |
|
|
209
209
|
|
|
210
210
|
### Result.**mapWithDefault**
|
|
211
211
|
|
|
@@ -215,7 +215,7 @@ No other changes yet.
|
|
|
215
215
|
</details>
|
|
216
216
|
|
|
217
217
|
```grain
|
|
218
|
-
mapWithDefault
|
|
218
|
+
mapWithDefault: (fn: (a => b), def: b, result: Result<a, c>) => b
|
|
219
219
|
```
|
|
220
220
|
|
|
221
221
|
If the Result is `Ok(value)`, applies the given function to the `value` to produce a new value, otherwise uses the default value.
|
|
@@ -223,17 +223,17 @@ Useful for unwrapping a successful Result while providing a fallback for any err
|
|
|
223
223
|
|
|
224
224
|
Parameters:
|
|
225
225
|
|
|
226
|
-
|param|type|description|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
| param | type | description |
|
|
227
|
+
| -------- | -------------- | ---------------------------------------------------- |
|
|
228
|
+
| `fn` | `a => b` | The function to call on the value of an `Ok` variant |
|
|
229
|
+
| `def` | `b` | A fallback value for an `Err` variant |
|
|
230
|
+
| `result` | `Result<a, c>` | The result to map |
|
|
231
231
|
|
|
232
232
|
Returns:
|
|
233
233
|
|
|
234
|
-
|type|description|
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
| type | description |
|
|
235
|
+
| ---- | -------------------------------------------------------------------------------------------------------------- |
|
|
236
|
+
| `b` | The value produced by the mapping function if the result is of the `Ok` variant or the default value otherwise |
|
|
237
237
|
|
|
238
238
|
### Result.**mapWithDefaultFn**
|
|
239
239
|
|
|
@@ -243,7 +243,7 @@ No other changes yet.
|
|
|
243
243
|
</details>
|
|
244
244
|
|
|
245
245
|
```grain
|
|
246
|
-
mapWithDefaultFn
|
|
246
|
+
mapWithDefaultFn:
|
|
247
247
|
(fnOk: (a => b), fnErr: (c => b), result: Result<a, c>) => b
|
|
248
248
|
```
|
|
249
249
|
|
|
@@ -253,17 +253,17 @@ Useful for unwrapping a Result into a value, whether it is successful or unsucce
|
|
|
253
253
|
|
|
254
254
|
Parameters:
|
|
255
255
|
|
|
256
|
-
|param|type|description|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
| param | type | description |
|
|
257
|
+
| -------- | -------------- | ----------------------------------------------------- |
|
|
258
|
+
| `fnOk` | `a => b` | The function to call on the value of an `Ok` variant |
|
|
259
|
+
| `fnErr` | `c => b` | The function to call on the value of an `Err` variant |
|
|
260
|
+
| `result` | `Result<a, c>` | The result to map |
|
|
261
261
|
|
|
262
262
|
Returns:
|
|
263
263
|
|
|
264
|
-
|type|description|
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
| type | description |
|
|
265
|
+
| ---- | -------------------------------------------------- |
|
|
266
|
+
| `b` | The value produced by one of the mapping functions |
|
|
267
267
|
|
|
268
268
|
### Result.**(||)**
|
|
269
269
|
|
|
@@ -280,23 +280,23 @@ Returns:
|
|
|
280
280
|
</details>
|
|
281
281
|
|
|
282
282
|
```grain
|
|
283
|
-
(||)
|
|
283
|
+
(||): (result1: Result<a, b>, result2: Result<a, b>) => Result<a, b>
|
|
284
284
|
```
|
|
285
285
|
|
|
286
286
|
Behaves like a logical OR (`||`) where the first Result is only returned if it is the `Ok` variant and falling back to the second Result in all other cases.
|
|
287
287
|
|
|
288
288
|
Parameters:
|
|
289
289
|
|
|
290
|
-
|param|type|description|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
| param | type | description |
|
|
291
|
+
| --------- | -------------- | ----------------- |
|
|
292
|
+
| `result1` | `Result<a, b>` | The first result |
|
|
293
|
+
| `result2` | `Result<a, b>` | The second result |
|
|
294
294
|
|
|
295
295
|
Returns:
|
|
296
296
|
|
|
297
|
-
|type|description|
|
|
298
|
-
|
|
299
|
-
|
|
297
|
+
| type | description |
|
|
298
|
+
| -------------- | ------------------------------------------------------------------------- |
|
|
299
|
+
| `Result<a, b>` | The first Result if it is the `Ok` variant or the second Result otherwise |
|
|
300
300
|
|
|
301
301
|
### Result.**(&&)**
|
|
302
302
|
|
|
@@ -313,23 +313,23 @@ Returns:
|
|
|
313
313
|
</details>
|
|
314
314
|
|
|
315
315
|
```grain
|
|
316
|
-
(&&)
|
|
316
|
+
(&&): (result1: Result<a, b>, result2: Result<a, b>) => Result<a, b>
|
|
317
317
|
```
|
|
318
318
|
|
|
319
319
|
Behaves like a logical AND (`&&`) where the first Result is only returned if it is the `Err` variant and falling back to the second Result in all other cases.
|
|
320
320
|
|
|
321
321
|
Parameters:
|
|
322
322
|
|
|
323
|
-
|param|type|description|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
323
|
+
| param | type | description |
|
|
324
|
+
| --------- | -------------- | ----------------- |
|
|
325
|
+
| `result1` | `Result<a, b>` | The first result |
|
|
326
|
+
| `result2` | `Result<a, b>` | The second result |
|
|
327
327
|
|
|
328
328
|
Returns:
|
|
329
329
|
|
|
330
|
-
|type|description|
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
| type | description |
|
|
331
|
+
| -------------- | ---------------------------------------------------------------------------- |
|
|
332
|
+
| `Result<a, b>` | The second Result if both are the `Ok` variant or the first Result otherwise |
|
|
333
333
|
|
|
334
334
|
### Result.**peek**
|
|
335
335
|
|
|
@@ -339,7 +339,7 @@ No other changes yet.
|
|
|
339
339
|
</details>
|
|
340
340
|
|
|
341
341
|
```grain
|
|
342
|
-
peek
|
|
342
|
+
peek: (fnOk: (a => b), fnErr: (c => d), result: Result<a, c>) => Void
|
|
343
343
|
```
|
|
344
344
|
|
|
345
345
|
If the Result is `Ok(value)`, applies the `fnOk` function to the `value` without producing a new value.
|
|
@@ -348,11 +348,11 @@ Useful for inspecting Results without changing anything.
|
|
|
348
348
|
|
|
349
349
|
Parameters:
|
|
350
350
|
|
|
351
|
-
|param|type|description|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
351
|
+
| param | type | description |
|
|
352
|
+
| -------- | -------------- | ----------------------------------------------------- |
|
|
353
|
+
| `fnOk` | `a => b` | The function to call on the value of an `Ok` variant |
|
|
354
|
+
| `fnErr` | `c => d` | The function to call on the value of an `Err` variant |
|
|
355
|
+
| `result` | `Result<a, c>` | The result to inspect |
|
|
356
356
|
|
|
357
357
|
### Result.**peekOk**
|
|
358
358
|
|
|
@@ -362,17 +362,17 @@ No other changes yet.
|
|
|
362
362
|
</details>
|
|
363
363
|
|
|
364
364
|
```grain
|
|
365
|
-
peekOk
|
|
365
|
+
peekOk: (fn: (a => b), result: Result<a, c>) => Void
|
|
366
366
|
```
|
|
367
367
|
|
|
368
368
|
If the Result is `Ok(value)`, applies the given function to the `value` without producing a new value.
|
|
369
369
|
|
|
370
370
|
Parameters:
|
|
371
371
|
|
|
372
|
-
|param|type|description|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
372
|
+
| param | type | description |
|
|
373
|
+
| -------- | -------------- | ---------------------------------------------------- |
|
|
374
|
+
| `fn` | `a => b` | The function to call on the value of an `Ok` variant |
|
|
375
|
+
| `result` | `Result<a, c>` | The result to inspect |
|
|
376
376
|
|
|
377
377
|
### Result.**peekErr**
|
|
378
378
|
|
|
@@ -382,17 +382,17 @@ No other changes yet.
|
|
|
382
382
|
</details>
|
|
383
383
|
|
|
384
384
|
```grain
|
|
385
|
-
peekErr
|
|
385
|
+
peekErr: (fn: (a => b), result: Result<c, a>) => Void
|
|
386
386
|
```
|
|
387
387
|
|
|
388
388
|
If the Result is `Err(value)`, applies the given function to the `value` without producing a new value.
|
|
389
389
|
|
|
390
390
|
Parameters:
|
|
391
391
|
|
|
392
|
-
|param|type|description|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
392
|
+
| param | type | description |
|
|
393
|
+
| -------- | -------------- | ----------------------------------------------------- |
|
|
394
|
+
| `fn` | `a => b` | The function to call on the value of an `Err` variant |
|
|
395
|
+
| `result` | `Result<c, a>` | The result to inspect |
|
|
396
396
|
|
|
397
397
|
### Result.**expect**
|
|
398
398
|
|
|
@@ -402,7 +402,7 @@ No other changes yet.
|
|
|
402
402
|
</details>
|
|
403
403
|
|
|
404
404
|
```grain
|
|
405
|
-
expect
|
|
405
|
+
expect: (msg: String, result: Result<a, b>) => a
|
|
406
406
|
```
|
|
407
407
|
|
|
408
408
|
Extracts the value inside an `Ok` result, otherwise throw an
|
|
@@ -410,16 +410,16 @@ exception containing the message and contents of the `Err`.
|
|
|
410
410
|
|
|
411
411
|
Parameters:
|
|
412
412
|
|
|
413
|
-
|param|type|description|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
413
|
+
| param | type | description |
|
|
414
|
+
| -------- | -------------- | ------------------------------------------------------ |
|
|
415
|
+
| `msg` | `String` | The message to prepend if the result contains an `Err` |
|
|
416
|
+
| `result` | `Result<a, b>` | The result to extract a value from |
|
|
417
417
|
|
|
418
418
|
Returns:
|
|
419
419
|
|
|
420
|
-
|type|description|
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
| type | description |
|
|
421
|
+
| ---- | ----------------------------------------------------- |
|
|
422
|
+
| `a` | The unwrapped value if the Result is the `Ok` variant |
|
|
423
423
|
|
|
424
424
|
Throws:
|
|
425
425
|
|
|
@@ -441,7 +441,7 @@ No other changes yet.
|
|
|
441
441
|
</details>
|
|
442
442
|
|
|
443
443
|
```grain
|
|
444
|
-
unwrap
|
|
444
|
+
unwrap: (result: Result<a, b>) => a
|
|
445
445
|
```
|
|
446
446
|
|
|
447
447
|
Extracts the value inside an `Ok` result, otherwise throw an
|
|
@@ -449,15 +449,15 @@ exception containing a default message and contents of the `Err`.
|
|
|
449
449
|
|
|
450
450
|
Parameters:
|
|
451
451
|
|
|
452
|
-
|param|type|description|
|
|
453
|
-
|
|
454
|
-
|
|
452
|
+
| param | type | description |
|
|
453
|
+
| -------- | -------------- | ---------------------------------- |
|
|
454
|
+
| `result` | `Result<a, b>` | The result to extract a value from |
|
|
455
455
|
|
|
456
456
|
Returns:
|
|
457
457
|
|
|
458
|
-
|type|description|
|
|
459
|
-
|
|
460
|
-
|
|
458
|
+
| type | description |
|
|
459
|
+
| ---- | ----------------------------------------------------- |
|
|
460
|
+
| `a` | The unwrapped value if the result is the `Ok` variant |
|
|
461
461
|
|
|
462
462
|
Throws:
|
|
463
463
|
|