happy-rusty 1.5.0 → 1.6.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/LICENSE +21 -674
  3. package/README.cn.md +265 -19
  4. package/README.md +261 -21
  5. package/dist/main.cjs +382 -32
  6. package/dist/main.cjs.map +1 -1
  7. package/dist/main.mjs +374 -33
  8. package/dist/main.mjs.map +1 -1
  9. package/dist/types.d.ts +2002 -52
  10. package/package.json +38 -25
  11. package/dist/types.d.ts.map +0 -1
  12. package/docs/README.md +0 -47
  13. package/docs/functions/Err.md +0 -46
  14. package/docs/functions/Ok.md +0 -70
  15. package/docs/functions/Some.md +0 -45
  16. package/docs/functions/isOption.md +0 -35
  17. package/docs/functions/isResult.md +0 -36
  18. package/docs/functions/promiseToAsyncResult.md +0 -50
  19. package/docs/interfaces/None.md +0 -979
  20. package/docs/interfaces/Option.md +0 -857
  21. package/docs/interfaces/Result.md +0 -903
  22. package/docs/type-aliases/AsyncIOResult.md +0 -24
  23. package/docs/type-aliases/AsyncOption.md +0 -24
  24. package/docs/type-aliases/AsyncResult.md +0 -25
  25. package/docs/type-aliases/AsyncVoidIOResult.md +0 -17
  26. package/docs/type-aliases/AsyncVoidResult.md +0 -23
  27. package/docs/type-aliases/IOResult.md +0 -24
  28. package/docs/type-aliases/VoidIOResult.md +0 -17
  29. package/docs/type-aliases/VoidResult.md +0 -23
  30. package/docs/variables/None.md +0 -18
  31. package/docs/variables/RESULT_FALSE.md +0 -18
  32. package/docs/variables/RESULT_TRUE.md +0 -18
  33. package/docs/variables/RESULT_VOID.md +0 -17
  34. package/docs/variables/RESULT_ZERO.md +0 -18
  35. package/src/enum/constants.ts +0 -30
  36. package/src/enum/core.ts +0 -635
  37. package/src/enum/defines.ts +0 -45
  38. package/src/enum/extensions.ts +0 -31
  39. package/src/enum/mod.ts +0 -6
  40. package/src/enum/prelude.ts +0 -619
  41. package/src/enum/symbols.ts +0 -9
  42. package/src/enum/utils.ts +0 -27
  43. package/src/mod.ts +0 -1
