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