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