happy-rusty 1.4.0 → 1.6.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +206 -0
  2. package/README.cn.md +253 -26
  3. package/README.md +249 -28
  4. package/dist/main.cjs +436 -32
  5. package/dist/main.cjs.map +1 -1
  6. package/dist/main.mjs +428 -33
  7. package/dist/main.mjs.map +1 -1
  8. package/dist/types.d.ts +2070 -66
  9. package/package.json +37 -24
  10. package/dist/types.d.ts.map +0 -1
  11. package/docs/README.md +0 -47
  12. package/docs/functions/Err.md +0 -46
  13. package/docs/functions/Ok.md +0 -70
  14. package/docs/functions/Some.md +0 -45
  15. package/docs/functions/isOption.md +0 -35
  16. package/docs/functions/isResult.md +0 -36
  17. package/docs/functions/promiseToAsyncResult.md +0 -50
  18. package/docs/interfaces/None.md +0 -850
  19. package/docs/interfaces/Option.md +0 -761
  20. package/docs/interfaces/Result.md +0 -777
  21. package/docs/type-aliases/AsyncIOResult.md +0 -24
  22. package/docs/type-aliases/AsyncOption.md +0 -24
  23. package/docs/type-aliases/AsyncResult.md +0 -25
  24. package/docs/type-aliases/AsyncVoidIOResult.md +0 -17
  25. package/docs/type-aliases/AsyncVoidResult.md +0 -23
  26. package/docs/type-aliases/IOResult.md +0 -24
  27. package/docs/type-aliases/VoidIOResult.md +0 -17
  28. package/docs/type-aliases/VoidResult.md +0 -23
  29. package/docs/variables/None.md +0 -18
  30. package/docs/variables/RESULT_FALSE.md +0 -18
  31. package/docs/variables/RESULT_TRUE.md +0 -18
  32. package/docs/variables/RESULT_VOID.md +0 -17
  33. package/docs/variables/RESULT_ZERO.md +0 -18
  34. package/src/enum/constants.ts +0 -30
  35. package/src/enum/core.ts +0 -569
  36. package/src/enum/defines.ts +0 -62
  37. package/src/enum/extensions.ts +0 -31
  38. package/src/enum/mod.ts +0 -6
  39. package/src/enum/prelude.ts +0 -549
  40. package/src/enum/symbols.ts +0 -9
  41. package/src/enum/utils.ts +0 -27
  42. package/src/mod.ts +0 -1