@@ -1,979 +0,0 @@
1
- [**happy-rusty**](../README.md) • **Docs**
2
-
3
- ***
4
-
5
- [happy-rusty](../README.md) / None
6
-
7
- # Interface: None
8
-
9
- Represents the absence of a value, as a specialized `Option` type.
10
- The type parameter is set to `never` because `None` does not hold a value.
11
-
12
- ## Extends
13
-
14
- - [`Option`](Option.md)\<`never`\>
15
-
16
- ## Properties
17
-
18
- | Property | Modifier | Type | Description | Overrides | Defined in |
19
- | ------ | ------ | ------ | ------ | ------ | ------ |
20
- | `[OptionKindSymbol]` | `readonly` | `"None"` | When using `None` alone, the following overrides can make type inference more accurate. | `Option.[OptionKindSymbol]` | [prelude.ts:15](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L15) |
21
-
22
- ## Methods
23
-
24
- ### and()
25
-
26
- ```ts
27
- and<U>(other): None
28
- ```
29
-
30
- Returns `None` if the Option is `None`, otherwise returns `other`.
31
- This is sometimes called "and then" because it is similar to a logical AND operation.
32
-
33
- #### Type Parameters
34
-
35
- | Type Parameter | Description |
36
- | ------ | ------ |
37
- | `U` | The type of the value in the other `Option`. |
38
-
39
- #### Parameters
40
-
41
- | Parameter | Type | Description |
42
- | ------ | ------ | ------ |
43
- | `other` | [`Option`](Option.md)\<`U`\> | The `Option` to return if `this` is `Some`. |
44
-
45
- #### Returns
46
-
47
- [`None`](None.md)
48
-
49
- `None` if `this` is `None`, otherwise returns `other`.
50
-
51
- #### Overrides
52
-
53
- [`Option`](Option.md).[`and`](Option.md#and)
54
-
55
- #### Defined in
56
-
57
- [prelude.ts:42](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L42)
58
-
59
- ***
60
-
61
- ### andThen()
62
-
63
- ```ts
64
- andThen<U>(fn): None
65
- ```
66
-
67
- Returns `None` if the Option is `None`, otherwise calls `fn` with the wrapped value and returns the result.
68
- This function can be used for control flow based on `Option` values.
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`) => [`Option`](Option.md)\<`U`\> | A function that takes the contained value and returns an `Option`. |
81
-
82
- #### Returns
83
-
84
- [`None`](None.md)
85
-
86
- The result of `fn` if `this` is `Some`, otherwise `None`.
87
-
88
- #### Overrides
89
-
90
- [`Option`](Option.md).[`andThen`](Option.md#andthen)
91
-
92
- #### Defined in
93
-
94
- [prelude.ts:43](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L43)
95
-
96
- ***
97
-
98
- ### andThenAsync()
99
-
100
- ```ts
101
- andThenAsync<U>(fn): Promise<None>
102
- ```
103
-
104
- Asynchronous version of `andThen`.
105
-
106
- #### Type Parameters
107
-
108
- | Type Parameter |
109
- | ------ |
110
- | `U` |
111
-
112
- #### Parameters
113
-
114
- | Parameter | Type |
115
- | ------ | ------ |
116
- | `fn` | (`value`) => [`AsyncOption`](../type-aliases/AsyncOption.md)\<`U`\> |
117
-
118
- #### Returns
119
-
120
- `Promise`\<[`None`](None.md)\>
121
-
122
- #### Overrides
123
-
124
- [`Option`](Option.md).[`andThenAsync`](Option.md#andthenasync)
125
-
126
- #### Defined in
127
-
128
- [prelude.ts:44](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L44)
129
-
130
- ***
131
-
132
- ### eq()
133
-
134
- ```ts
135
- eq<T>(other): boolean
136
- ```
137
-
138
- Tests whether `this` and `other` are both `Some` containing equal values, or both are `None`.
139
- This method can be used for comparing `Option` instances in a value-sensitive manner.
140
-
141
- #### Type Parameters
142
-
143
- | Type Parameter |
144
- | ------ |
145
- | `T` |
146
-
147
- #### Parameters
148
-
149
- | Parameter | Type | Description |
150
- | ------ | ------ | ------ |
151
- | `other` | [`Option`](Option.md)\<`T`\> | The other `Option` to compare with. |
152
-
153
- #### Returns
154
-
155
- `boolean`
156
-
157
- `true` if `this` and `other` are both `Some` with equal values, or both are `None`, otherwise `false`.
158
-
159
- #### Overrides
160
-
161
- [`Option`](Option.md).[`eq`](Option.md#eq)
162
-
163
- #### Defined in
164
-
165
- [prelude.ts:52](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L52)
166
-
167
- ***
168
-
169
- ### expect()
170
-
171
- ```ts
172
- expect(msg): never
173
- ```
174
-
175
- Returns the contained `Some` value, with a provided error message if the value is a `None`.
176
-
177
- #### Parameters
178
-
179
- | Parameter | Type | Description |
180
- | ------ | ------ | ------ |
181
- | `msg` | `string` | The error message to provide if the value is a `None`. |
182
-
183
- #### Returns
184
-
185
- `never`
186
-
187
- #### Throws
188
-
189
- Throws an error with the provided message if the Option is a `None`.
190
-
191
- #### Overrides
192
-
193
- [`Option`](Option.md).[`expect`](Option.md#expect)
194
-
195
- #### Defined in
196
-
197
- [prelude.ts:22](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L22)
198
-
199
- ***
200
-
201
- ### filter()
202
-
203
- ```ts
204
- filter(predicate): None
205
- ```
206
-
207
- Returns `None` if the Option is `None`, otherwise calls predicate with the wrapped value and returns:
208
- - `Some(t)` if predicate returns `true` (where `t` is the wrapped value), and
209
- - `None` if predicate returns `false`.
210
-
211
- #### Parameters
212
-
213
- | Parameter | Type | Description |
214
- | ------ | ------ | ------ |
215
- | `predicate` | (`value`) => `boolean` | A function that takes the contained value and returns a boolean. |
216
-
217
- #### Returns
218
-
219
- [`None`](None.md)
220
-
221
- #### Overrides
222
-
223
- [`Option`](Option.md).[`filter`](Option.md#filter)
224
-
225
- #### Defined in
226
-
227
- [prelude.ts:32](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L32)
228
-
229
- ***
230
-
231
- ### flatten()
232
-
233
- ```ts
234
- flatten(): None
235
- ```
236
-
237
- Converts from `Option<Option<T>>` to `Option<T>`.
238
-
239
- #### Returns
240
-
241
- [`None`](None.md)
242
-
243
- `None` if the Option is `None`, otherwise returns the contained `Option`.
244
-
245
- #### Overrides
246
-
247
- [`Option`](Option.md).[`flatten`](Option.md#flatten)
248
-
249
- #### Defined in
250
-
251
- [prelude.ts:33](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L33)
252
-
253
- ***
254
-
255
- ### inspect()
256
-
257
- ```ts
258
- inspect(fn): this
259
- ```
260
-
261
- Calls the provided function with the contained value if `this` is `Some`.
262
- This is primarily for side effects and does not transform the `Option`.
263
-
264
- #### Parameters
265
-
266
- | Parameter | Type | Description |
267
- | ------ | ------ | ------ |
268
- | `fn` | (`value`) => `void` | A function to call with the contained value. |
269
-
270
- #### Returns
271
-
272
- `this`
273
-
274
- `this`, unmodified, for chaining additional methods.
275
-
276
- #### Overrides
277
-
278
- [`Option`](Option.md).[`inspect`](Option.md#inspect)
279
-
280
- #### Defined in
281
-
282
- [prelude.ts:50](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L50)
283
-
284
- ***
285
-
286
- ### isNone()
287
-
288
- ```ts
289
- isNone(): true
290
- ```
291
-
292
- Returns `true` if the Option is a `None` value.
293
-
294
- #### Returns
295
-
296
- `true`
297
-
298
- #### Overrides
299
-
300
- [`Option`](Option.md).[`isNone`](Option.md#isnone)
301
-
302
- #### Defined in
303
-
304
- [prelude.ts:18](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L18)
305
-
306
- ***
307
-
308
- ### isSome()
309
-
310
- ```ts
311
- isSome(): false
312
- ```
313
-
314
- Returns `true` if the Option is a `Some` value.
315
-
316
- #### Returns
317
-
318
- `false`
319
-
320
- #### Overrides
321
-
322
- [`Option`](Option.md).[`isSome`](Option.md#issome)
323
-
324
- #### Defined in
325
-
326
- [prelude.ts:17](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L17)
327
-
328
- ***
329
-
330
- ### isSomeAnd()
331
-
332
- ```ts
333
- isSomeAnd(predicate): false
334
- ```
335
-
336
- Returns `true` if the Option is a `Some` value and the predicate returns `true` for the contained value.
337
-
338
- #### Parameters
339
-
340
- | Parameter | Type | Description |
341
- | ------ | ------ | ------ |
342
- | `predicate` | (`value`) => `boolean` | A function that takes the contained value and returns a boolean. |
343
-
344
- #### Returns
345
-
346
- `false`
347
-
348
- #### Overrides
349
-
350
- [`Option`](Option.md).[`isSomeAnd`](Option.md#issomeand)
351
-
352
- #### Defined in
353
-
354
- [prelude.ts:19](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L19)
355
-
356
- ***
357
-
358
- ### isSomeAndAsync()
359
-
360
- ```ts
361
- isSomeAndAsync(predicate): Promise<false>
362
- ```
363
-
364
- Asynchronous version of `isSomeAnd`.
365
-
366
- #### Parameters
367
-
368
- | Parameter | Type |
369
- | ------ | ------ |
370
- | `predicate` | (`value`) => `Promise`\<`boolean`\> |
371
-
372
- #### Returns
373
-
374
- `Promise`\<`false`\>
375
-
376
- #### Overrides
377
-
378
- [`Option`](Option.md).[`isSomeAndAsync`](Option.md#issomeandasync)
379
-
380
- #### Defined in
381
-
382
- [prelude.ts:20](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L20)
383
-
384
- ***
385
-
386
- ### map()
387
-
388
- ```ts
389
- map<U>(fn): None
390
- ```
391
-
392
- Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
393
-
394
- #### Type Parameters
395
-
396
- | Type Parameter | Description |
397
- | ------ | ------ |
398
- | `U` | The type of the value returned by the map function. |
399
-
400
- #### Parameters
401
-
402
- | Parameter | Type | Description |
403
- | ------ | ------ | ------ |
404
- | `fn` | (`value`) => `U` | A function that takes the contained value and returns a new value. |
405
-
406
- #### Returns
407
-
408
- [`None`](None.md)
409
-
410
- #### Overrides
411
-
412
- [`Option`](Option.md).[`map`](Option.md#map)
413
-
414
- #### Defined in
415
-
416
- [prelude.ts:34](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L34)
417
-
418
- ***
419
-
420
- ### mapOr()
421
-
422
- ```ts
423
- mapOr<U>(defaultValue, fn): U
424
- ```
425
-
426
- Maps an `Option<T>` to `U` by applying a function to the contained value (if any), or returns the provided default (if not).
427
-
428
- #### Type Parameters
429
-
430
- | Type Parameter | Description |
431
- | ------ | ------ |
432
- | `U` | The type of the value returned by the map function or the default value. |
433
-
434
- #### Parameters
435
-
436
- | Parameter | Type | Description |
437
- | ------ | ------ | ------ |
438
- | `defaultValue` | `U` | The value to return if the Option is `None`. |
439
- | `fn` | (`value`) => `U` | A function that takes the contained value and returns a new value. |
440
-
441
- #### Returns
442
-
443
- `U`
444
-
445
- #### Overrides
446
-
447
- [`Option`](Option.md).[`mapOr`](Option.md#mapor)
448
-
449
- #### Defined in
450
-
451
- [prelude.ts:35](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L35)
452
-
453
- ***
454
-
455
- ### mapOrElse()
456
-
457
- ```ts
458
- mapOrElse<U>(defaultFn, fn): U
459
- ```
460
-
461
- Maps an `Option<T>` to `U` by applying a function to a contained value (if any), or computes a default (if not).
462
-
463
- #### Type Parameters
464
-
465
- | Type Parameter | Description |
466
- | ------ | ------ |
467
- | `U` | The type of the value returned by the map function or the default function. |
468
-
469
- #### Parameters
470
-
471
- | Parameter | Type | Description |
472
- | ------ | ------ | ------ |
473
- | `defaultFn` | () => `U` | A function that returns the default value. |
474
- | `fn` | (`value`) => `U` | A function that takes the contained value and returns a new value. |
475
-
476
- #### Returns
477
-
478
- `U`
479
-
480
- #### Overrides
481
-
482
- [`Option`](Option.md).[`mapOrElse`](Option.md#maporelse)
483
-
484
- #### Defined in
485
-
486
- [prelude.ts:36](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L36)
487
-
488
- ***
489
-
490
- ### okOr()
491
-
492
- ```ts
493
- okOr<E>(error): Result<never, E>
494
- ```
495
-
496
- Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`.
497
-
498
- #### Type Parameters
499
-
500
- | Type Parameter | Description |
501
- | ------ | ------ |
502
- | `E` | The type of the error value in the `Err` variant of the resulting `Result`. |
503
-
504
- #### Parameters
505
-
506
- | Parameter | Type | Description |
507
- | ------ | ------ | ------ |
508
- | `error` | `E` | The error value to use if the Option is a `None`. |
509
-
510
- #### Returns
511
-
512
- [`Result`](Result.md)\<`never`, `E`\>
513
-
514
- #### Overrides
515
-
516
- [`Option`](Option.md).[`okOr`](Option.md#okor)
517
-
518
- #### Defined in
519
-
520
- [prelude.ts:28](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L28)
521
-
522
- ***
523
-
524
- ### okOrElse()
525
-
526
- ```ts
527
- okOrElse<E>(err): Result<never, E>
528
- ```
529
-
530
- Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`.
531
-
532
- #### Type Parameters
533
-
534
- | Type Parameter | Description |
535
- | ------ | ------ |
536
- | `E` | The type of the error value in the `Err` variant of the resulting `Result`. |
537
-
538
- #### Parameters
539
-
540
- | Parameter | Type | Description |
541
- | ------ | ------ | ------ |
542
- | `err` | () => `E` | A function that returns the error value. |
543
-
544
- #### Returns
545
-
546
- [`Result`](Result.md)\<`never`, `E`\>
547
-
548
- #### Overrides
549
-
550
- [`Option`](Option.md).[`okOrElse`](Option.md#okorelse)
551
-
552
- #### Defined in
553
-
554
- [prelude.ts:29](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L29)
555
-
556
- ***
557
-
558
- ### or()
559
-
560
- ```ts
561
- or<T>(other): Option<T>
562
- ```
563
-
564
- Returns the Option if it contains a value, otherwise returns `other`.
565
- This can be used for providing a fallback `Option`.
566
-
567
- #### Type Parameters
568
-
569
- | Type Parameter |
570
- | ------ |
571
- | `T` |
572
-
573
- #### Parameters
574
-
575
- | Parameter | Type | Description |
576
- | ------ | ------ | ------ |
577
- | `other` | [`Option`](Option.md)\<`T`\> | The fallback `Option` to use if `this` is `None`. |
578
-
579
- #### Returns
580
-
581
- [`Option`](Option.md)\<`T`\>
582
-
583
- `this` if it is `Some`, otherwise `other`.
584
-
585
- #### Overrides
586
-
587
- [`Option`](Option.md).[`or`](Option.md#or)
588
-
589
- #### Defined in
590
-
591
- [prelude.ts:45](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L45)
592
-
593
- ***
594
-
595
- ### orElse()
596
-
597
- ```ts
598
- orElse<T>(fn): Option<T>
599
- ```
600
-
601
- Returns the Option if it contains a value, otherwise calls `fn` and returns the result.
602
- This method can be used for lazy fallbacks, as `fn` is only evaluated if `this` is `None`.
603
-
604
- #### Type Parameters
605
-
606
- | Type Parameter |
607
- | ------ |
608
- | `T` |
609
-
610
- #### Parameters
611
-
612
- | Parameter | Type | Description |
613
- | ------ | ------ | ------ |
614
- | `fn` | () => [`Option`](Option.md)\<`T`\> | A function that produces an `Option`. |
615
-
616
- #### Returns
617
-
618
- [`Option`](Option.md)\<`T`\>
619
-
620
- `this` if it is `Some`, otherwise the result of `fn`.
621
-
622
- #### Overrides
623
-
624
- [`Option`](Option.md).[`orElse`](Option.md#orelse)
625
-
626
- #### Defined in
627
-
628
- [prelude.ts:46](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L46)
629
-
630
- ***
631
-
632
- ### orElseAsync()
633
-
634
- ```ts
635
- orElseAsync<T>(fn): AsyncOption<T>
636
- ```
637
-
638
- Asynchronous version of `orElse`.
639
-
640
- #### Type Parameters
641
-
642
- | Type Parameter |
643
- | ------ |
644
- | `T` |
645
-
646
- #### Parameters
647
-
648
- | Parameter | Type |
649
- | ------ | ------ |
650
- | `fn` | () => [`AsyncOption`](../type-aliases/AsyncOption.md)\<`T`\> |
651
-
652
- #### Returns
653
-
654
- [`AsyncOption`](../type-aliases/AsyncOption.md)\<`T`\>
655
-
656
- #### Overrides
657
-
658
- [`Option`](Option.md).[`orElseAsync`](Option.md#orelseasync)
659
-
660
- #### Defined in
661
-
662
- [prelude.ts:47](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L47)
663
-
664
- ***
665
-
666
- ### toString()
667
-
668
- ```ts
669
- toString(): string
670
- ```
671
-
672
- Custom `toString` implementation that uses the `Option`'s contained value.
673
-
674
- #### Returns
675
-
676
- `string`
677
-
678
- #### Inherited from
679
-
680
- [`Option`](Option.md).[`toString`](Option.md#tostring)
681
-
682
- #### Defined in
683
-
684
- [core.ts:302](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/core.ts#L302)
685
-
686
- ***
687
-
688
- ### transpose()
689
-
690
- ```ts
691
- transpose(): Result<None, never>
692
- ```
693
-
694
- Transposes an `Option` of a `Result` into a `Result` of an `Option`.
695
-
696
- #### Returns
697
-
698
- [`Result`](Result.md)\<[`None`](None.md), `never`\>
699
-
700
- `Ok` containing `Some` if the Option is a `Some` containing `Ok`,
701
- `Err` containing the error if the Option is a `Some` containing `Err`,
702
- `Ok` containing `None` if the Option is `None`.
703
-
704
- #### Overrides
705
-
706
- [`Option`](Option.md).[`transpose`](Option.md#transpose)
707
-
708
- #### Defined in
709
-
710
- [prelude.ts:30](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L30)
711
-
712
- ***
713
-
714
- ### unwrap()
715
-
716
- ```ts
717
- unwrap(): never
718
- ```
719
-
720
- Returns the contained `Some` value.
721
-
722
- #### Returns
723
-
724
- `never`
725
-
726
- #### Throws
727
-
728
- Throws an error if the value is a `None`.
729
-
730
- #### Overrides
731
-
732
- [`Option`](Option.md).[`unwrap`](Option.md#unwrap)
733
-
734
- #### Defined in
735
-
736
- [prelude.ts:23](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L23)
737
-
738
- ***
739
-
740
- ### unwrapOr()
741
-
742
- ```ts
743
- unwrapOr<T>(defaultValue): T
744
- ```
745
-
746
- Returns the contained `Some` value or a provided default.
747
-
748
- #### Type Parameters
749
-
750
- | Type Parameter |
751
- | ------ |
752
- | `T` |
753
-
754
- #### Parameters
755
-
756
- | Parameter | Type | Description |
757
- | ------ | ------ | ------ |
758
- | `defaultValue` | `T` | The value to return if the Option is a `None`. |
759
-
760
- #### Returns
761
-
762
- `T`
763
-
764
- #### Overrides
765
-
766
- [`Option`](Option.md).[`unwrapOr`](Option.md#unwrapor)
767
-
768
- #### Defined in
769
-
770
- [prelude.ts:24](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L24)
771
-
772
- ***
773
-
774
- ### unwrapOrElse()
775
-
776
- ```ts
777
- unwrapOrElse<T>(fn): T
778
- ```
779
-
780
- Returns the contained `Some` value or computes it from a closure.
781
-
782
- #### Type Parameters
783
-
784
- | Type Parameter |
785
- | ------ |
786
- | `T` |
787
-
788
- #### Parameters
789
-
790
- | Parameter | Type | Description |
791
- | ------ | ------ | ------ |
792
- | `fn` | () => `T` | A function that returns the default value. |
793
-
794
- #### Returns
795
-
796
- `T`
797
-
798
- #### Overrides
799
-
800
- [`Option`](Option.md).[`unwrapOrElse`](Option.md#unwraporelse)
801
-
802
- #### Defined in
803
-
804
- [prelude.ts:25](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L25)
805
-
806
- ***
807
-
808
- ### unwrapOrElseAsync()
809
-
810
- ```ts
811
- unwrapOrElseAsync<T>(fn): Promise<T>
812
- ```
813
-
814
- Asynchronous version of `unwrapOrElse`.
815
-
816
- #### Type Parameters
817
-
818
- | Type Parameter |
819
- | ------ |
820
- | `T` |
821
-
822
- #### Parameters
823
-
824
- | Parameter | Type |
825
- | ------ | ------ |
826
- | `fn` | () => `Promise`\<`T`\> |
827
-
828
- #### Returns
829
-
830
- `Promise`\<`T`\>
831
-
832
- #### Overrides
833
-
834
- [`Option`](Option.md).[`unwrapOrElseAsync`](Option.md#unwraporelseasync)
835
-
836
- #### Defined in
837
-
838
- [prelude.ts:26](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L26)
839
-
840
- ***
841
-
842
- ### unzip()
843
-
844
- ```ts
845
- unzip(): [None, None]
846
- ```
847
-
848
- Converts from `Option<[T, U]>` to `[Option<T>, Option<U>]`.
849
- If `this` is `Some([a, b])`, returns `[Some(a), Some(b)]`.
850
- If `this` is `None`, returns `[None, None]`.
851
-
852
- #### Returns
853
-
854
- [[`None`](None.md), [`None`](None.md)]
855
-
856
- A tuple of `Options`, one for each element in the original `Option` of a tuple.
857
-
858
- #### Overrides
859
-
860
- [`Option`](Option.md).[`unzip`](Option.md#unzip)
861
-
862
- #### Defined in
863
-
864
- [prelude.ts:40](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L40)
865
-
866
- ***
867
-
868
- ### xor()
869
-
870
- ```ts
871
- xor<T>(other): Option<T>
872
- ```
873
-
874
- Returns `Some` if exactly one of `this`, `other` is `Some`, otherwise returns `None`.
875
- This can be thought of as an exclusive or operation on `Option` values.
876
-
877
- #### Type Parameters
878
-
879
- | Type Parameter |
880
- | ------ |
881
- | `T` |
882
-
883
- #### Parameters
884
-
885
- | Parameter | Type | Description |
886
- | ------ | ------ | ------ |
887
- | `other` | [`Option`](Option.md)\<`T`\> | The other `Option` to compare with. |
888
-
889
- #### Returns
890
-
891
- [`Option`](Option.md)\<`T`\>
892
-
893
- `Some` if exactly one of `this` and `other` is `Some`, otherwise `None`.
894
-
895
- #### Overrides
896
-
897
- [`Option`](Option.md).[`xor`](Option.md#xor)
898
-
899
- #### Defined in
900
-
901
- [prelude.ts:48](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L48)
902
-
903
- ***
904
-
905
- ### zip()
906
-
907
- ```ts
908
- zip<U>(other): None
909
- ```
910
-
911
- Combines `this` with another `Option` by zipping their contained values.
912
- If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some([s, o])`.
913
- If either `this` or `other` is `None`, returns `None`.
914
-
915
- #### Type Parameters
916
-
917
- | Type Parameter | Description |
918
- | ------ | ------ |
919
- | `U` | The type of the value in the other `Option`. |
920
-
921
- #### Parameters
922
-
923
- | Parameter | Type | Description |
924
- | ------ | ------ | ------ |
925
- | `other` | [`Option`](Option.md)\<`U`\> | The other `Option` to zip with. |
926
-
927
- #### Returns
928
-
929
- [`None`](None.md)
930
-
931
- An `Option` containing a tuple of the values if both are `Some`, otherwise `None`.
932
-
933
- #### Overrides
934
-
935
- [`Option`](Option.md).[`zip`](Option.md#zip)
936
-
937
- #### Defined in
938
-
939
- [prelude.ts:38](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L38)
940
-
941
- ***
942
-
943
- ### zipWith()
944
-
945
- ```ts
946
- zipWith<U, R>(other, fn): None
947
- ```
948
-
949
- Zips `this` with another `Option` using a provided function to combine their contained values.
950
- If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some(fn(s, o))`.
951
- If either `this` or `other` is `None`, returns `None`.
952
-
953
- #### Type Parameters
954
-
955
- | Type Parameter | Description |
956
- | ------ | ------ |
957
- | `U` | The type of the value in the other `Option`. |
958
- | `R` | The return type of the combining function. |
959
-
960
- #### Parameters
961
-
962
- | Parameter | Type | Description |
963
- | ------ | ------ | ------ |
964
- | `other` | [`Option`](Option.md)\<`U`\> | The other `Option` to zip with. |
965
- | `fn` | (`value`, `otherValue`) => `R` | The function to combine the values from both `Options`. |
966
-
967
- #### Returns
968
-
969
- [`None`](None.md)
970
-
971
- An `Option` containing the result of `fn` if both `Options` are `Some`, otherwise `None`.
972
-
973
- #### Overrides
974
-
975
- [`Option`](Option.md).[`zipWith`](Option.md#zipwith)
976
-
977
- #### Defined in
978
-
979
- [prelude.ts:39](https://github.com/JiangJie/happy-rusty/blob/6efe20969984552f52d79aee092bb6925a077fe7/src/enum/prelude.ts#L39)