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,850 +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 | Inherited from | 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/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L15) |
21
- | `[toStringTag]` | `public` | `"Option"` | [object Option]. | - | [`Option`](Option.md).`[toStringTag]` | [core.ts:30](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L30) |
22
-
23
- ## Methods
24
-
25
- ### and()
26
-
27
- ```ts
28
- and<U>(other): None
29
- ```
30
-
31
- Returns `None` if the Option is `None`, otherwise returns `other`.
32
- This is sometimes called "and then" because it is similar to a logical AND operation.
33
-
34
- #### Type Parameters
35
-
36
- | Type Parameter | Description |
37
- | ------ | ------ |
38
- | `U` | The type of the value in the other `Option`. |
39
-
40
- #### Parameters
41
-
42
- | Parameter | Type | Description |
43
- | ------ | ------ | ------ |
44
- | `other` | [`Option`](Option.md)\<`U`\> | The `Option` to return if `this` is `Some`. |
45
-
46
- #### Returns
47
-
48
- [`None`](None.md)
49
-
50
- `None` if `this` is `None`, otherwise returns `other`.
51
-
52
- #### Overrides
53
-
54
- [`Option`](Option.md).[`and`](Option.md#and)
55
-
56
- #### Defined in
57
-
58
- [prelude.ts:30](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L30)
59
-
60
- ***
61
-
62
- ### andThen()
63
-
64
- ```ts
65
- andThen<U>(fn): None
66
- ```
67
-
68
- Returns `None` if the Option is `None`, otherwise calls `fn` with the wrapped value and returns the result.
69
- This function can be used for control flow based on `Option` values.
70
-
71
- #### Type Parameters
72
-
73
- | Type Parameter | Description |
74
- | ------ | ------ |
75
- | `U` | The type of the value returned by the function. |
76
-
77
- #### Parameters
78
-
79
- | Parameter | Type | Description |
80
- | ------ | ------ | ------ |
81
- | `fn` | (`value`) => [`Option`](Option.md)\<`U`\> | A function that takes the contained value and returns an `Option`. |
82
-
83
- #### Returns
84
-
85
- [`None`](None.md)
86
-
87
- The result of `fn` if `this` is `Some`, otherwise `None`.
88
-
89
- #### Overrides
90
-
91
- [`Option`](Option.md).[`andThen`](Option.md#andthen)
92
-
93
- #### Defined in
94
-
95
- [prelude.ts:31](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L31)
96
-
97
- ***
98
-
99
- ### eq()
100
-
101
- ```ts
102
- eq<T>(other): boolean
103
- ```
104
-
105
- Tests whether `this` and `other` are both `Some` containing equal values, or both are `None`.
106
- This method can be used for comparing `Option` instances in a value-sensitive manner.
107
-
108
- #### Type Parameters
109
-
110
- | Type Parameter |
111
- | ------ |
112
- | `T` |
113
-
114
- #### Parameters
115
-
116
- | Parameter | Type | Description |
117
- | ------ | ------ | ------ |
118
- | `other` | [`Option`](Option.md)\<`T`\> | The other `Option` to compare with. |
119
-
120
- #### Returns
121
-
122
- `boolean`
123
-
124
- `true` if `this` and `other` are both `Some` with equal values, or both are `None`, otherwise `false`.
125
-
126
- #### Overrides
127
-
128
- [`Option`](Option.md).[`eq`](Option.md#eq)
129
-
130
- #### Defined in
131
-
132
- [prelude.ts:36](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L36)
133
-
134
- ***
135
-
136
- ### expect()
137
-
138
- ```ts
139
- expect(msg): never
140
- ```
141
-
142
- Returns the contained `Some` value, with a provided error message if the value is a `None`.
143
-
144
- #### Parameters
145
-
146
- | Parameter | Type | Description |
147
- | ------ | ------ | ------ |
148
- | `msg` | `string` | The error message to provide if the value is a `None`. |
149
-
150
- #### Returns
151
-
152
- `never`
153
-
154
- #### Throws
155
-
156
- Throws an error with the provided message if the Option is a `None`.
157
-
158
- #### Inherited from
159
-
160
- [`Option`](Option.md).[`expect`](Option.md#expect)
161
-
162
- #### Defined in
163
-
164
- [core.ts:76](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L76)
165
-
166
- ***
167
-
168
- ### filter()
169
-
170
- ```ts
171
- filter(predicate): None
172
- ```
173
-
174
- Returns `None` if the Option is `None`, otherwise calls predicate with the wrapped value and returns:
175
- - `Some(t)` if predicate returns `true` (where `t` is the wrapped value), and
176
- - `None` if predicate returns `false`.
177
-
178
- #### Parameters
179
-
180
- | Parameter | Type | Description |
181
- | ------ | ------ | ------ |
182
- | `predicate` | (`value`) => `boolean` | A function that takes the contained value and returns a boolean. |
183
-
184
- #### Returns
185
-
186
- [`None`](None.md)
187
-
188
- #### Overrides
189
-
190
- [`Option`](Option.md).[`filter`](Option.md#filter)
191
-
192
- #### Defined in
193
-
194
- [prelude.ts:22](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L22)
195
-
196
- ***
197
-
198
- ### flatten()
199
-
200
- ```ts
201
- flatten(): None
202
- ```
203
-
204
- Converts from `Option<Option<T>>` to `Option<T>`.
205
-
206
- #### Returns
207
-
208
- [`None`](None.md)
209
-
210
- `None` if the Option is `None`, otherwise returns the contained `Option`.
211
-
212
- #### Overrides
213
-
214
- [`Option`](Option.md).[`flatten`](Option.md#flatten)
215
-
216
- #### Defined in
217
-
218
- [prelude.ts:23](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L23)
219
-
220
- ***
221
-
222
- ### inspect()
223
-
224
- ```ts
225
- inspect(fn): this
226
- ```
227
-
228
- Calls the provided function with the contained value if `this` is `Some`.
229
- This is primarily for side effects and does not transform the `Option`.
230
-
231
- #### Parameters
232
-
233
- | Parameter | Type | Description |
234
- | ------ | ------ | ------ |
235
- | `fn` | (`value`) => `void` | A function to call with the contained value. |
236
-
237
- #### Returns
238
-
239
- `this`
240
-
241
- `this`, unmodified, for chaining additional methods.
242
-
243
- #### Inherited from
244
-
245
- [`Option`](Option.md).[`inspect`](Option.md#inspect)
246
-
247
- #### Defined in
248
-
249
- [core.ts:263](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L263)
250
-
251
- ***
252
-
253
- ### isNone()
254
-
255
- ```ts
256
- isNone(): boolean
257
- ```
258
-
259
- Returns `true` if the Option is a `None` value.
260
-
261
- #### Returns
262
-
263
- `boolean`
264
-
265
- #### Inherited from
266
-
267
- [`Option`](Option.md).[`isNone`](Option.md#isnone)
268
-
269
- #### Defined in
270
-
271
- [core.ts:55](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L55)
272
-
273
- ***
274
-
275
- ### isSome()
276
-
277
- ```ts
278
- isSome(): boolean
279
- ```
280
-
281
- Returns `true` if the Option is a `Some` value.
282
-
283
- #### Returns
284
-
285
- `boolean`
286
-
287
- #### Inherited from
288
-
289
- [`Option`](Option.md).[`isSome`](Option.md#issome)
290
-
291
- #### Defined in
292
-
293
- [core.ts:50](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L50)
294
-
295
- ***
296
-
297
- ### isSomeAnd()
298
-
299
- ```ts
300
- isSomeAnd(predicate): boolean
301
- ```
302
-
303
- Returns `true` if the Option is a `Some` value and the predicate returns `true` for the contained value.
304
-
305
- #### Parameters
306
-
307
- | Parameter | Type | Description |
308
- | ------ | ------ | ------ |
309
- | `predicate` | (`value`) => `boolean` | A function that takes the contained value and returns a boolean. |
310
-
311
- #### Returns
312
-
313
- `boolean`
314
-
315
- #### Inherited from
316
-
317
- [`Option`](Option.md).[`isSomeAnd`](Option.md#issomeand)
318
-
319
- #### Defined in
320
-
321
- [core.ts:61](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L61)
322
-
323
- ***
324
-
325
- ### map()
326
-
327
- ```ts
328
- map<U>(fn): None
329
- ```
330
-
331
- Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
332
-
333
- #### Type Parameters
334
-
335
- | Type Parameter | Description |
336
- | ------ | ------ |
337
- | `U` | The type of the value returned by the map function. |
338
-
339
- #### Parameters
340
-
341
- | Parameter | Type | Description |
342
- | ------ | ------ | ------ |
343
- | `fn` | (`value`) => `U` | A function that takes the contained value and returns a new value. |
344
-
345
- #### Returns
346
-
347
- [`None`](None.md)
348
-
349
- #### Overrides
350
-
351
- [`Option`](Option.md).[`map`](Option.md#map)
352
-
353
- #### Defined in
354
-
355
- [prelude.ts:24](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L24)
356
-
357
- ***
358
-
359
- ### mapOr()
360
-
361
- ```ts
362
- mapOr<U>(defaultValue, fn): U
363
- ```
364
-
365
- Maps an `Option<T>` to `U` by applying a function to the contained value (if any), or returns the provided default (if not).
366
-
367
- #### Type Parameters
368
-
369
- | Type Parameter | Description |
370
- | ------ | ------ |
371
- | `U` | The type of the value returned by the map function or the default value. |
372
-
373
- #### Parameters
374
-
375
- | Parameter | Type | Description |
376
- | ------ | ------ | ------ |
377
- | `defaultValue` | `U` | The value to return if the Option is `None`. |
378
- | `fn` | (`value`) => `U` | A function that takes the contained value and returns a new value. |
379
-
380
- #### Returns
381
-
382
- `U`
383
-
384
- #### Inherited from
385
-
386
- [`Option`](Option.md).[`mapOr`](Option.md#mapor)
387
-
388
- #### Defined in
389
-
390
- [core.ts:159](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L159)
391
-
392
- ***
393
-
394
- ### mapOrElse()
395
-
396
- ```ts
397
- mapOrElse<U>(defaultFn, fn): U
398
- ```
399
-
400
- Maps an `Option<T>` to `U` by applying a function to a contained value (if any), or computes a default (if not).
401
-
402
- #### Type Parameters
403
-
404
- | Type Parameter | Description |
405
- | ------ | ------ |
406
- | `U` | The type of the value returned by the map function or the default function. |
407
-
408
- #### Parameters
409
-
410
- | Parameter | Type | Description |
411
- | ------ | ------ | ------ |
412
- | `defaultFn` | () => `U` | A function that returns the default value. |
413
- | `fn` | (`value`) => `U` | A function that takes the contained value and returns a new value. |
414
-
415
- #### Returns
416
-
417
- `U`
418
-
419
- #### Inherited from
420
-
421
- [`Option`](Option.md).[`mapOrElse`](Option.md#maporelse)
422
-
423
- #### Defined in
424
-
425
- [core.ts:167](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L167)
426
-
427
- ***
428
-
429
- ### okOr()
430
-
431
- ```ts
432
- okOr<E>(error): Result<never, E>
433
- ```
434
-
435
- Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`.
436
-
437
- #### Type Parameters
438
-
439
- | Type Parameter | Description |
440
- | ------ | ------ |
441
- | `E` | The type of the error value in the `Err` variant of the resulting `Result`. |
442
-
443
- #### Parameters
444
-
445
- | Parameter | Type | Description |
446
- | ------ | ------ | ------ |
447
- | `error` | `E` | The error value to use if the Option is a `None`. |
448
-
449
- #### Returns
450
-
451
- [`Result`](Result.md)\<`never`, `E`\>
452
-
453
- #### Inherited from
454
-
455
- [`Option`](Option.md).[`okOr`](Option.md#okor)
456
-
457
- #### Defined in
458
-
459
- [core.ts:109](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L109)
460
-
461
- ***
462
-
463
- ### okOrElse()
464
-
465
- ```ts
466
- okOrElse<E>(err): Result<never, E>
467
- ```
468
-
469
- Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`.
470
-
471
- #### Type Parameters
472
-
473
- | Type Parameter | Description |
474
- | ------ | ------ |
475
- | `E` | The type of the error value in the `Err` variant of the resulting `Result`. |
476
-
477
- #### Parameters
478
-
479
- | Parameter | Type | Description |
480
- | ------ | ------ | ------ |
481
- | `err` | () => `E` | A function that returns the error value. |
482
-
483
- #### Returns
484
-
485
- [`Result`](Result.md)\<`never`, `E`\>
486
-
487
- #### Inherited from
488
-
489
- [`Option`](Option.md).[`okOrElse`](Option.md#okorelse)
490
-
491
- #### Defined in
492
-
493
- [core.ts:116](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L116)
494
-
495
- ***
496
-
497
- ### or()
498
-
499
- ```ts
500
- or<T>(other): Option<T>
501
- ```
502
-
503
- Returns the Option if it contains a value, otherwise returns `other`.
504
- This can be used for providing a fallback `Option`.
505
-
506
- #### Type Parameters
507
-
508
- | Type Parameter |
509
- | ------ |
510
- | `T` |
511
-
512
- #### Parameters
513
-
514
- | Parameter | Type | Description |
515
- | ------ | ------ | ------ |
516
- | `other` | [`Option`](Option.md)\<`T`\> | The fallback `Option` to use if `this` is `None`. |
517
-
518
- #### Returns
519
-
520
- [`Option`](Option.md)\<`T`\>
521
-
522
- `this` if it is `Some`, otherwise `other`.
523
-
524
- #### Overrides
525
-
526
- [`Option`](Option.md).[`or`](Option.md#or)
527
-
528
- #### Defined in
529
-
530
- [prelude.ts:32](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L32)
531
-
532
- ***
533
-
534
- ### orElse()
535
-
536
- ```ts
537
- orElse<T>(fn): Option<T>
538
- ```
539
-
540
- Returns the Option if it contains a value, otherwise calls `fn` and returns the result.
541
- This method can be used for lazy fallbacks, as `fn` is only evaluated if `this` is `None`.
542
-
543
- #### Type Parameters
544
-
545
- | Type Parameter |
546
- | ------ |
547
- | `T` |
548
-
549
- #### Parameters
550
-
551
- | Parameter | Type | Description |
552
- | ------ | ------ | ------ |
553
- | `fn` | () => [`Option`](Option.md)\<`T`\> | A function that produces an `Option`. |
554
-
555
- #### Returns
556
-
557
- [`Option`](Option.md)\<`T`\>
558
-
559
- `this` if it is `Some`, otherwise the result of `fn`.
560
-
561
- #### Overrides
562
-
563
- [`Option`](Option.md).[`orElse`](Option.md#orelse)
564
-
565
- #### Defined in
566
-
567
- [prelude.ts:33](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L33)
568
-
569
- ***
570
-
571
- ### toString()
572
-
573
- ```ts
574
- toString(): string
575
- ```
576
-
577
- Custom `toString` implementation that uses the `Option`'s contained value.
578
-
579
- #### Returns
580
-
581
- `string`
582
-
583
- #### Inherited from
584
-
585
- [`Option`](Option.md).[`toString`](Option.md#tostring)
586
-
587
- #### Defined in
588
-
589
- [core.ts:280](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L280)
590
-
591
- ***
592
-
593
- ### transpose()
594
-
595
- ```ts
596
- transpose(): Result<None, never>
597
- ```
598
-
599
- Transposes an `Option` of a `Result` into a `Result` of an `Option`.
600
-
601
- #### Returns
602
-
603
- [`Result`](Result.md)\<[`None`](None.md), `never`\>
604
-
605
- `Ok` containing `Some` if the Option is a `Some` containing `Ok`,
606
- `Err` containing the error if the Option is a `Some` containing `Err`,
607
- `Ok` containing `None` if the Option is `None`.
608
-
609
- #### Overrides
610
-
611
- [`Option`](Option.md).[`transpose`](Option.md#transpose)
612
-
613
- #### Defined in
614
-
615
- [prelude.ts:20](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L20)
616
-
617
- ***
618
-
619
- ### unwrap()
620
-
621
- ```ts
622
- unwrap(): never
623
- ```
624
-
625
- Returns the contained `Some` value.
626
-
627
- #### Returns
628
-
629
- `never`
630
-
631
- #### Throws
632
-
633
- Throws an error if the value is a `None`.
634
-
635
- #### Inherited from
636
-
637
- [`Option`](Option.md).[`unwrap`](Option.md#unwrap)
638
-
639
- #### Defined in
640
-
641
- [core.ts:82](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/core.ts#L82)
642
-
643
- ***
644
-
645
- ### unwrapOr()
646
-
647
- ```ts
648
- unwrapOr<T>(defaultValue): T
649
- ```
650
-
651
- Returns the contained `Some` value or a provided default.
652
-
653
- #### Type Parameters
654
-
655
- | Type Parameter |
656
- | ------ |
657
- | `T` |
658
-
659
- #### Parameters
660
-
661
- | Parameter | Type | Description |
662
- | ------ | ------ | ------ |
663
- | `defaultValue` | `T` | The value to return if the Option is a `None`. |
664
-
665
- #### Returns
666
-
667
- `T`
668
-
669
- #### Overrides
670
-
671
- [`Option`](Option.md).[`unwrapOr`](Option.md#unwrapor)
672
-
673
- #### Defined in
674
-
675
- [prelude.ts:17](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L17)
676
-
677
- ***
678
-
679
- ### unwrapOrElse()
680
-
681
- ```ts
682
- unwrapOrElse<T>(fn): T
683
- ```
684
-
685
- Returns the contained `Some` value or computes it from a closure.
686
-
687
- #### Type Parameters
688
-
689
- | Type Parameter |
690
- | ------ |
691
- | `T` |
692
-
693
- #### Parameters
694
-
695
- | Parameter | Type | Description |
696
- | ------ | ------ | ------ |
697
- | `fn` | () => `T` | A function that returns the default value. |
698
-
699
- #### Returns
700
-
701
- `T`
702
-
703
- #### Overrides
704
-
705
- [`Option`](Option.md).[`unwrapOrElse`](Option.md#unwraporelse)
706
-
707
- #### Defined in
708
-
709
- [prelude.ts:18](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L18)
710
-
711
- ***
712
-
713
- ### unzip()
714
-
715
- ```ts
716
- unzip(): [None, None]
717
- ```
718
-
719
- Converts from `Option<[T, U]>` to `[Option<T>, Option<U>]`.
720
- If `this` is `Some([a, b])`, returns `[Some(a), Some(b)]`.
721
- If `this` is `None`, returns `[None, None]`.
722
-
723
- #### Returns
724
-
725
- [[`None`](None.md), [`None`](None.md)]
726
-
727
- A tuple of `Options`, one for each element in the original `Option` of a tuple.
728
-
729
- #### Overrides
730
-
731
- [`Option`](Option.md).[`unzip`](Option.md#unzip)
732
-
733
- #### Defined in
734
-
735
- [prelude.ts:28](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L28)
736
-
737
- ***
738
-
739
- ### xor()
740
-
741
- ```ts
742
- xor<T>(other): Option<T>
743
- ```
744
-
745
- Returns `Some` if exactly one of `this`, `other` is `Some`, otherwise returns `None`.
746
- This can be thought of as an exclusive or operation on `Option` values.
747
-
748
- #### Type Parameters
749
-
750
- | Type Parameter |
751
- | ------ |
752
- | `T` |
753
-
754
- #### Parameters
755
-
756
- | Parameter | Type | Description |
757
- | ------ | ------ | ------ |
758
- | `other` | [`Option`](Option.md)\<`T`\> | The other `Option` to compare with. |
759
-
760
- #### Returns
761
-
762
- [`Option`](Option.md)\<`T`\>
763
-
764
- `Some` if exactly one of `this` and `other` is `Some`, otherwise `None`.
765
-
766
- #### Overrides
767
-
768
- [`Option`](Option.md).[`xor`](Option.md#xor)
769
-
770
- #### Defined in
771
-
772
- [prelude.ts:34](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L34)
773
-
774
- ***
775
-
776
- ### zip()
777
-
778
- ```ts
779
- zip<U>(other): None
780
- ```
781
-
782
- Combines `this` with another `Option` by zipping their contained values.
783
- If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some([s, o])`.
784
- If either `this` or `other` is `None`, returns `None`.
785
-
786
- #### Type Parameters
787
-
788
- | Type Parameter | Description |
789
- | ------ | ------ |
790
- | `U` | The type of the value in the other `Option`. |
791
-
792
- #### Parameters
793
-
794
- | Parameter | Type | Description |
795
- | ------ | ------ | ------ |
796
- | `other` | [`Option`](Option.md)\<`U`\> | The other `Option` to zip with. |
797
-
798
- #### Returns
799
-
800
- [`None`](None.md)
801
-
802
- An `Option` containing a tuple of the values if both are `Some`, otherwise `None`.
803
-
804
- #### Overrides
805
-
806
- [`Option`](Option.md).[`zip`](Option.md#zip)
807
-
808
- #### Defined in
809
-
810
- [prelude.ts:26](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L26)
811
-
812
- ***
813
-
814
- ### zipWith()
815
-
816
- ```ts
817
- zipWith<U, R>(other, fn): None
818
- ```
819
-
820
- Zips `this` with another `Option` using a provided function to combine their contained values.
821
- If `this` is `Some(s)` and `other` is `Some(o)`, returns `Some(fn(s, o))`.
822
- If either `this` or `other` is `None`, returns `None`.
823
-
824
- #### Type Parameters
825
-
826
- | Type Parameter | Description |
827
- | ------ | ------ |
828
- | `U` | The type of the value in the other `Option`. |
829
- | `R` | The return type of the combining function. |
830
-
831
- #### Parameters
832
-
833
- | Parameter | Type | Description |
834
- | ------ | ------ | ------ |
835
- | `other` | [`Option`](Option.md)\<`U`\> | The other `Option` to zip with. |
836
- | `fn` | (`value`, `otherValue`) => `R` | The function to combine the values from both `Options`. |
837
-
838
- #### Returns
839
-
840
- [`None`](None.md)
841
-
842
- An `Option` containing the result of `fn` if both `Options` are `Some`, otherwise `None`.
843
-
844
- #### Overrides
845
-
846
- [`Option`](Option.md).[`zipWith`](Option.md#zipwith)
847
-
848
- #### Defined in
849
-
850
- [prelude.ts:27](https://github.com/JiangJie/happy-rusty/blob/7d7f4ab2132e507f77594d030495f95b5688b84a/src/enum/prelude.ts#L27)