happy-rusty 1.4.0 → 1.5.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/README.cn.md +9 -28
- package/README.md +9 -28
- package/dist/main.cjs +54 -0
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +54 -0
- package/dist/main.mjs.map +1 -1
- package/dist/types.d.ts +71 -17
- package/docs/functions/Err.md +1 -1
- package/docs/functions/Ok.md +2 -2
- package/docs/functions/Some.md +1 -1
- package/docs/functions/isOption.md +1 -1
- package/docs/functions/isResult.md +1 -1
- package/docs/functions/promiseToAsyncResult.md +1 -1
- package/docs/interfaces/None.md +175 -46
- package/docs/interfaces/Option.md +128 -32
- package/docs/interfaces/Result.md +160 -34
- package/docs/type-aliases/AsyncIOResult.md +1 -1
- package/docs/type-aliases/AsyncOption.md +1 -1
- package/docs/type-aliases/AsyncResult.md +1 -1
- package/docs/type-aliases/AsyncVoidIOResult.md +1 -1
- package/docs/type-aliases/AsyncVoidResult.md +1 -1
- package/docs/type-aliases/IOResult.md +1 -1
- package/docs/type-aliases/VoidIOResult.md +1 -1
- package/docs/type-aliases/VoidResult.md +1 -1
- package/docs/variables/None.md +1 -1
- package/docs/variables/RESULT_FALSE.md +1 -1
- package/docs/variables/RESULT_TRUE.md +1 -1
- package/docs/variables/RESULT_VOID.md +1 -1
- package/docs/variables/RESULT_ZERO.md +1 -1
- package/package.json +5 -5
- package/src/enum/core.ts +69 -3
- package/src/enum/defines.ts +1 -18
- package/src/enum/prelude.ts +71 -1
|
@@ -25,12 +25,6 @@ pub enum Result<T, E> {
|
|
|
25
25
|
| `T` | The type of the value contained in a successful `Result`. |
|
|
26
26
|
| `E` | The type of the error contained in an unsuccessful `Result`. |
|
|
27
27
|
|
|
28
|
-
## Properties
|
|
29
|
-
|
|
30
|
-
| Property | Type | Description | Defined in |
|
|
31
|
-
| ------ | ------ | ------ | ------ |
|
|
32
|
-
| `[toStringTag]` | `"Result"` | [object Result]. | [core.ts:304](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L304) |
|
|
33
|
-
|
|
34
28
|
## Methods
|
|
35
29
|
|
|
36
30
|
### and()
|
|
@@ -61,7 +55,7 @@ The passed `Result` if `this` is `Ok`, otherwise returns `this` (which is `Err`)
|
|
|
61
55
|
|
|
62
56
|
#### Defined in
|
|
63
57
|
|
|
64
|
-
[core.ts:
|
|
58
|
+
[core.ts:528](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L528)
|
|
65
59
|
|
|
66
60
|
***
|
|
67
61
|
|
|
@@ -93,7 +87,37 @@ The result of `fn` if `this` is `Ok`, otherwise `this` as `Err`.
|
|
|
93
87
|
|
|
94
88
|
#### Defined in
|
|
95
89
|
|
|
96
|
-
[core.ts:
|
|
90
|
+
[core.ts:544](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L544)
|
|
91
|
+
|
|
92
|
+
***
|
|
93
|
+
|
|
94
|
+
### andThenAsync()
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
andThenAsync<U>(fn): AsyncResult<U, E>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Asynchronous version of `andThen`.
|
|
101
|
+
|
|
102
|
+
#### Type Parameters
|
|
103
|
+
|
|
104
|
+
| Type Parameter |
|
|
105
|
+
| ------ |
|
|
106
|
+
| `U` |
|
|
107
|
+
|
|
108
|
+
#### Parameters
|
|
109
|
+
|
|
110
|
+
| Parameter | Type |
|
|
111
|
+
| ------ | ------ |
|
|
112
|
+
| `fn` | (`value`) => [`AsyncResult`](../type-aliases/AsyncResult.md)\<`U`, `E`\> |
|
|
113
|
+
|
|
114
|
+
#### Returns
|
|
115
|
+
|
|
116
|
+
[`AsyncResult`](../type-aliases/AsyncResult.md)\<`U`, `E`\>
|
|
117
|
+
|
|
118
|
+
#### Defined in
|
|
119
|
+
|
|
120
|
+
[core.ts:549](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L549)
|
|
97
121
|
|
|
98
122
|
***
|
|
99
123
|
|
|
@@ -122,7 +146,7 @@ Just same as `result as unknown as Result<U, E>`.
|
|
|
122
146
|
|
|
123
147
|
#### Defined in
|
|
124
148
|
|
|
125
|
-
[core.ts:
|
|
149
|
+
[core.ts:612](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L612)
|
|
126
150
|
|
|
127
151
|
***
|
|
128
152
|
|
|
@@ -150,7 +174,7 @@ Just same as `result as unknown as Result<T, F>`.
|
|
|
150
174
|
|
|
151
175
|
#### Defined in
|
|
152
176
|
|
|
153
|
-
[core.ts:
|
|
177
|
+
[core.ts:601](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L601)
|
|
154
178
|
|
|
155
179
|
***
|
|
156
180
|
|
|
@@ -176,7 +200,7 @@ Tests whether `this` and `other` are both `Ok` containing equal values, or both
|
|
|
176
200
|
|
|
177
201
|
#### Defined in
|
|
178
202
|
|
|
179
|
-
[core.ts:
|
|
203
|
+
[core.ts:589](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L589)
|
|
180
204
|
|
|
181
205
|
***
|
|
182
206
|
|
|
@@ -196,7 +220,7 @@ If the result is `Ok`, returns `None`.
|
|
|
196
220
|
|
|
197
221
|
#### Defined in
|
|
198
222
|
|
|
199
|
-
[core.ts:
|
|
223
|
+
[core.ts:452](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L452)
|
|
200
224
|
|
|
201
225
|
***
|
|
202
226
|
|
|
@@ -224,7 +248,7 @@ Throws an error with the provided message if the result is an `Err`.
|
|
|
224
248
|
|
|
225
249
|
#### Defined in
|
|
226
250
|
|
|
227
|
-
[core.ts:
|
|
251
|
+
[core.ts:390](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L390)
|
|
228
252
|
|
|
229
253
|
***
|
|
230
254
|
|
|
@@ -252,7 +276,7 @@ Throws an error with the provided message if the result is an `Ok`.
|
|
|
252
276
|
|
|
253
277
|
#### Defined in
|
|
254
278
|
|
|
255
|
-
[core.ts:
|
|
279
|
+
[core.ts:424](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L424)
|
|
256
280
|
|
|
257
281
|
***
|
|
258
282
|
|
|
@@ -284,7 +308,7 @@ If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.
|
|
|
284
308
|
|
|
285
309
|
#### Defined in
|
|
286
310
|
|
|
287
|
-
[core.ts:
|
|
311
|
+
[core.ts:512](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L512)
|
|
288
312
|
|
|
289
313
|
***
|
|
290
314
|
|
|
@@ -311,7 +335,7 @@ Does not modify the `Result`.
|
|
|
311
335
|
|
|
312
336
|
#### Defined in
|
|
313
337
|
|
|
314
|
-
[core.ts:
|
|
338
|
+
[core.ts:572](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L572)
|
|
315
339
|
|
|
316
340
|
***
|
|
317
341
|
|
|
@@ -338,7 +362,7 @@ Does not modify the `Result`.
|
|
|
338
362
|
|
|
339
363
|
#### Defined in
|
|
340
364
|
|
|
341
|
-
[core.ts:
|
|
365
|
+
[core.ts:580](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L580)
|
|
342
366
|
|
|
343
367
|
***
|
|
344
368
|
|
|
@@ -356,7 +380,7 @@ Returns `true` if the result is `Err`.
|
|
|
356
380
|
|
|
357
381
|
#### Defined in
|
|
358
382
|
|
|
359
|
-
[core.ts:
|
|
383
|
+
[core.ts:353](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L353)
|
|
360
384
|
|
|
361
385
|
***
|
|
362
386
|
|
|
@@ -380,7 +404,31 @@ Returns `true` if the result is `Err` and the provided predicate returns `true`
|
|
|
380
404
|
|
|
381
405
|
#### Defined in
|
|
382
406
|
|
|
383
|
-
[core.ts:
|
|
407
|
+
[core.ts:370](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L370)
|
|
408
|
+
|
|
409
|
+
***
|
|
410
|
+
|
|
411
|
+
### isErrAndAsync()
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
isErrAndAsync(predicate): Promise<boolean>
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
Asynchronous version of `isErrAnd`.
|
|
418
|
+
|
|
419
|
+
#### Parameters
|
|
420
|
+
|
|
421
|
+
| Parameter | Type |
|
|
422
|
+
| ------ | ------ |
|
|
423
|
+
| `predicate` | (`error`) => `Promise`\<`boolean`\> |
|
|
424
|
+
|
|
425
|
+
#### Returns
|
|
426
|
+
|
|
427
|
+
`Promise`\<`boolean`\>
|
|
428
|
+
|
|
429
|
+
#### Defined in
|
|
430
|
+
|
|
431
|
+
[core.ts:375](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L375)
|
|
384
432
|
|
|
385
433
|
***
|
|
386
434
|
|
|
@@ -398,7 +446,7 @@ Returns `true` if the result is `Ok`.
|
|
|
398
446
|
|
|
399
447
|
#### Defined in
|
|
400
448
|
|
|
401
|
-
[core.ts:
|
|
449
|
+
[core.ts:348](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L348)
|
|
402
450
|
|
|
403
451
|
***
|
|
404
452
|
|
|
@@ -422,7 +470,31 @@ Returns `true` if the result is `Ok` and the provided predicate returns `true` f
|
|
|
422
470
|
|
|
423
471
|
#### Defined in
|
|
424
472
|
|
|
425
|
-
[core.ts:
|
|
473
|
+
[core.ts:359](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L359)
|
|
474
|
+
|
|
475
|
+
***
|
|
476
|
+
|
|
477
|
+
### isOkAndAsync()
|
|
478
|
+
|
|
479
|
+
```ts
|
|
480
|
+
isOkAndAsync(predicate): Promise<boolean>
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Asynchronous version of `isOkAnd`.
|
|
484
|
+
|
|
485
|
+
#### Parameters
|
|
486
|
+
|
|
487
|
+
| Parameter | Type |
|
|
488
|
+
| ------ | ------ |
|
|
489
|
+
| `predicate` | (`value`) => `Promise`\<`boolean`\> |
|
|
490
|
+
|
|
491
|
+
#### Returns
|
|
492
|
+
|
|
493
|
+
`Promise`\<`boolean`\>
|
|
494
|
+
|
|
495
|
+
#### Defined in
|
|
496
|
+
|
|
497
|
+
[core.ts:364](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L364)
|
|
426
498
|
|
|
427
499
|
***
|
|
428
500
|
|
|
@@ -453,7 +525,7 @@ leaving an `Err` value untouched.
|
|
|
453
525
|
|
|
454
526
|
#### Defined in
|
|
455
527
|
|
|
456
|
-
[core.ts:
|
|
528
|
+
[core.ts:473](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L473)
|
|
457
529
|
|
|
458
530
|
***
|
|
459
531
|
|
|
@@ -484,7 +556,7 @@ leaving an `Ok` value untouched.
|
|
|
484
556
|
|
|
485
557
|
#### Defined in
|
|
486
558
|
|
|
487
|
-
[core.ts:
|
|
559
|
+
[core.ts:485](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L485)
|
|
488
560
|
|
|
489
561
|
***
|
|
490
562
|
|
|
@@ -515,7 +587,7 @@ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value
|
|
|
515
587
|
|
|
516
588
|
#### Defined in
|
|
517
589
|
|
|
518
|
-
[core.ts:
|
|
590
|
+
[core.ts:497](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L497)
|
|
519
591
|
|
|
520
592
|
***
|
|
521
593
|
|
|
@@ -546,7 +618,7 @@ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value
|
|
|
546
618
|
|
|
547
619
|
#### Defined in
|
|
548
620
|
|
|
549
|
-
[core.ts:
|
|
621
|
+
[core.ts:505](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L505)
|
|
550
622
|
|
|
551
623
|
***
|
|
552
624
|
|
|
@@ -566,7 +638,7 @@ If the result is `Err`, returns `None`.
|
|
|
566
638
|
|
|
567
639
|
#### Defined in
|
|
568
640
|
|
|
569
|
-
[core.ts:
|
|
641
|
+
[core.ts:445](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L445)
|
|
570
642
|
|
|
571
643
|
***
|
|
572
644
|
|
|
@@ -598,7 +670,7 @@ Returns `this` if it is `Ok`, otherwise returns the passed `Result`.
|
|
|
598
670
|
|
|
599
671
|
#### Defined in
|
|
600
672
|
|
|
601
|
-
[core.ts:
|
|
673
|
+
[core.ts:536](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L536)
|
|
602
674
|
|
|
603
675
|
***
|
|
604
676
|
|
|
@@ -630,7 +702,37 @@ The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.
|
|
|
630
702
|
|
|
631
703
|
#### Defined in
|
|
632
704
|
|
|
633
|
-
[core.ts:
|
|
705
|
+
[core.ts:557](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L557)
|
|
706
|
+
|
|
707
|
+
***
|
|
708
|
+
|
|
709
|
+
### orElseAsync()
|
|
710
|
+
|
|
711
|
+
```ts
|
|
712
|
+
orElseAsync<F>(fn): AsyncResult<T, F>
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
Asynchronous version of `orElse`.
|
|
716
|
+
|
|
717
|
+
#### Type Parameters
|
|
718
|
+
|
|
719
|
+
| Type Parameter |
|
|
720
|
+
| ------ |
|
|
721
|
+
| `F` |
|
|
722
|
+
|
|
723
|
+
#### Parameters
|
|
724
|
+
|
|
725
|
+
| Parameter | Type |
|
|
726
|
+
| ------ | ------ |
|
|
727
|
+
| `fn` | (`error`) => [`AsyncResult`](../type-aliases/AsyncResult.md)\<`T`, `F`\> |
|
|
728
|
+
|
|
729
|
+
#### Returns
|
|
730
|
+
|
|
731
|
+
[`AsyncResult`](../type-aliases/AsyncResult.md)\<`T`, `F`\>
|
|
732
|
+
|
|
733
|
+
#### Defined in
|
|
734
|
+
|
|
735
|
+
[core.ts:562](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L562)
|
|
634
736
|
|
|
635
737
|
***
|
|
636
738
|
|
|
@@ -648,7 +750,7 @@ Custom `toString` implementation that uses the `Result`'s contained value.
|
|
|
648
750
|
|
|
649
751
|
#### Defined in
|
|
650
752
|
|
|
651
|
-
[core.ts:
|
|
753
|
+
[core.ts:617](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L617)
|
|
652
754
|
|
|
653
755
|
***
|
|
654
756
|
|
|
@@ -682,7 +784,7 @@ Transposes a `Result` of an `Option` into an `Option` of a `Result`.
|
|
|
682
784
|
|
|
683
785
|
#### Defined in
|
|
684
786
|
|
|
685
|
-
[core.ts:
|
|
787
|
+
[core.ts:461](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L461)
|
|
686
788
|
|
|
687
789
|
***
|
|
688
790
|
|
|
@@ -704,7 +806,7 @@ Throws an error if the result is an `Err`.
|
|
|
704
806
|
|
|
705
807
|
#### Defined in
|
|
706
808
|
|
|
707
|
-
[core.ts:
|
|
809
|
+
[core.ts:396](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L396)
|
|
708
810
|
|
|
709
811
|
***
|
|
710
812
|
|
|
@@ -726,7 +828,7 @@ Throws an error if the result is an `Ok`.
|
|
|
726
828
|
|
|
727
829
|
#### Defined in
|
|
728
830
|
|
|
729
|
-
[core.ts:
|
|
831
|
+
[core.ts:430](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L430)
|
|
730
832
|
|
|
731
833
|
***
|
|
732
834
|
|
|
@@ -750,7 +852,7 @@ Returns the contained `Ok` value or a provided default.
|
|
|
750
852
|
|
|
751
853
|
#### Defined in
|
|
752
854
|
|
|
753
|
-
[core.ts:
|
|
855
|
+
[core.ts:402](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L402)
|
|
754
856
|
|
|
755
857
|
***
|
|
756
858
|
|
|
@@ -774,4 +876,28 @@ Returns the contained `Ok` value or computes it from a closure if the result is
|
|
|
774
876
|
|
|
775
877
|
#### Defined in
|
|
776
878
|
|
|
777
|
-
[core.ts:
|
|
879
|
+
[core.ts:408](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L408)
|
|
880
|
+
|
|
881
|
+
***
|
|
882
|
+
|
|
883
|
+
### unwrapOrElseAsync()
|
|
884
|
+
|
|
885
|
+
```ts
|
|
886
|
+
unwrapOrElseAsync(fn): Promise<T>
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
Asynchronous version of `unwrapOrElse`.
|
|
890
|
+
|
|
891
|
+
#### Parameters
|
|
892
|
+
|
|
893
|
+
| Parameter | Type |
|
|
894
|
+
| ------ | ------ |
|
|
895
|
+
| `fn` | (`error`) => `Promise`\<`T`\> |
|
|
896
|
+
|
|
897
|
+
#### Returns
|
|
898
|
+
|
|
899
|
+
`Promise`\<`T`\>
|
|
900
|
+
|
|
901
|
+
#### Defined in
|
|
902
|
+
|
|
903
|
+
[core.ts:413](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L413)
|
|
@@ -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
|
-
[defines.ts:
|
|
24
|
+
[defines.ts:35](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/defines.ts#L35)
|
|
@@ -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
|
+
[core.ts:626](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L626)
|
|
@@ -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
|
+
[core.ts:635](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L635)
|
|
@@ -14,4 +14,4 @@ type AsyncVoidIOResult: AsyncIOResult<void>;
|
|
|
14
14
|
|
|
15
15
|
## Defined in
|
|
16
16
|
|
|
17
|
-
[defines.ts:
|
|
17
|
+
[defines.ts:45](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/defines.ts#L45)
|
|
@@ -20,4 +20,4 @@ type AsyncVoidResult<E>: Promise<VoidResult<E>>;
|
|
|
20
20
|
|
|
21
21
|
## Defined in
|
|
22
22
|
|
|
23
|
-
[defines.ts:
|
|
23
|
+
[defines.ts:19](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/defines.ts#L19)
|
|
@@ -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
|
-
[defines.ts:
|
|
24
|
+
[defines.ts:27](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/defines.ts#L27)
|
|
@@ -14,4 +14,4 @@ Similar to Rust's `Result<(), Error>`.
|
|
|
14
14
|
|
|
15
15
|
## Defined in
|
|
16
16
|
|
|
17
|
-
[defines.ts:
|
|
17
|
+
[defines.ts:40](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/defines.ts#L40)
|
|
@@ -20,4 +20,4 @@ Similar to Rust's `Result<(), E>`.
|
|
|
20
20
|
|
|
21
21
|
## Defined in
|
|
22
22
|
|
|
23
|
-
[defines.ts:
|
|
23
|
+
[defines.ts:12](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/defines.ts#L12)
|
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:10](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[prelude.ts:10](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L10)
|
|
@@ -15,4 +15,4 @@ Can be used anywhere due to immutability.
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[constants.ts:19](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[constants.ts:19](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/constants.ts#L19)
|
|
@@ -15,4 +15,4 @@ Can be used anywhere due to immutability.
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[constants.ts:13](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[constants.ts:13](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/constants.ts#L13)
|
|
@@ -14,4 +14,4 @@ Result constant for `void` or `()`.
|
|
|
14
14
|
|
|
15
15
|
## Defined in
|
|
16
16
|
|
|
17
|
-
[constants.ts:30](https://github.com/JiangJie/happy-rusty/blob/
|
|
17
|
+
[constants.ts:30](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/constants.ts#L30)
|
|
@@ -15,4 +15,4 @@ Can be used anywhere due to immutability.
|
|
|
15
15
|
|
|
16
16
|
## Defined in
|
|
17
17
|
|
|
18
|
-
[constants.ts:25](https://github.com/JiangJie/happy-rusty/blob/
|
|
18
|
+
[constants.ts:25](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/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.5.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"source": "src/mod.ts",
|
|
9
9
|
"main": "dist/main.cjs",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"Err"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@eslint/js": "^9.
|
|
51
|
+
"@eslint/js": "^9.9.0",
|
|
52
52
|
"@types/eslint__js": "^8.42.3",
|
|
53
|
-
"eslint": "^9.
|
|
53
|
+
"eslint": "^9.9.0",
|
|
54
54
|
"rollup": "^4.20.0",
|
|
55
55
|
"rollup-plugin-dts": "^6.1.1",
|
|
56
56
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
57
57
|
"typedoc": "^0.26.5",
|
|
58
58
|
"typedoc-plugin-markdown": "^4.2.3",
|
|
59
59
|
"typescript": "^5.5.4",
|
|
60
|
-
"typescript-eslint": "^8.0.
|
|
60
|
+
"typescript-eslint": "^8.0.1"
|
|
61
61
|
},
|
|
62
|
-
"packageManager": "pnpm@9.
|
|
62
|
+
"packageManager": "pnpm@9.7.0"
|
|
63
63
|
}
|
package/src/enum/core.ts
CHANGED
|
@@ -26,8 +26,10 @@ export interface Option<T> {
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* [object Option].
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
29
31
|
*/
|
|
30
|
-
[Symbol.toStringTag]: 'Option',
|
|
32
|
+
readonly [Symbol.toStringTag]: 'Option',
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* Identify `Some` or `None`.
|
|
@@ -60,6 +62,11 @@ export interface Option<T> {
|
|
|
60
62
|
*/
|
|
61
63
|
isSomeAnd(predicate: (value: T) => boolean): boolean;
|
|
62
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Asynchronous version of `isSomeAnd`.
|
|
67
|
+
*/
|
|
68
|
+
isSomeAndAsync(predicate: (value: T) => Promise<boolean>): Promise<boolean>;
|
|
69
|
+
|
|
63
70
|
// #endregion
|
|
64
71
|
|
|
65
72
|
// #region Extracting the contained value
|
|
@@ -93,6 +100,11 @@ export interface Option<T> {
|
|
|
93
100
|
*/
|
|
94
101
|
unwrapOrElse(fn: () => T): T;
|
|
95
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Asynchronous version of `unwrapOrElse`.
|
|
105
|
+
*/
|
|
106
|
+
unwrapOrElseAsync(fn: () => Promise<T>): Promise<T>;
|
|
107
|
+
|
|
96
108
|
// #endregion
|
|
97
109
|
|
|
98
110
|
// #region Transforming contained values
|
|
@@ -228,6 +240,11 @@ export interface Option<T> {
|
|
|
228
240
|
*/
|
|
229
241
|
andThen<U>(fn: (value: T) => Option<U>): Option<U>;
|
|
230
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Asynchronous version of `andThen`.
|
|
245
|
+
*/
|
|
246
|
+
andThenAsync<U>(fn: (value: T) => AsyncOption<U>): AsyncOption<U>;
|
|
247
|
+
|
|
231
248
|
/**
|
|
232
249
|
* Returns the Option if it contains a value, otherwise returns `other`.
|
|
233
250
|
* This can be used for providing a fallback `Option`.
|
|
@@ -244,6 +261,11 @@ export interface Option<T> {
|
|
|
244
261
|
*/
|
|
245
262
|
orElse(fn: () => Option<T>): Option<T>;
|
|
246
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Asynchronous version of `orElse`.
|
|
266
|
+
*/
|
|
267
|
+
orElseAsync(fn: () => AsyncOption<T>): AsyncOption<T>;
|
|
268
|
+
|
|
247
269
|
/**
|
|
248
270
|
* Returns `Some` if exactly one of `this`, `other` is `Some`, otherwise returns `None`.
|
|
249
271
|
* This can be thought of as an exclusive or operation on `Option` values.
|
|
@@ -300,8 +322,10 @@ export interface Result<T, E> {
|
|
|
300
322
|
|
|
301
323
|
/**
|
|
302
324
|
* [object Result].
|
|
325
|
+
*
|
|
326
|
+
* @private
|
|
303
327
|
*/
|
|
304
|
-
[Symbol.toStringTag]: 'Result',
|
|
328
|
+
readonly [Symbol.toStringTag]: 'Result',
|
|
305
329
|
|
|
306
330
|
/**
|
|
307
331
|
* Identify `Ok` or `Err`.
|
|
@@ -334,12 +358,22 @@ export interface Result<T, E> {
|
|
|
334
358
|
*/
|
|
335
359
|
isOkAnd(predicate: (value: T) => boolean): boolean;
|
|
336
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Asynchronous version of `isOkAnd`.
|
|
363
|
+
*/
|
|
364
|
+
isOkAndAsync(predicate: (value: T) => Promise<boolean>): Promise<boolean>;
|
|
365
|
+
|
|
337
366
|
/**
|
|
338
367
|
* Returns `true` if the result is `Err` and the provided predicate returns `true` for the contained error.
|
|
339
368
|
* @param predicate - A function that takes the `Err` value and returns a boolean.
|
|
340
369
|
*/
|
|
341
370
|
isErrAnd(predicate: (error: E) => boolean): boolean;
|
|
342
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Asynchronous version of `isErrAnd`.
|
|
374
|
+
*/
|
|
375
|
+
isErrAndAsync(predicate: (error: E) => Promise<boolean>): Promise<boolean>;
|
|
376
|
+
|
|
343
377
|
// #endregion
|
|
344
378
|
|
|
345
379
|
// #region Extracting the contained value
|
|
@@ -373,6 +407,11 @@ export interface Result<T, E> {
|
|
|
373
407
|
*/
|
|
374
408
|
unwrapOrElse(fn: (error: E) => T): T;
|
|
375
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Asynchronous version of `unwrapOrElse`.
|
|
412
|
+
*/
|
|
413
|
+
unwrapOrElseAsync(fn: (error: E) => Promise<T>): Promise<T>;
|
|
414
|
+
|
|
376
415
|
/**
|
|
377
416
|
* These methods extract the contained value in a `Result<T, E>` when it is the `Err` variant.
|
|
378
417
|
*/
|
|
@@ -504,6 +543,11 @@ export interface Result<T, E> {
|
|
|
504
543
|
*/
|
|
505
544
|
andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;
|
|
506
545
|
|
|
546
|
+
/**
|
|
547
|
+
* Asynchronous version of `andThen`.
|
|
548
|
+
*/
|
|
549
|
+
andThenAsync<U>(fn: (value: T) => AsyncResult<U, E>): AsyncResult<U, E>;
|
|
550
|
+
|
|
507
551
|
/**
|
|
508
552
|
* Calls the provided function with the contained error if `this` is `Err`, otherwise returns `this` as `Ok`.
|
|
509
553
|
* @typeParam F - The type of the error returned by the function.
|
|
@@ -512,6 +556,11 @@ export interface Result<T, E> {
|
|
|
512
556
|
*/
|
|
513
557
|
orElse<F>(fn: (error: E) => Result<T, F>): Result<T, F>;
|
|
514
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Asynchronous version of `orElse`.
|
|
561
|
+
*/
|
|
562
|
+
orElseAsync<F>(fn: (error: E) => AsyncResult<T, F>): AsyncResult<T, F>;
|
|
563
|
+
|
|
515
564
|
// #endregion
|
|
516
565
|
|
|
517
566
|
/**
|
|
@@ -566,4 +615,21 @@ export interface Result<T, E> {
|
|
|
566
615
|
* Custom `toString` implementation that uses the `Result`'s contained value.
|
|
567
616
|
*/
|
|
568
617
|
toString(): string;
|
|
569
|
-
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Represents an asynchronous operation that yields an `Option<T>`.
|
|
622
|
+
* This is a promise that resolves to either `Some(T)` if the value is present, or `None` if the value is absent.
|
|
623
|
+
*
|
|
624
|
+
* @typeParam T - The type of the value that may be contained within the `Option`.
|
|
625
|
+
*/
|
|
626
|
+
export type AsyncOption<T> = Promise<Option<T>>;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Represents an asynchronous operation that yields a `Result<T, E>`.
|
|
630
|
+
* This is a promise that resolves to `Ok(T)` if the operation was successful, or `Err(E)` if there was an error.
|
|
631
|
+
*
|
|
632
|
+
* @typeParam T - The type of the value that is produced by a successful operation.
|
|
633
|
+
* @typeParam E - The type of the error that may be produced by a failed operation.
|
|
634
|
+
*/
|
|
635
|
+
export type AsyncResult<T, E> = Promise<Result<T, E>>;
|