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