happy-rusty 1.2.0 → 1.3.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.
- package/dist/main.cjs +24 -14
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +21 -14
- package/dist/main.mjs.map +1 -1
- package/dist/types.d.ts +79 -53
- package/docs/README.md +4 -1
- package/docs/functions/Err.md +1 -1
- package/docs/functions/Ok.md +1 -1
- package/docs/functions/Some.md +1 -1
- package/docs/functions/isOption.md +1 -1
- package/docs/functions/isResult.md +1 -1
- package/docs/functions/{promiseToResult.md → promiseToAsyncResult.md} +5 -5
- package/docs/interfaces/None.md +28 -28
- package/docs/interfaces/Option.md +27 -27
- package/docs/interfaces/Result.md +29 -29
- package/docs/type-aliases/AsyncIOResult.md +2 -2
- package/docs/type-aliases/AsyncOption.md +1 -1
- package/docs/type-aliases/AsyncResult.md +1 -1
- package/docs/type-aliases/IOResult.md +1 -1
- package/docs/variables/None.md +1 -1
- package/docs/variables/RESULT_FALSE.md +18 -0
- package/docs/variables/RESULT_TRUE.md +18 -0
- package/docs/variables/RESULT_ZERO.md +18 -0
- package/package.json +1 -1
- package/src/enum/constants.ts +25 -0
- package/src/enum/core.ts +569 -0
- package/src/enum/defines.ts +38 -0
- package/src/enum/extensions.ts +31 -0
- package/src/enum/helpers.ts +27 -0
- package/src/enum/mod.ts +6 -0
- package/src/enum/prelude.ts +8 -673
- package/src/enum/symbols.ts +9 -0
- package/src/mod.ts +1 -15
|
@@ -31,7 +31,7 @@ pub enum Option<T> {
|
|
|
31
31
|
|
|
32
32
|
| Property | Type | Description | Defined in |
|
|
33
33
|
| ------ | ------ | ------ | ------ |
|
|
34
|
-
| `[toStringTag]` | `"Option"` | [object Option]. | [
|
|
34
|
+
| `[toStringTag]` | `"Option"` | [object Option]. | [core.ts:30](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L30) |
|
|
35
35
|
|
|
36
36
|
## Methods
|
|
37
37
|
|
|
@@ -64,7 +64,7 @@ This is sometimes called "and then" because it is similar to a logical AND opera
|
|
|
64
64
|
|
|
65
65
|
#### Defined in
|
|
66
66
|
|
|
67
|
-
[
|
|
67
|
+
[core.ts:220](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L220)
|
|
68
68
|
|
|
69
69
|
***
|
|
70
70
|
|
|
@@ -97,7 +97,7 @@ The result of `fn` if `this` is `Some`, otherwise `None`.
|
|
|
97
97
|
|
|
98
98
|
#### Defined in
|
|
99
99
|
|
|
100
|
-
[
|
|
100
|
+
[core.ts:229](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L229)
|
|
101
101
|
|
|
102
102
|
***
|
|
103
103
|
|
|
@@ -124,7 +124,7 @@ This method can be used for comparing `Option` instances in a value-sensitive ma
|
|
|
124
124
|
|
|
125
125
|
#### Defined in
|
|
126
126
|
|
|
127
|
-
[
|
|
127
|
+
[core.ts:273](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L273)
|
|
128
128
|
|
|
129
129
|
***
|
|
130
130
|
|
|
@@ -152,7 +152,7 @@ Throws an error with the provided message if the Option is a `None`.
|
|
|
152
152
|
|
|
153
153
|
#### Defined in
|
|
154
154
|
|
|
155
|
-
[
|
|
155
|
+
[core.ts:76](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L76)
|
|
156
156
|
|
|
157
157
|
***
|
|
158
158
|
|
|
@@ -178,7 +178,7 @@ Returns `None` if the Option is `None`, otherwise calls predicate with the wrapp
|
|
|
178
178
|
|
|
179
179
|
#### Defined in
|
|
180
180
|
|
|
181
|
-
[
|
|
181
|
+
[core.ts:138](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L138)
|
|
182
182
|
|
|
183
183
|
***
|
|
184
184
|
|
|
@@ -210,7 +210,7 @@ Converts from `Option<Option<T>>` to `Option<T>`.
|
|
|
210
210
|
|
|
211
211
|
#### Defined in
|
|
212
212
|
|
|
213
|
-
[
|
|
213
|
+
[core.ts:144](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L144)
|
|
214
214
|
|
|
215
215
|
***
|
|
216
216
|
|
|
@@ -237,7 +237,7 @@ This is primarily for side effects and does not transform the `Option`.
|
|
|
237
237
|
|
|
238
238
|
#### Defined in
|
|
239
239
|
|
|
240
|
-
[
|
|
240
|
+
[core.ts:263](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L263)
|
|
241
241
|
|
|
242
242
|
***
|
|
243
243
|
|
|
@@ -255,7 +255,7 @@ Returns `true` if the Option is a `None` value.
|
|
|
255
255
|
|
|
256
256
|
#### Defined in
|
|
257
257
|
|
|
258
|
-
[
|
|
258
|
+
[core.ts:55](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L55)
|
|
259
259
|
|
|
260
260
|
***
|
|
261
261
|
|
|
@@ -273,7 +273,7 @@ Returns `true` if the Option is a `Some` value.
|
|
|
273
273
|
|
|
274
274
|
#### Defined in
|
|
275
275
|
|
|
276
|
-
[
|
|
276
|
+
[core.ts:50](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L50)
|
|
277
277
|
|
|
278
278
|
***
|
|
279
279
|
|
|
@@ -297,7 +297,7 @@ Returns `true` if the Option is a `Some` value and the predicate returns `true`
|
|
|
297
297
|
|
|
298
298
|
#### Defined in
|
|
299
299
|
|
|
300
|
-
[
|
|
300
|
+
[core.ts:61](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L61)
|
|
301
301
|
|
|
302
302
|
***
|
|
303
303
|
|
|
@@ -327,7 +327,7 @@ Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
|
|
|
327
327
|
|
|
328
328
|
#### Defined in
|
|
329
329
|
|
|
330
|
-
[
|
|
330
|
+
[core.ts:151](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L151)
|
|
331
331
|
|
|
332
332
|
***
|
|
333
333
|
|
|
@@ -358,7 +358,7 @@ Maps an `Option<T>` to `U` by applying a function to the contained value (if any
|
|
|
358
358
|
|
|
359
359
|
#### Defined in
|
|
360
360
|
|
|
361
|
-
[
|
|
361
|
+
[core.ts:159](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L159)
|
|
362
362
|
|
|
363
363
|
***
|
|
364
364
|
|
|
@@ -389,7 +389,7 @@ Maps an `Option<T>` to `U` by applying a function to a contained value (if any),
|
|
|
389
389
|
|
|
390
390
|
#### Defined in
|
|
391
391
|
|
|
392
|
-
[
|
|
392
|
+
[core.ts:167](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L167)
|
|
393
393
|
|
|
394
394
|
***
|
|
395
395
|
|
|
@@ -419,7 +419,7 @@ Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` a
|
|
|
419
419
|
|
|
420
420
|
#### Defined in
|
|
421
421
|
|
|
422
|
-
[
|
|
422
|
+
[core.ts:109](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L109)
|
|
423
423
|
|
|
424
424
|
***
|
|
425
425
|
|
|
@@ -449,7 +449,7 @@ Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` a
|
|
|
449
449
|
|
|
450
450
|
#### Defined in
|
|
451
451
|
|
|
452
|
-
[
|
|
452
|
+
[core.ts:116](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L116)
|
|
453
453
|
|
|
454
454
|
***
|
|
455
455
|
|
|
@@ -476,7 +476,7 @@ This can be used for providing a fallback `Option`.
|
|
|
476
476
|
|
|
477
477
|
#### Defined in
|
|
478
478
|
|
|
479
|
-
[
|
|
479
|
+
[core.ts:237](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L237)
|
|
480
480
|
|
|
481
481
|
***
|
|
482
482
|
|
|
@@ -503,7 +503,7 @@ This method can be used for lazy fallbacks, as `fn` is only evaluated if `this`
|
|
|
503
503
|
|
|
504
504
|
#### Defined in
|
|
505
505
|
|
|
506
|
-
[
|
|
506
|
+
[core.ts:245](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L245)
|
|
507
507
|
|
|
508
508
|
***
|
|
509
509
|
|
|
@@ -521,7 +521,7 @@ Custom `toString` implementation that uses the `Option`'s contained value.
|
|
|
521
521
|
|
|
522
522
|
#### Defined in
|
|
523
523
|
|
|
524
|
-
[
|
|
524
|
+
[core.ts:280](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L280)
|
|
525
525
|
|
|
526
526
|
***
|
|
527
527
|
|
|
@@ -556,7 +556,7 @@ Transposes an `Option` of a `Result` into a `Result` of an `Option`.
|
|
|
556
556
|
|
|
557
557
|
#### Defined in
|
|
558
558
|
|
|
559
|
-
[
|
|
559
|
+
[core.ts:126](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L126)
|
|
560
560
|
|
|
561
561
|
***
|
|
562
562
|
|
|
@@ -578,7 +578,7 @@ Throws an error if the value is a `None`.
|
|
|
578
578
|
|
|
579
579
|
#### Defined in
|
|
580
580
|
|
|
581
|
-
[
|
|
581
|
+
[core.ts:82](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L82)
|
|
582
582
|
|
|
583
583
|
***
|
|
584
584
|
|
|
@@ -602,7 +602,7 @@ Returns the contained `Some` value or a provided default.
|
|
|
602
602
|
|
|
603
603
|
#### Defined in
|
|
604
604
|
|
|
605
|
-
[
|
|
605
|
+
[core.ts:88](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L88)
|
|
606
606
|
|
|
607
607
|
***
|
|
608
608
|
|
|
@@ -626,7 +626,7 @@ Returns the contained `Some` value or computes it from a closure.
|
|
|
626
626
|
|
|
627
627
|
#### Defined in
|
|
628
628
|
|
|
629
|
-
[
|
|
629
|
+
[core.ts:94](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L94)
|
|
630
630
|
|
|
631
631
|
***
|
|
632
632
|
|
|
@@ -661,7 +661,7 @@ A tuple of `Options`, one for each element in the original `Option` of a tuple.
|
|
|
661
661
|
|
|
662
662
|
#### Defined in
|
|
663
663
|
|
|
664
|
-
[
|
|
664
|
+
[core.ts:203](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L203)
|
|
665
665
|
|
|
666
666
|
***
|
|
667
667
|
|
|
@@ -688,7 +688,7 @@ This can be thought of as an exclusive or operation on `Option` values.
|
|
|
688
688
|
|
|
689
689
|
#### Defined in
|
|
690
690
|
|
|
691
|
-
[
|
|
691
|
+
[core.ts:253](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L253)
|
|
692
692
|
|
|
693
693
|
***
|
|
694
694
|
|
|
@@ -722,7 +722,7 @@ An `Option` containing a tuple of the values if both are `Some`, otherwise `None
|
|
|
722
722
|
|
|
723
723
|
#### Defined in
|
|
724
724
|
|
|
725
|
-
[
|
|
725
|
+
[core.ts:181](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L181)
|
|
726
726
|
|
|
727
727
|
***
|
|
728
728
|
|
|
@@ -758,4 +758,4 @@ An `Option` containing the result of `fn` if both `Options` are `Some`, otherwis
|
|
|
758
758
|
|
|
759
759
|
#### Defined in
|
|
760
760
|
|
|
761
|
-
[
|
|
761
|
+
[core.ts:193](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L193)
|
|
@@ -29,7 +29,7 @@ pub enum Result<T, E> {
|
|
|
29
29
|
|
|
30
30
|
| Property | Type | Description | Defined in |
|
|
31
31
|
| ------ | ------ | ------ | ------ |
|
|
32
|
-
| `[toStringTag]` | `"Result"` | [object Result]. | [
|
|
32
|
+
| `[toStringTag]` | `"Result"` | [object Result]. | [core.ts:304](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L304) |
|
|
33
33
|
|
|
34
34
|
## Methods
|
|
35
35
|
|
|
@@ -61,7 +61,7 @@ The passed `Result` if `this` is `Ok`, otherwise returns `this` (which is `Err`)
|
|
|
61
61
|
|
|
62
62
|
#### Defined in
|
|
63
63
|
|
|
64
|
-
[
|
|
64
|
+
[core.ts:489](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L489)
|
|
65
65
|
|
|
66
66
|
***
|
|
67
67
|
|
|
@@ -93,7 +93,7 @@ The result of `fn` if `this` is `Ok`, otherwise `this` as `Err`.
|
|
|
93
93
|
|
|
94
94
|
#### Defined in
|
|
95
95
|
|
|
96
|
-
[
|
|
96
|
+
[core.ts:505](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L505)
|
|
97
97
|
|
|
98
98
|
***
|
|
99
99
|
|
|
@@ -122,7 +122,7 @@ Just same as `result as unknown as Result<U, E>`.
|
|
|
122
122
|
|
|
123
123
|
#### Defined in
|
|
124
124
|
|
|
125
|
-
[
|
|
125
|
+
[core.ts:563](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L563)
|
|
126
126
|
|
|
127
127
|
***
|
|
128
128
|
|
|
@@ -150,7 +150,7 @@ Just same as `result as unknown as Result<T, F>`.
|
|
|
150
150
|
|
|
151
151
|
#### Defined in
|
|
152
152
|
|
|
153
|
-
[
|
|
153
|
+
[core.ts:552](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L552)
|
|
154
154
|
|
|
155
155
|
***
|
|
156
156
|
|
|
@@ -176,7 +176,7 @@ Tests whether `this` and `other` are both `Ok` containing equal values, or both
|
|
|
176
176
|
|
|
177
177
|
#### Defined in
|
|
178
178
|
|
|
179
|
-
[
|
|
179
|
+
[core.ts:540](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L540)
|
|
180
180
|
|
|
181
181
|
***
|
|
182
182
|
|
|
@@ -196,7 +196,7 @@ If the result is `Ok`, returns `None`.
|
|
|
196
196
|
|
|
197
197
|
#### Defined in
|
|
198
198
|
|
|
199
|
-
[
|
|
199
|
+
[core.ts:413](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L413)
|
|
200
200
|
|
|
201
201
|
***
|
|
202
202
|
|
|
@@ -224,7 +224,7 @@ Throws an error with the provided message if the result is an `Err`.
|
|
|
224
224
|
|
|
225
225
|
#### Defined in
|
|
226
226
|
|
|
227
|
-
[
|
|
227
|
+
[core.ts:356](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L356)
|
|
228
228
|
|
|
229
229
|
***
|
|
230
230
|
|
|
@@ -252,7 +252,7 @@ Throws an error with the provided message if the result is an `Ok`.
|
|
|
252
252
|
|
|
253
253
|
#### Defined in
|
|
254
254
|
|
|
255
|
-
[
|
|
255
|
+
[core.ts:385](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L385)
|
|
256
256
|
|
|
257
257
|
***
|
|
258
258
|
|
|
@@ -284,7 +284,7 @@ If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.
|
|
|
284
284
|
|
|
285
285
|
#### Defined in
|
|
286
286
|
|
|
287
|
-
[
|
|
287
|
+
[core.ts:473](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L473)
|
|
288
288
|
|
|
289
289
|
***
|
|
290
290
|
|
|
@@ -311,7 +311,7 @@ Does not modify the `Result`.
|
|
|
311
311
|
|
|
312
312
|
#### Defined in
|
|
313
313
|
|
|
314
|
-
[
|
|
314
|
+
[core.ts:523](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L523)
|
|
315
315
|
|
|
316
316
|
***
|
|
317
317
|
|
|
@@ -338,7 +338,7 @@ Does not modify the `Result`.
|
|
|
338
338
|
|
|
339
339
|
#### Defined in
|
|
340
340
|
|
|
341
|
-
[
|
|
341
|
+
[core.ts:531](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L531)
|
|
342
342
|
|
|
343
343
|
***
|
|
344
344
|
|
|
@@ -356,7 +356,7 @@ Returns `true` if the result is `Err`.
|
|
|
356
356
|
|
|
357
357
|
#### Defined in
|
|
358
358
|
|
|
359
|
-
[
|
|
359
|
+
[core.ts:329](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L329)
|
|
360
360
|
|
|
361
361
|
***
|
|
362
362
|
|
|
@@ -380,7 +380,7 @@ Returns `true` if the result is `Err` and the provided predicate returns `true`
|
|
|
380
380
|
|
|
381
381
|
#### Defined in
|
|
382
382
|
|
|
383
|
-
[
|
|
383
|
+
[core.ts:341](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L341)
|
|
384
384
|
|
|
385
385
|
***
|
|
386
386
|
|
|
@@ -398,7 +398,7 @@ Returns `true` if the result is `Ok`.
|
|
|
398
398
|
|
|
399
399
|
#### Defined in
|
|
400
400
|
|
|
401
|
-
[
|
|
401
|
+
[core.ts:324](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L324)
|
|
402
402
|
|
|
403
403
|
***
|
|
404
404
|
|
|
@@ -422,7 +422,7 @@ Returns `true` if the result is `Ok` and the provided predicate returns `true` f
|
|
|
422
422
|
|
|
423
423
|
#### Defined in
|
|
424
424
|
|
|
425
|
-
[
|
|
425
|
+
[core.ts:335](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L335)
|
|
426
426
|
|
|
427
427
|
***
|
|
428
428
|
|
|
@@ -453,7 +453,7 @@ leaving an `Err` value untouched.
|
|
|
453
453
|
|
|
454
454
|
#### Defined in
|
|
455
455
|
|
|
456
|
-
[
|
|
456
|
+
[core.ts:434](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L434)
|
|
457
457
|
|
|
458
458
|
***
|
|
459
459
|
|
|
@@ -484,7 +484,7 @@ leaving an `Ok` value untouched.
|
|
|
484
484
|
|
|
485
485
|
#### Defined in
|
|
486
486
|
|
|
487
|
-
[
|
|
487
|
+
[core.ts:446](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L446)
|
|
488
488
|
|
|
489
489
|
***
|
|
490
490
|
|
|
@@ -515,7 +515,7 @@ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value
|
|
|
515
515
|
|
|
516
516
|
#### Defined in
|
|
517
517
|
|
|
518
|
-
[
|
|
518
|
+
[core.ts:458](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L458)
|
|
519
519
|
|
|
520
520
|
***
|
|
521
521
|
|
|
@@ -546,7 +546,7 @@ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value
|
|
|
546
546
|
|
|
547
547
|
#### Defined in
|
|
548
548
|
|
|
549
|
-
[
|
|
549
|
+
[core.ts:466](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L466)
|
|
550
550
|
|
|
551
551
|
***
|
|
552
552
|
|
|
@@ -566,7 +566,7 @@ If the result is `Err`, returns `None`.
|
|
|
566
566
|
|
|
567
567
|
#### Defined in
|
|
568
568
|
|
|
569
|
-
[
|
|
569
|
+
[core.ts:406](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L406)
|
|
570
570
|
|
|
571
571
|
***
|
|
572
572
|
|
|
@@ -598,7 +598,7 @@ Returns `this` if it is `Ok`, otherwise returns the passed `Result`.
|
|
|
598
598
|
|
|
599
599
|
#### Defined in
|
|
600
600
|
|
|
601
|
-
[
|
|
601
|
+
[core.ts:497](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L497)
|
|
602
602
|
|
|
603
603
|
***
|
|
604
604
|
|
|
@@ -630,7 +630,7 @@ The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.
|
|
|
630
630
|
|
|
631
631
|
#### Defined in
|
|
632
632
|
|
|
633
|
-
[
|
|
633
|
+
[core.ts:513](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L513)
|
|
634
634
|
|
|
635
635
|
***
|
|
636
636
|
|
|
@@ -648,7 +648,7 @@ Custom `toString` implementation that uses the `Result`'s contained value.
|
|
|
648
648
|
|
|
649
649
|
#### Defined in
|
|
650
650
|
|
|
651
|
-
[
|
|
651
|
+
[core.ts:568](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L568)
|
|
652
652
|
|
|
653
653
|
***
|
|
654
654
|
|
|
@@ -682,7 +682,7 @@ Transposes a `Result` of an `Option` into an `Option` of a `Result`.
|
|
|
682
682
|
|
|
683
683
|
#### Defined in
|
|
684
684
|
|
|
685
|
-
[
|
|
685
|
+
[core.ts:422](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L422)
|
|
686
686
|
|
|
687
687
|
***
|
|
688
688
|
|
|
@@ -704,7 +704,7 @@ Throws an error if the result is an `Err`.
|
|
|
704
704
|
|
|
705
705
|
#### Defined in
|
|
706
706
|
|
|
707
|
-
[
|
|
707
|
+
[core.ts:362](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L362)
|
|
708
708
|
|
|
709
709
|
***
|
|
710
710
|
|
|
@@ -726,7 +726,7 @@ Throws an error if the result is an `Ok`.
|
|
|
726
726
|
|
|
727
727
|
#### Defined in
|
|
728
728
|
|
|
729
|
-
[
|
|
729
|
+
[core.ts:391](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L391)
|
|
730
730
|
|
|
731
731
|
***
|
|
732
732
|
|
|
@@ -750,7 +750,7 @@ Returns the contained `Ok` value or a provided default.
|
|
|
750
750
|
|
|
751
751
|
#### Defined in
|
|
752
752
|
|
|
753
|
-
[
|
|
753
|
+
[core.ts:368](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L368)
|
|
754
754
|
|
|
755
755
|
***
|
|
756
756
|
|
|
@@ -774,4 +774,4 @@ Returns the contained `Ok` value or computes it from a closure if the result is
|
|
|
774
774
|
|
|
775
775
|
#### Defined in
|
|
776
776
|
|
|
777
|
-
[
|
|
777
|
+
[core.ts:374](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L374)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# Type Alias: AsyncIOResult\<T\>
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
type AsyncIOResult<T>:
|
|
10
|
+
type AsyncIOResult<T>: AsyncResult<T, Error>;
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Represents an asynchronous I/O operation that yields a `Result<T, Error>`.
|
|
@@ -21,4 +21,4 @@ This is a promise that resolves to `Ok(T)` if the I/O operation was successful,
|
|
|
21
21
|
|
|
22
22
|
## Defined in
|
|
23
23
|
|
|
24
|
-
[
|
|
24
|
+
[defines.ts:38](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/defines.ts#L38)
|
|
@@ -21,4 +21,4 @@ This is a promise that resolves to either `Some(T)` if the value is present, or
|
|
|
21
21
|
|
|
22
22
|
## Defined in
|
|
23
23
|
|
|
24
|
-
[
|
|
24
|
+
[defines.ts:13](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/defines.ts#L13)
|
|
@@ -22,4 +22,4 @@ This is a promise that resolves to `Ok(T)` if the operation was successful, or `
|
|
|
22
22
|
|
|
23
23
|
## Defined in
|
|
24
24
|
|
|
25
|
-
[
|
|
25
|
+
[defines.ts:22](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/defines.ts#L22)
|
|
@@ -21,4 +21,4 @@ This is a result that is either `Ok(T)` if the operation was successful, or `Err
|
|
|
21
21
|
|
|
22
22
|
## Defined in
|
|
23
23
|
|
|
24
|
-
[
|
|
24
|
+
[defines.ts:30](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/defines.ts#L30)
|
package/docs/variables/None.md
CHANGED
|
@@ -15,4 +15,4 @@ This constant is frozen to ensure it is immutable and cannot be altered, preserv
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[prelude.ts:
|
|
18
|
+
[prelude.ts:10](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L10)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[**happy-rusty**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[happy-rusty](../README.md) / RESULT\_FALSE
|
|
6
|
+
|
|
7
|
+
# Variable: RESULT\_FALSE
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const RESULT_FALSE: Result<boolean, any>;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Result constant for `false`.
|
|
14
|
+
Can be used anywhere due to immutability.
|
|
15
|
+
|
|
16
|
+
## Defined in
|
|
17
|
+
|
|
18
|
+
[constants.ts:19](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/constants.ts#L19)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[**happy-rusty**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[happy-rusty](../README.md) / RESULT\_TRUE
|
|
6
|
+
|
|
7
|
+
# Variable: RESULT\_TRUE
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const RESULT_TRUE: Result<boolean, any>;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Result constant for `true`.
|
|
14
|
+
Can be used anywhere due to immutability.
|
|
15
|
+
|
|
16
|
+
## Defined in
|
|
17
|
+
|
|
18
|
+
[constants.ts:13](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/constants.ts#L13)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[**happy-rusty**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[happy-rusty](../README.md) / RESULT\_ZERO
|
|
6
|
+
|
|
7
|
+
# Variable: RESULT\_ZERO
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const RESULT_ZERO: Result<number, any>;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Result constant for `0`.
|
|
14
|
+
Can be used anywhere due to immutability.
|
|
15
|
+
|
|
16
|
+
## Defined in
|
|
17
|
+
|
|
18
|
+
[constants.ts:25](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/constants.ts#L25)
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Porting some excellent design implementations from Rust to JavaScript.",
|
|
4
4
|
"author": "jiang115jie@gmail.com",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"source": "src/mod.ts",
|
|
9
9
|
"main": "dist/main.cjs",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type { Result } from './core.ts';
|
|
3
|
+
import { Ok } from './prelude.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Exports some Result constants.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Result constant for `true`.
|
|
11
|
+
* Can be used anywhere due to immutability.
|
|
12
|
+
*/
|
|
13
|
+
export const RESULT_TRUE: Result<boolean, any> = Ok(true);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Result constant for `false`.
|
|
17
|
+
* Can be used anywhere due to immutability.
|
|
18
|
+
*/
|
|
19
|
+
export const RESULT_FALSE: Result<boolean, any> = Ok(false);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Result constant for `0`.
|
|
23
|
+
* Can be used anywhere due to immutability.
|
|
24
|
+
*/
|
|
25
|
+
export const RESULT_ZERO: Result<number, any> = Ok(0);
|