@@ -1,777 +0,0 @@
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
- ## 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
- ## 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
- #### Defined in
63
-
64
- [core.ts:489](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L489)
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
- #### Defined in
95
-
96
- [core.ts:505](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L505)
97
-
98
- ***
99
-
100
- ### asErr()
101
-
102
- ```ts
103
- asErr<U>(): Result<U, E>
104
- ```
105
-
106
- Transforms the current Result into a new Result where the type of the success result is replaced with a new type `U`.
107
- The type of the error result remains unchanged.
108
- Useful where you need to return an Error chained to another type.
109
- Just same as `result as unknown as Result<U, E>`.
110
-
111
- #### Type Parameters
112
-
113
- | Type Parameter | Description |
114
- | ------ | ------ |
115
- | `U` | The new type for the success result. |
116
-
117
- #### Returns
118
-
119
- [`Result`](Result.md)\<`U`, `E`\>
120
-
121
- `this` but the success result type is `U`.
122
-
123
- #### Defined in
124
-
125
- [core.ts:563](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L563)
126
-
127
- ***
128
-
129
- ### asOk()
130
-
131
- ```ts
132
- asOk<F>(): Result<T, F>
133
- ```
134
-
135
- Transforms the current Result into a new Result where the type of the error result is replaced with a new type `F`.
136
- The type of the success result remains unchanged.
137
- Just same as `result as unknown as Result<T, F>`.
138
-
139
- #### Type Parameters
140
-
141
- | Type Parameter | Description |
142
- | ------ | ------ |
143
- | `F` | The new type for the error result. |
144
-
145
- #### Returns
146
-
147
- [`Result`](Result.md)\<`T`, `F`\>
148
-
149
- `this` but the error result type is `F`.
150
-
151
- #### Defined in
152
-
153
- [core.ts:552](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L552)
154
-
155
- ***
156
-
157
- ### eq()
158
-
159
- ```ts
160
- eq(other): boolean
161
- ```
162
-
163
- Tests whether `this` and `other` are both `Ok` containing equal values, or both are `Err` containing equal errors.
164
-
165
- #### Parameters
166
-
167
- | Parameter | Type | Description |
168
- | ------ | ------ | ------ |
169
- | `other` | [`Result`](Result.md)\<`T`, `E`\> | The other `Result` to compare with. |
170
-
171
- #### Returns
172
-
173
- `boolean`
174
-
175
- `true` if `this` and `other` are both `Ok` with equal values, or both are `Err` with equal errors, otherwise `false`.
176
-
177
- #### Defined in
178
-
179
- [core.ts:540](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L540)
180
-
181
- ***
182
-
183
- ### err()
184
-
185
- ```ts
186
- err(): Option<E>
187
- ```
188
-
189
- Converts from `Result<T, E>` to `Option<E>`.
190
- If the result is `Err`, returns `Some(E)`.
191
- If the result is `Ok`, returns `None`.
192
-
193
- #### Returns
194
-
195
- [`Option`](Option.md)\<`E`\>
196
-
197
- #### Defined in
198
-
199
- [core.ts:413](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L413)
200
-
201
- ***
202
-
203
- ### expect()
204
-
205
- ```ts
206
- expect(msg): T
207
- ```
208
-
209
- Returns the contained `Ok` value, with a provided error message if the result is `Err`.
210
-
211
- #### Parameters
212
-
213
- | Parameter | Type | Description |
214
- | ------ | ------ | ------ |
215
- | `msg` | `string` | The error message to provide if the result is an `Err`. |
216
-
217
- #### Returns
218
-
219
- `T`
220
-
221
- #### Throws
222
-
223
- Throws an error with the provided message if the result is an `Err`.
224
-
225
- #### Defined in
226
-
227
- [core.ts:356](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L356)
228
-
229
- ***
230
-
231
- ### expectErr()
232
-
233
- ```ts
234
- expectErr(msg): E
235
- ```
236
-
237
- Returns the contained `Err` value, with a provided error message if the result is `Ok`.
238
-
239
- #### Parameters
240
-
241
- | Parameter | Type | Description |
242
- | ------ | ------ | ------ |
243
- | `msg` | `string` | The error message to provide if the result is an `Ok`. |
244
-
245
- #### Returns
246
-
247
- `E`
248
-
249
- #### Throws
250
-
251
- Throws an error with the provided message if the result is an `Ok`.
252
-
253
- #### Defined in
254
-
255
- [core.ts:385](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L385)
256
-
257
- ***
258
-
259
- ### flatten()
260
-
261
- ```ts
262
- flatten<T>(this): Result<T, E>
263
- ```
264
-
265
- Converts from `Result<Result<T, E>, E>` to `Result<T, E>`.
266
- If the result is `Ok(Ok(T))`, returns `Ok(T)`.
267
- If the result is `Ok(Err(E))` or `Err(E)`, returns `Err(E)`.
268
-
269
- #### Type Parameters
270
-
271
- | Type Parameter |
272
- | ------ |
273
- | `T` |
274
-
275
- #### Parameters
276
-
277
- | Parameter | Type |
278
- | ------ | ------ |
279
- | `this` | [`Result`](Result.md)\<[`Result`](Result.md)\<`T`, `E`\>, `E`\> |
280
-
281
- #### Returns
282
-
283
- [`Result`](Result.md)\<`T`, `E`\>
284
-
285
- #### Defined in
286
-
287
- [core.ts:473](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L473)
288
-
289
- ***
290
-
291
- ### inspect()
292
-
293
- ```ts
294
- inspect(fn): this
295
- ```
296
-
297
- Calls the provided function with the contained value if `this` is `Ok`, for side effects only.
298
- Does not modify the `Result`.
299
-
300
- #### Parameters
301
-
302
- | Parameter | Type | Description |
303
- | ------ | ------ | ------ |
304
- | `fn` | (`value`) => `void` | A function to call with the `Ok` value. |
305
-
306
- #### Returns
307
-
308
- `this`
309
-
310
- `this`, unmodified.
311
-
312
- #### Defined in
313
-
314
- [core.ts:523](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L523)
315
-
316
- ***
317
-
318
- ### inspectErr()
319
-
320
- ```ts
321
- inspectErr(fn): this
322
- ```
323
-
324
- Calls the provided function with the contained error if `this` is `Err`, for side effects only.
325
- Does not modify the `Result`.
326
-
327
- #### Parameters
328
-
329
- | Parameter | Type | Description |
330
- | ------ | ------ | ------ |
331
- | `fn` | (`error`) => `void` | A function to call with the `Err` value. |
332
-
333
- #### Returns
334
-
335
- `this`
336
-
337
- `this`, unmodified.
338
-
339
- #### Defined in
340
-
341
- [core.ts:531](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L531)
342
-
343
- ***
344
-
345
- ### isErr()
346
-
347
- ```ts
348
- isErr(): boolean
349
- ```
350
-
351
- Returns `true` if the result is `Err`.
352
-
353
- #### Returns
354
-
355
- `boolean`
356
-
357
- #### Defined in
358
-
359
- [core.ts:329](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L329)
360
-
361
- ***
362
-
363
- ### isErrAnd()
364
-
365
- ```ts
366
- isErrAnd(predicate): boolean
367
- ```
368
-
369
- Returns `true` if the result is `Err` and the provided predicate returns `true` for the contained error.
370
-
371
- #### Parameters
372
-
373
- | Parameter | Type | Description |
374
- | ------ | ------ | ------ |
375
- | `predicate` | (`error`) => `boolean` | A function that takes the `Err` value and returns a boolean. |
376
-
377
- #### Returns
378
-
379
- `boolean`
380
-
381
- #### Defined in
382
-
383
- [core.ts:341](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L341)
384
-
385
- ***
386
-
387
- ### isOk()
388
-
389
- ```ts
390
- isOk(): boolean
391
- ```
392
-
393
- Returns `true` if the result is `Ok`.
394
-
395
- #### Returns
396
-
397
- `boolean`
398
-
399
- #### Defined in
400
-
401
- [core.ts:324](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L324)
402
-
403
- ***
404
-
405
- ### isOkAnd()
406
-
407
- ```ts
408
- isOkAnd(predicate): boolean
409
- ```
410
-
411
- Returns `true` if the result is `Ok` and the provided predicate returns `true` for the contained value.
412
-
413
- #### Parameters
414
-
415
- | Parameter | Type | Description |
416
- | ------ | ------ | ------ |
417
- | `predicate` | (`value`) => `boolean` | A function that takes the `Ok` value and returns a boolean. |
418
-
419
- #### Returns
420
-
421
- `boolean`
422
-
423
- #### Defined in
424
-
425
- [core.ts:335](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L335)
426
-
427
- ***
428
-
429
- ### map()
430
-
431
- ```ts
432
- map<U>(fn): Result<U, E>
433
- ```
434
-
435
- Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,
436
- leaving an `Err` value untouched.
437
-
438
- #### Type Parameters
439
-
440
- | Type Parameter | Description |
441
- | ------ | ------ |
442
- | `U` | The type of the value returned by the map function. |
443
-
444
- #### Parameters
445
-
446
- | Parameter | Type | Description |
447
- | ------ | ------ | ------ |
448
- | `fn` | (`value`) => `U` | A function that takes the `Ok` value and returns a new value. |
449
-
450
- #### Returns
451
-
452
- [`Result`](Result.md)\<`U`, `E`\>
453
-
454
- #### Defined in
455
-
456
- [core.ts:434](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L434)
457
-
458
- ***
459
-
460
- ### mapErr()
461
-
462
- ```ts
463
- mapErr<F>(fn): Result<T, F>
464
- ```
465
-
466
- Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,
467
- leaving an `Ok` value untouched.
468
-
469
- #### Type Parameters
470
-
471
- | Type Parameter | Description |
472
- | ------ | ------ |
473
- | `F` | The type of the error returned by the map function. |
474
-
475
- #### Parameters
476
-
477
- | Parameter | Type | Description |
478
- | ------ | ------ | ------ |
479
- | `fn` | (`error`) => `F` | A function that takes the `Err` value and returns a new error value. |
480
-
481
- #### Returns
482
-
483
- [`Result`](Result.md)\<`T`, `F`\>
484
-
485
- #### Defined in
486
-
487
- [core.ts:446](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L446)
488
-
489
- ***
490
-
491
- ### mapOr()
492
-
493
- ```ts
494
- mapOr<U>(defaultValue, fn): U
495
- ```
496
-
497
- 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`).
498
-
499
- #### Type Parameters
500
-
501
- | Type Parameter | Description |
502
- | ------ | ------ |
503
- | `U` | The type of the value returned by the map function or the default value. |
504
-
505
- #### Parameters
506
-
507
- | Parameter | Type | Description |
508
- | ------ | ------ | ------ |
509
- | `defaultValue` | `U` | The value to return if the result is `Err`. |
510
- | `fn` | (`value`) => `U` | A function that takes the `Ok` value and returns a new value. |
511
-
512
- #### Returns
513
-
514
- `U`
515
-
516
- #### Defined in
517
-
518
- [core.ts:458](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L458)
519
-
520
- ***
521
-
522
- ### mapOrElse()
523
-
524
- ```ts
525
- mapOrElse<U>(defaultFn, fn): U
526
- ```
527
-
528
- Maps a `Result<T, E>` to `U` by applying a function to the contained `Ok` value (if `Ok`), or computes a default (if `Err`).
529
-
530
- #### Type Parameters
531
-
532
- | Type Parameter | Description |
533
- | ------ | ------ |
534
- | `U` | The type of the value returned by the map function or the default function. |
535
-
536
- #### Parameters
537
-
538
- | Parameter | Type | Description |
539
- | ------ | ------ | ------ |
540
- | `defaultFn` | (`error`) => `U` | A function that returns the default value. |
541
- | `fn` | (`value`) => `U` | A function that takes the `Ok` value and returns a new value. |
542
-
543
- #### Returns
544
-
545
- `U`
546
-
547
- #### Defined in
548
-
549
- [core.ts:466](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L466)
550
-
551
- ***
552
-
553
- ### ok()
554
-
555
- ```ts
556
- ok(): Option<T>
557
- ```
558
-
559
- Converts from `Result<T, E>` to `Option<T>`.
560
- If the result is `Ok`, returns `Some(T)`.
561
- If the result is `Err`, returns `None`.
562
-
563
- #### Returns
564
-
565
- [`Option`](Option.md)\<`T`\>
566
-
567
- #### Defined in
568
-
569
- [core.ts:406](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L406)
570
-
571
- ***
572
-
573
- ### or()
574
-
575
- ```ts
576
- or<F>(other): Result<T, F>
577
- ```
578
-
579
- Returns `this` if it is `Ok`, otherwise returns the passed `Result`.
580
-
581
- #### Type Parameters
582
-
583
- | Type Parameter | Description |
584
- | ------ | ------ |
585
- | `F` | The type of the error in the other `Result`. |
586
-
587
- #### Parameters
588
-
589
- | Parameter | Type | Description |
590
- | ------ | ------ | ------ |
591
- | `other` | [`Result`](Result.md)\<`T`, `F`\> | The `Result` to return if `this` is `Err`. |
592
-
593
- #### Returns
594
-
595
- [`Result`](Result.md)\<`T`, `F`\>
596
-
597
- `this` if it is `Ok`, otherwise returns `other`.
598
-
599
- #### Defined in
600
-
601
- [core.ts:497](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L497)
602
-
603
- ***
604
-
605
- ### orElse()
606
-
607
- ```ts
608
- orElse<F>(fn): Result<T, F>
609
- ```
610
-
611
- Calls the provided function with the contained error if `this` is `Err`, otherwise returns `this` as `Ok`.
612
-
613
- #### Type Parameters
614
-
615
- | Type Parameter | Description |
616
- | ------ | ------ |
617
- | `F` | The type of the error returned by the function. |
618
-
619
- #### Parameters
620
-
621
- | Parameter | Type | Description |
622
- | ------ | ------ | ------ |
623
- | `fn` | (`error`) => [`Result`](Result.md)\<`T`, `F`\> | A function that takes the `Err` value and returns a `Result`. |
624
-
625
- #### Returns
626
-
627
- [`Result`](Result.md)\<`T`, `F`\>
628
-
629
- The result of `fn` if `this` is `Err`, otherwise `this` as `Ok`.
630
-
631
- #### Defined in
632
-
633
- [core.ts:513](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L513)
634
-
635
- ***
636
-
637
- ### toString()
638
-
639
- ```ts
640
- toString(): string
641
- ```
642
-
643
- Custom `toString` implementation that uses the `Result`'s contained value.
644
-
645
- #### Returns
646
-
647
- `string`
648
-
649
- #### Defined in
650
-
651
- [core.ts:568](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L568)
652
-
653
- ***
654
-
655
- ### transpose()
656
-
657
- ```ts
658
- transpose<T>(this): Option<Result<T, E>>
659
- ```
660
-
661
- Transposes a `Result` of an `Option` into an `Option` of a `Result`.
662
-
663
- #### Type Parameters
664
-
665
- | Type Parameter | Description |
666
- | ------ | ------ |
667
- | `T` | The type of the success value in the `Ok` variant of the `Option`. |
668
-
669
- #### Parameters
670
-
671
- | Parameter | Type |
672
- | ------ | ------ |
673
- | `this` | [`Result`](Result.md)\<[`Option`](Option.md)\<`T`\>, `E`\> |
674
-
675
- #### Returns
676
-
677
- [`Option`](Option.md)\<[`Result`](Result.md)\<`T`, `E`\>\>
678
-
679
- `Some` containing `Ok` if the result is `Ok` containing `Some`,
680
- `Some` containing `Err` if the result is `Err`,
681
- `None` if the result is `Ok` containing `None`.
682
-
683
- #### Defined in
684
-
685
- [core.ts:422](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L422)
686
-
687
- ***
688
-
689
- ### unwrap()
690
-
691
- ```ts
692
- unwrap(): T
693
- ```
694
-
695
- Returns the contained `Ok` value.
696
-
697
- #### Returns
698
-
699
- `T`
700
-
701
- #### Throws
702
-
703
- Throws an error if the result is an `Err`.
704
-
705
- #### Defined in
706
-
707
- [core.ts:362](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L362)
708
-
709
- ***
710
-
711
- ### unwrapErr()
712
-
713
- ```ts
714
- unwrapErr(): E
715
- ```
716
-
717
- Returns the contained `Err` value.
718
-
719
- #### Returns
720
-
721
- `E`
722
-
723
- #### Throws
724
-
725
- Throws an error if the result is an `Ok`.
726
-
727
- #### Defined in
728
-
729
- [core.ts:391](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L391)
730
-
731
- ***
732
-
733
- ### unwrapOr()
734
-
735
- ```ts
736
- unwrapOr(defaultValue): T
737
- ```
738
-
739
- Returns the contained `Ok` value or a provided default.
740
-
741
- #### Parameters
742
-
743
- | Parameter | Type | Description |
744
- | ------ | ------ | ------ |
745
- | `defaultValue` | `T` | The value to return if the result is an `Err`. |
746
-
747
- #### Returns
748
-
749
- `T`
750
-
751
- #### Defined in
752
-
753
- [core.ts:368](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L368)
754
-
755
- ***
756
-
757
- ### unwrapOrElse()
758
-
759
- ```ts
760
- unwrapOrElse(fn): T
761
- ```
762
-
763
- Returns the contained `Ok` value or computes it from a closure if the result is `Err`.
764
-
765
- #### Parameters
766
-
767
- | Parameter | Type | Description |
768
- | ------ | ------ | ------ |
769
- | `fn` | (`error`) => `T` | A function that takes the `Err` value and returns an `Ok` value. |
770
-
771
- #### Returns
772
-
773
- `T`
774
-
775
- #### Defined in
776
-
777
- [core.ts:374](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L374)