happy-rusty 1.0.8 → 1.1.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.
@@ -0,0 +1,702 @@
1
+ [**happy-rusty**](../index.md) • **Docs**
2
+
3
+ ***
4
+
5
+ [happy-rusty](../index.md) / Result
6
+
7
+ # Interface: Result\<T, E\>
8
+
9
+ The `Result` type is used for returning and propagating errors.
10
+ It is an enum with the variants, `Ok(T)`, representing success and containing a value, and `Err(E)`, representing error and containing an error value.
11
+ This interface includes methods that act on the `Result` type, similar to Rust's `Result` enum.
12
+
13
+ As Rust Code:
14
+ ```rust
15
+ pub enum Result<T, E> {
16
+ Ok(T),
17
+ Err(E),
18
+ }
19
+ ```
20
+
21
+ ## Type parameters
22
+
23
+ | Type parameter | Description |
24
+ | :------ | :------ |
25
+ | `T` | The type of the value contained in a successful `Result`. |
26
+ | `E` | The type of the error contained in an unsuccessful `Result`. |
27
+
28
+ ## Properties
29
+
30
+ | Property | Modifier | Type | Description |
31
+ | :------ | :------ | :------ | :------ |
32
+ | `[resultKindSymbol]` | `private` | `"Ok"` \| `"Err"` | Identify `Ok` or `Err`. |
33
+
34
+ ## Methods
35
+
36
+ ### and()
37
+
38
+ ```ts
39
+ and<U>(other): Result<U, E>
40
+ ```
41
+
42
+ Returns `this` if the result is `Err`, otherwise returns the passed `Result`.
43
+
44
+ #### Type parameters
45
+
46
+ | Type parameter | Description |
47
+ | :------ | :------ |
48
+ | `U` | The type of the value in the other `Result`. |
49
+
50
+ #### Parameters
51
+
52
+ | Parameter | Type | Description |
53
+ | :------ | :------ | :------ |
54
+ | `other` | [`Result`](Result.md)\<`U`, `E`\> | The `Result` to return if `this` is `Ok`. |
55
+
56
+ #### Returns
57
+
58
+ [`Result`](Result.md)\<`U`, `E`\>
59
+
60
+ The passed `Result` if `this` is `Ok`, otherwise returns `this` (which is `Err`).
61
+
62
+ #### Source
63
+
64
+ [enum/prelude.ts:518](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L518)
65
+
66
+ ***
67
+
68
+ ### andThen()
69
+
70
+ ```ts
71
+ andThen<U>(fn): Result<U, E>
72
+ ```
73
+
74
+ Calls the provided function with the contained value if `this` is `Ok`, otherwise returns `this` as `Err`.
75
+
76
+ #### Type parameters
77
+
78
+ | Type parameter | Description |
79
+ | :------ | :------ |
80
+ | `U` | The type of the value returned by the function. |
81
+
82
+ #### Parameters
83
+
84
+ | Parameter | Type | Description |
85
+ | :------ | :------ | :------ |
86
+ | `fn` | (`value`) => [`Result`](Result.md)\<`U`, `E`\> | A function that takes the `Ok` value and returns a `Result`. |
87
+
88
+ #### Returns
89
+
90
+ [`Result`](Result.md)\<`U`, `E`\>
91
+
92
+ The result of `fn` if `this` is `Ok`, otherwise `this` as `Err`.
93
+
94
+ #### Source
95
+
96
+ [enum/prelude.ts:534](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L534)
97
+
98
+ ***
99
+
100
+ ### eq()
101
+
102
+ ```ts
103
+ eq(other): boolean
104
+ ```
105
+
106
+ Tests whether `this` and `other` are both `Ok` containing equal values, or both are `Err` containing equal errors.
107
+
108
+ #### Parameters
109
+
110
+ | Parameter | Type | Description |
111
+ | :------ | :------ | :------ |
112
+ | `other` | [`Result`](Result.md)\<`T`, `E`\> | The other `Result` to compare with. |
113
+
114
+ #### Returns
115
+
116
+ `boolean`
117
+
118
+ `true` if `this` and `other` are both `Ok` with equal values, or both are `Err` with equal errors, otherwise `false`.
119
+
120
+ #### Source
121
+
122
+ [enum/prelude.ts:569](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L569)
123
+
124
+ ***
125
+
126
+ ### err()
127
+
128
+ ```ts
129
+ err(): Option<E>
130
+ ```
131
+
132
+ Converts from `Result<T, E>` to `Option<E>`.
133
+ If the result is `Err`, returns `Some(E)`.
134
+ If the result is `Ok`, returns `None`.
135
+
136
+ #### Returns
137
+
138
+ [`Option`](Option.md)\<`E`\>
139
+
140
+ #### Source
141
+
142
+ [enum/prelude.ts:442](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L442)
143
+
144
+ ***
145
+
146
+ ### expect()
147
+
148
+ ```ts
149
+ expect(msg): T
150
+ ```
151
+
152
+ Returns the contained `Ok` value, with a provided error message if the result is `Err`.
153
+
154
+ #### Parameters
155
+
156
+ | Parameter | Type | Description |
157
+ | :------ | :------ | :------ |
158
+ | `msg` | `string` | The error message to provide if the result is an `Err`. |
159
+
160
+ #### Returns
161
+
162
+ `T`
163
+
164
+ #### Throws
165
+
166
+ Throws an error with the provided message if the result is an `Err`.
167
+
168
+ #### Source
169
+
170
+ [enum/prelude.ts:385](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L385)
171
+
172
+ ***
173
+
174
+ ### expectErr()
175
+
176
+ ```ts
177
+ expectErr(msg): E
178
+ ```
179
+
180
+ Returns the contained `Err` value, with a provided error message if the result is `Ok`.
181
+
182
+ #### Parameters
183
+
184
+ | Parameter | Type | Description |
185
+ | :------ | :------ | :------ |
186
+ | `msg` | `string` | The error message to provide if the result is an `Ok`. |
187
+
188
+ #### Returns
189
+
190
+ `E`
191
+
192
+ #### Throws
193
+
194
+ Throws an error with the provided message if the result is an `Ok`.
195
+
196
+ #### Source
197
+
198
+ [enum/prelude.ts:414](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L414)
199
+
200
+ ***
201
+
202
+ ### flatten()
203
+
204
+ ```ts
205
+ flatten<T>(this): Result<T, E>
206
+ ```
207
+
208
+ Converts from `Result<Result<T, E>, E>` to `Result<T, E>`.
209
+ If the result is `Ok(Ok(T))`, returns `Ok(T)`.
210
+ If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.
211
+
212
+ #### Type parameters
213
+
214
+ | Type parameter |
215
+ | :------ |
216
+ | `T` |
217
+
218
+ #### Parameters
219
+
220
+ | Parameter | Type |
221
+ | :------ | :------ |
222
+ | `this` | [`Result`](Result.md)\<[`Result`](Result.md)\<`T`, `E`\>, `E`\> |
223
+
224
+ #### Returns
225
+
226
+ [`Result`](Result.md)\<`T`, `E`\>
227
+
228
+ #### Source
229
+
230
+ [enum/prelude.ts:502](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L502)
231
+
232
+ ***
233
+
234
+ ### inspect()
235
+
236
+ ```ts
237
+ inspect(fn): this
238
+ ```
239
+
240
+ Calls the provided function with the contained value if `this` is `Ok`, for side effects only.
241
+ Does not modify the `Result`.
242
+
243
+ #### Parameters
244
+
245
+ | Parameter | Type | Description |
246
+ | :------ | :------ | :------ |
247
+ | `fn` | (`value`) => `void` | A function to call with the `Ok` value. |
248
+
249
+ #### Returns
250
+
251
+ `this`
252
+
253
+ `this`, unmodified.
254
+
255
+ #### Source
256
+
257
+ [enum/prelude.ts:552](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L552)
258
+
259
+ ***
260
+
261
+ ### inspectErr()
262
+
263
+ ```ts
264
+ inspectErr(fn): this
265
+ ```
266
+
267
+ Calls the provided function with the contained error if `this` is `Err`, for side effects only.
268
+ Does not modify the `Result`.
269
+
270
+ #### Parameters
271
+
272
+ | Parameter | Type | Description |
273
+ | :------ | :------ | :------ |
274
+ | `fn` | (`error`) => `void` | A function to call with the `Err` value. |
275
+
276
+ #### Returns
277
+
278
+ `this`
279
+
280
+ `this`, unmodified.
281
+
282
+ #### Source
283
+
284
+ [enum/prelude.ts:560](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L560)
285
+
286
+ ***
287
+
288
+ ### isErr()
289
+
290
+ ```ts
291
+ isErr(): boolean
292
+ ```
293
+
294
+ Returns `true` if the result is `Err`.
295
+
296
+ #### Returns
297
+
298
+ `boolean`
299
+
300
+ #### Source
301
+
302
+ [enum/prelude.ts:358](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L358)
303
+
304
+ ***
305
+
306
+ ### isErrAnd()
307
+
308
+ ```ts
309
+ isErrAnd(predicate): boolean
310
+ ```
311
+
312
+ Returns `true` if the result is `Err` and the provided predicate returns `true` for the contained error.
313
+
314
+ #### Parameters
315
+
316
+ | Parameter | Type | Description |
317
+ | :------ | :------ | :------ |
318
+ | `predicate` | (`error`) => `boolean` | A function that takes the `Err` value and returns a boolean. |
319
+
320
+ #### Returns
321
+
322
+ `boolean`
323
+
324
+ #### Source
325
+
326
+ [enum/prelude.ts:370](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L370)
327
+
328
+ ***
329
+
330
+ ### isOk()
331
+
332
+ ```ts
333
+ isOk(): boolean
334
+ ```
335
+
336
+ Returns `true` if the result is `Ok`.
337
+
338
+ #### Returns
339
+
340
+ `boolean`
341
+
342
+ #### Source
343
+
344
+ [enum/prelude.ts:353](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L353)
345
+
346
+ ***
347
+
348
+ ### isOkAnd()
349
+
350
+ ```ts
351
+ isOkAnd(predicate): boolean
352
+ ```
353
+
354
+ Returns `true` if the result is `Ok` and the provided predicate returns `true` for the contained value.
355
+
356
+ #### Parameters
357
+
358
+ | Parameter | Type | Description |
359
+ | :------ | :------ | :------ |
360
+ | `predicate` | (`value`) => `boolean` | A function that takes the `Ok` value and returns a boolean. |
361
+
362
+ #### Returns
363
+
364
+ `boolean`
365
+
366
+ #### Source
367
+
368
+ [enum/prelude.ts:364](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L364)
369
+
370
+ ***
371
+
372
+ ### map()
373
+
374
+ ```ts
375
+ map<U>(fn): Result<U, E>
376
+ ```
377
+
378
+ Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,
379
+ leaving an `Err` value untouched.
380
+
381
+ #### Type parameters
382
+
383
+ | Type parameter | Description |
384
+ | :------ | :------ |
385
+ | `U` | The type of the value returned by the map function. |
386
+
387
+ #### Parameters
388
+
389
+ | Parameter | Type | Description |
390
+ | :------ | :------ | :------ |
391
+ | `fn` | (`value`) => `U` | A function that takes the `Ok` value and returns a new value. |
392
+
393
+ #### Returns
394
+
395
+ [`Result`](Result.md)\<`U`, `E`\>
396
+
397
+ #### Source
398
+
399
+ [enum/prelude.ts:463](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L463)
400
+
401
+ ***
402
+
403
+ ### mapErr()
404
+
405
+ ```ts
406
+ mapErr<F>(fn): Result<T, F>
407
+ ```
408
+
409
+ Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,
410
+ leaving an `Ok` value untouched.
411
+
412
+ #### Type parameters
413
+
414
+ | Type parameter | Description |
415
+ | :------ | :------ |
416
+ | `F` | The type of the error returned by the map function. |
417
+
418
+ #### Parameters
419
+
420
+ | Parameter | Type | Description |
421
+ | :------ | :------ | :------ |
422
+ | `fn` | (`error`) => `F` | A function that takes the `Err` value and returns a new error value. |
423
+
424
+ #### Returns
425
+
426
+ [`Result`](Result.md)\<`T`, `F`\>
427
+
428
+ #### Source
429
+
430
+ [enum/prelude.ts:475](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L475)
431
+
432
+ ***
433
+
434
+ ### mapOr()
435
+
436
+ ```ts
437
+ mapOr<U>(defaultValue, fn): U
438
+ ```
439
+
440
+ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or returns the provided default (if `Err`).
441
+
442
+ #### Type parameters
443
+
444
+ | Type parameter | Description |
445
+ | :------ | :------ |
446
+ | `U` | The type of the value returned by the map function or the default value. |
447
+
448
+ #### Parameters
449
+
450
+ | Parameter | Type | Description |
451
+ | :------ | :------ | :------ |
452
+ | `defaultValue` | `U` | The value to return if the result is `Err`. |
453
+ | `fn` | (`value`) => `U` | A function that takes the `Ok` value and returns a new value. |
454
+
455
+ #### Returns
456
+
457
+ `U`
458
+
459
+ #### Source
460
+
461
+ [enum/prelude.ts:487](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L487)
462
+
463
+ ***
464
+
465
+ ### mapOrElse()
466
+
467
+ ```ts
468
+ mapOrElse<U>(defaultFn, fn): U
469
+ ```
470
+
471
+ Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or computes a default (if `Err`).
472
+
473
+ #### Type parameters
474
+
475
+ | Type parameter | Description |
476
+ | :------ | :------ |
477
+ | `U` | The type of the value returned by the map function or the default function. |
478
+
479
+ #### Parameters
480
+
481
+ | Parameter | Type | Description |
482
+ | :------ | :------ | :------ |
483
+ | `defaultFn` | (`error`) => `U` | A function that returns the default value. |
484
+ | `fn` | (`value`) => `U` | A function that takes the `Ok` value and returns a new value. |
485
+
486
+ #### Returns
487
+
488
+ `U`
489
+
490
+ #### Source
491
+
492
+ [enum/prelude.ts:495](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L495)
493
+
494
+ ***
495
+
496
+ ### ok()
497
+
498
+ ```ts
499
+ ok(): Option<T>
500
+ ```
501
+
502
+ Converts from `Result<T, E>` to `Option<T>`.
503
+ If the result is `Ok`, returns `Some(T)`.
504
+ If the result is `Err`, returns `None`.
505
+
506
+ #### Returns
507
+
508
+ [`Option`](Option.md)\<`T`\>
509
+
510
+ #### Source
511
+
512
+ [enum/prelude.ts:435](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L435)
513
+
514
+ ***
515
+
516
+ ### or()
517
+
518
+ ```ts
519
+ or<F>(other): Result<T, F>
520
+ ```
521
+
522
+ Returns `this` if it is `Ok`, otherwise returns the passed `Result`.
523
+
524
+ #### Type parameters
525
+
526
+ | Type parameter | Description |
527
+ | :------ | :------ |
528
+ | `F` | The type of the error in the other `Result`. |
529
+
530
+ #### Parameters
531
+
532
+ | Parameter | Type | Description |
533
+ | :------ | :------ | :------ |
534
+ | `other` | [`Result`](Result.md)\<`T`, `F`\> | The `Result` to return if `this` is `Err`. |
535
+
536
+ #### Returns
537
+
538
+ [`Result`](Result.md)\<`T`, `F`\>
539
+
540
+ `this` if it is `Ok`, otherwise returns `other`.
541
+
542
+ #### Source
543
+
544
+ [enum/prelude.ts:526](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L526)
545
+
546
+ ***
547
+
548
+ ### orElse()
549
+
550
+ ```ts
551
+ orElse<F>(fn): Result<T, F>
552
+ ```
553
+
554
+ Calls the provided function with the contained error if `this` is `Err`, otherwise returns `this` as `Ok`.
555
+
556
+ #### Type parameters
557
+
558
+ | Type parameter | Description |
559
+ | :------ | :------ |
560
+ | `F` | The type of the error returned by the function. |
561
+
562
+ #### Parameters
563
+
564
+ | Parameter | Type | Description |
565
+ | :------ | :------ | :------ |
566
+ | `fn` | (`error`) => [`Result`](Result.md)\<`T`, `F`\> | A function that takes the `Err` value and returns a `Result`. |
567
+
568
+ #### Returns
569
+
570
+ [`Result`](Result.md)\<`T`, `F`\>
571
+
572
+ The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.
573
+
574
+ #### Source
575
+
576
+ [enum/prelude.ts:542](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L542)
577
+
578
+ ***
579
+
580
+ ### transpose()
581
+
582
+ ```ts
583
+ transpose<T>(this): Option<Result<T, E>>
584
+ ```
585
+
586
+ Transposes a `Result` of an `Option` into an `Option` of a `Result`.
587
+
588
+ #### Type parameters
589
+
590
+ | Type parameter | Description |
591
+ | :------ | :------ |
592
+ | `T` | The type of the success value in the `Ok` variant of the `Option`. |
593
+
594
+ #### Parameters
595
+
596
+ | Parameter | Type |
597
+ | :------ | :------ |
598
+ | `this` | [`Result`](Result.md)\<[`Option`](Option.md)\<`T`\>, `E`\> |
599
+
600
+ #### Returns
601
+
602
+ [`Option`](Option.md)\<[`Result`](Result.md)\<`T`, `E`\>\>
603
+
604
+ `Some` containing `Ok` if the result is `Ok` containing `Some`,
605
+ `Some` containing `Err` if the result is `Err`,
606
+ `None` if the result is `Ok` containing `None`.
607
+
608
+ #### Source
609
+
610
+ [enum/prelude.ts:451](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L451)
611
+
612
+ ***
613
+
614
+ ### unwrap()
615
+
616
+ ```ts
617
+ unwrap(): T
618
+ ```
619
+
620
+ Returns the contained `Ok` value.
621
+
622
+ #### Returns
623
+
624
+ `T`
625
+
626
+ #### Throws
627
+
628
+ Throws an error if the result is an `Err`.
629
+
630
+ #### Source
631
+
632
+ [enum/prelude.ts:391](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L391)
633
+
634
+ ***
635
+
636
+ ### unwrapErr()
637
+
638
+ ```ts
639
+ unwrapErr(): E
640
+ ```
641
+
642
+ Returns the contained `Err` value.
643
+
644
+ #### Returns
645
+
646
+ `E`
647
+
648
+ #### Throws
649
+
650
+ Throws an error if the result is an `Ok`.
651
+
652
+ #### Source
653
+
654
+ [enum/prelude.ts:420](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L420)
655
+
656
+ ***
657
+
658
+ ### unwrapOr()
659
+
660
+ ```ts
661
+ unwrapOr(defaultValue): T
662
+ ```
663
+
664
+ Returns the contained `Ok` value or a provided default.
665
+
666
+ #### Parameters
667
+
668
+ | Parameter | Type | Description |
669
+ | :------ | :------ | :------ |
670
+ | `defaultValue` | `T` | The value to return if the result is an `Err`. |
671
+
672
+ #### Returns
673
+
674
+ `T`
675
+
676
+ #### Source
677
+
678
+ [enum/prelude.ts:397](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L397)
679
+
680
+ ***
681
+
682
+ ### unwrapOrElse()
683
+
684
+ ```ts
685
+ unwrapOrElse(fn): T
686
+ ```
687
+
688
+ Returns the contained `Ok` value or computes it from a closure if the result is `Err`.
689
+
690
+ #### Parameters
691
+
692
+ | Parameter | Type | Description |
693
+ | :------ | :------ | :------ |
694
+ | `fn` | (`error`) => `T` | A function that takes the `Err` value and returns an `Ok` value. |
695
+
696
+ #### Returns
697
+
698
+ `T`
699
+
700
+ #### Source
701
+
702
+ [enum/prelude.ts:403](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L403)
@@ -0,0 +1,24 @@
1
+ [**happy-rusty**](../index.md) • **Docs**
2
+
3
+ ***
4
+
5
+ [happy-rusty](../index.md) / AsyncIOResult
6
+
7
+ # Type alias: AsyncIOResult\<T\>
8
+
9
+ ```ts
10
+ type AsyncIOResult<T>: Promise<IOResult<T>>;
11
+ ```
12
+
13
+ Represents an asynchronous I/O operation that yields a `Result<T, Error>`.
14
+ This is a promise that resolves to `Ok(T)` if the I/O operation was successful, or `Err(Error)` if there was an error.
15
+
16
+ ## Type parameters
17
+
18
+ | Type parameter | Description |
19
+ | :------ | :------ |
20
+ | `T` | The type of the value that is produced by a successful I/O operation. |
21
+
22
+ ## Source
23
+
24
+ [enum/prelude.ts:609](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L609)