happy-rusty 1.2.0 → 1.3.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.
- package/dist/main.cjs +24 -14
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +21 -14
- package/dist/main.mjs.map +1 -1
- package/dist/types.d.ts +79 -53
- package/docs/README.md +4 -1
- package/docs/functions/Err.md +1 -1
- package/docs/functions/Ok.md +1 -1
- package/docs/functions/Some.md +1 -1
- package/docs/functions/isOption.md +1 -1
- package/docs/functions/isResult.md +1 -1
- package/docs/functions/{promiseToResult.md → promiseToAsyncResult.md} +5 -5
- package/docs/interfaces/None.md +28 -28
- package/docs/interfaces/Option.md +27 -27
- package/docs/interfaces/Result.md +29 -29
- package/docs/type-aliases/AsyncIOResult.md +2 -2
- package/docs/type-aliases/AsyncOption.md +1 -1
- package/docs/type-aliases/AsyncResult.md +1 -1
- package/docs/type-aliases/IOResult.md +1 -1
- package/docs/variables/None.md +1 -1
- package/docs/variables/RESULT_FALSE.md +18 -0
- package/docs/variables/RESULT_TRUE.md +18 -0
- package/docs/variables/RESULT_ZERO.md +18 -0
- package/package.json +1 -1
- package/src/enum/constants.ts +25 -0
- package/src/enum/core.ts +569 -0
- package/src/enum/defines.ts +38 -0
- package/src/enum/extensions.ts +31 -0
- package/src/enum/helpers.ts +27 -0
- package/src/enum/mod.ts +6 -0
- package/src/enum/prelude.ts +8 -673
- package/src/enum/symbols.ts +9 -0
- package/src/mod.ts +1 -15
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol for Option kind: `Some` or `None`.
|
|
3
|
+
*/
|
|
4
|
+
declare const OptionKindSymbol: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Symbol for Result kind: `Ok` or `Err`.
|
|
7
|
+
*/
|
|
8
|
+
declare const ResultKindSymbol: unique symbol;
|
|
9
|
+
|
|
1
10
|
/**
|
|
2
11
|
* @fileoverview
|
|
3
12
|
* A Rust-inspired [Option](https://doc.rust-lang.org/core/option/index.html) enum type, used as an alternative to the use of null and undefined.
|
|
@@ -5,14 +14,7 @@
|
|
|
5
14
|
* And [Result](https://doc.rust-lang.org/core/result/index.html) enum type, used for better error handling.
|
|
6
15
|
*
|
|
7
16
|
*/
|
|
8
|
-
|
|
9
|
-
* Symbol for Option kind: `Some` or `None`.
|
|
10
|
-
*/
|
|
11
|
-
declare const optionKindSymbol: unique symbol;
|
|
12
|
-
/**
|
|
13
|
-
* Symbol for Result kind: `Ok` or `Err`.
|
|
14
|
-
*/
|
|
15
|
-
declare const resultKindSymbol: unique symbol;
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* Type `Option` represents an optional value: every `Option` is either `Some` and contains a value, or `None`, and does not.
|
|
18
20
|
* This interface includes methods that act on the `Option` type, similar to Rust's `Option` enum.
|
|
@@ -36,7 +38,7 @@ interface Option<T> {
|
|
|
36
38
|
*
|
|
37
39
|
* @private
|
|
38
40
|
*/
|
|
39
|
-
readonly [
|
|
41
|
+
readonly [OptionKindSymbol]: 'Some' | 'None';
|
|
40
42
|
/**
|
|
41
43
|
* The `isSome` and `isNone` methods return `true` if the `Option` is `Some` or `None`, respectively.
|
|
42
44
|
*/
|
|
@@ -252,7 +254,7 @@ interface Result<T, E> {
|
|
|
252
254
|
*
|
|
253
255
|
* @private
|
|
254
256
|
*/
|
|
255
|
-
readonly [
|
|
257
|
+
readonly [ResultKindSymbol]: 'Ok' | 'Err';
|
|
256
258
|
/**
|
|
257
259
|
* The `isOk` and `isErr` methods return `true` if the `Result` is `Ok` or `Err`, respectively.
|
|
258
260
|
*/
|
|
@@ -453,9 +455,30 @@ interface Result<T, E> {
|
|
|
453
455
|
*/
|
|
454
456
|
toString(): string;
|
|
455
457
|
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Exports some Result constants.
|
|
461
|
+
*/
|
|
456
462
|
/**
|
|
457
|
-
*
|
|
463
|
+
* Result constant for `true`.
|
|
464
|
+
* Can be used anywhere due to immutability.
|
|
458
465
|
*/
|
|
466
|
+
declare const RESULT_TRUE: Result<boolean, any>;
|
|
467
|
+
/**
|
|
468
|
+
* Result constant for `false`.
|
|
469
|
+
* Can be used anywhere due to immutability.
|
|
470
|
+
*/
|
|
471
|
+
declare const RESULT_FALSE: Result<boolean, any>;
|
|
472
|
+
/**
|
|
473
|
+
* Result constant for `0`.
|
|
474
|
+
* Can be used anywhere due to immutability.
|
|
475
|
+
*/
|
|
476
|
+
declare const RESULT_ZERO: Result<number, any>;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Exports some commonly used types.
|
|
480
|
+
*/
|
|
481
|
+
|
|
459
482
|
/**
|
|
460
483
|
* Represents an asynchronous operation that yields an `Option<T>`.
|
|
461
484
|
* This is a promise that resolves to either `Some(T)` if the value is present, or `None` if the value is absent.
|
|
@@ -484,7 +507,49 @@ type IOResult<T> = Result<T, Error>;
|
|
|
484
507
|
*
|
|
485
508
|
* @typeParam T - The type of the value that is produced by a successful I/O operation.
|
|
486
509
|
*/
|
|
487
|
-
type AsyncIOResult<T> =
|
|
510
|
+
type AsyncIOResult<T> = AsyncResult<T, Error>;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`.
|
|
514
|
+
* This allows for promise-based asynchronous operations to be handled in a way that is more in line with the Result pattern.
|
|
515
|
+
*
|
|
516
|
+
* @typeParam T - The type of the value that the promise resolves to.
|
|
517
|
+
* @typeParam E - The type of the error that the promise may reject with, defaults to `Error`.
|
|
518
|
+
* @param p - The promise to convert into a `Result` type.
|
|
519
|
+
* @returns A promise that resolves to a `Result<T, E>`. If the input promise `p` resolves, the resulting promise will resolve with `Ok<T>`. If the input promise `p` rejects, the resulting promise will resolve with `Err<E>`.
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* async function example() {
|
|
524
|
+
* const result = await promiseToAsyncResult(fetchData());
|
|
525
|
+
* if (result.isOk()) {
|
|
526
|
+
* console.log('Data:', result.unwrap());
|
|
527
|
+
* } else {
|
|
528
|
+
* console.error('Error:', result.unwrapErr());
|
|
529
|
+
* }
|
|
530
|
+
* }
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
declare function promiseToAsyncResult<T, E = Error>(p: Promise<T>): Promise<Result<T, E>>;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Checks if a value is an `Option`.
|
|
537
|
+
*
|
|
538
|
+
* @typeParam T - The expected type of the value contained within the `Option`.
|
|
539
|
+
* @param o - The value to be checked as an `Option`.
|
|
540
|
+
* @returns `true` if the value is an `Option`, otherwise `false`.
|
|
541
|
+
*/
|
|
542
|
+
declare function isOption<T>(o: unknown): o is Option<T>;
|
|
543
|
+
/**
|
|
544
|
+
* Checks if a value is a `Result`.
|
|
545
|
+
*
|
|
546
|
+
* @typeParam T - The expected type of the success value contained within the `Result`.
|
|
547
|
+
* @typeParam E - The expected type of the error value contained within the `Result`.
|
|
548
|
+
* @param r - The value to be checked as a `Result`.
|
|
549
|
+
* @returns `true` if the value is a `Result`, otherwise `false`.
|
|
550
|
+
*/
|
|
551
|
+
declare function isResult<T, E>(r: unknown): r is Result<T, E>;
|
|
552
|
+
|
|
488
553
|
/**
|
|
489
554
|
* Creates an `Option<T>` representing the presence of a value.
|
|
490
555
|
* This function is typically used to construct an `Option` that contains a value, indicating that the operation yielding the value was successful.
|
|
@@ -510,7 +575,7 @@ interface None extends Option<never> {
|
|
|
510
575
|
/**
|
|
511
576
|
* When using `None` alone, the following overrides can make type inference more accurate.
|
|
512
577
|
*/
|
|
513
|
-
readonly [
|
|
578
|
+
readonly [OptionKindSymbol]: 'None';
|
|
514
579
|
unwrapOr<T>(defaultValue: T): T;
|
|
515
580
|
unwrapOrElse<T>(fn: () => T): T;
|
|
516
581
|
transpose(): Result<None, never>;
|
|
@@ -568,45 +633,6 @@ declare function Ok<T, E>(value: T): Result<T, E>;
|
|
|
568
633
|
* ```
|
|
569
634
|
*/
|
|
570
635
|
declare function Err<T, E>(error: E): Result<T, E>;
|
|
571
|
-
/**
|
|
572
|
-
* Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`.
|
|
573
|
-
* This allows for promise-based asynchronous operations to be handled in a way that is more in line with the Result pattern.
|
|
574
|
-
*
|
|
575
|
-
* @typeParam T - The type of the value that the promise resolves to.
|
|
576
|
-
* @typeParam E - The type of the error that the promise may reject with, defaults to `Error`.
|
|
577
|
-
* @param p - The promise to convert into a `Result` type.
|
|
578
|
-
* @returns A promise that resolves to a `Result<T, E>`. If the input promise `p` resolves, the resulting promise will resolve with `Ok<T>`. If the input promise `p` rejects, the resulting promise will resolve with `Err<E>`.
|
|
579
|
-
*
|
|
580
|
-
* @example
|
|
581
|
-
* ```ts
|
|
582
|
-
* async function example() {
|
|
583
|
-
* const result = await promiseToResult(fetchData());
|
|
584
|
-
* if (result.isOk()) {
|
|
585
|
-
* console.log('Data:', result.unwrap());
|
|
586
|
-
* } else {
|
|
587
|
-
* console.error('Error:', result.unwrapErr());
|
|
588
|
-
* }
|
|
589
|
-
* }
|
|
590
|
-
* ```
|
|
591
|
-
*/
|
|
592
|
-
declare function promiseToResult<T, E = Error>(p: Promise<T>): Promise<Result<T, E>>;
|
|
593
|
-
/**
|
|
594
|
-
* Checks if a value is an `Option`.
|
|
595
|
-
*
|
|
596
|
-
* @typeParam T - The expected type of the value contained within the `Option`.
|
|
597
|
-
* @param o - The value to be checked as an `Option`.
|
|
598
|
-
* @returns `true` if the value is an `Option`, otherwise `false`.
|
|
599
|
-
*/
|
|
600
|
-
declare function isOption<T>(o: unknown): o is Option<T>;
|
|
601
|
-
/**
|
|
602
|
-
* Checks if a value is a `Result`.
|
|
603
|
-
*
|
|
604
|
-
* @typeParam T - The expected type of the success value contained within the `Result`.
|
|
605
|
-
* @typeParam E - The expected type of the error value contained within the `Result`.
|
|
606
|
-
* @param r - The value to be checked as a `Result`.
|
|
607
|
-
* @returns `true` if the value is a `Result`, otherwise `false`.
|
|
608
|
-
*/
|
|
609
|
-
declare function isResult<T, E>(r: unknown): r is Result<T, E>;
|
|
610
636
|
|
|
611
|
-
export { type AsyncIOResult, type AsyncOption, type AsyncResult, Err, type IOResult, None, Ok, type Option, type Result, Some, isOption, isResult,
|
|
637
|
+
export { type AsyncIOResult, type AsyncOption, type AsyncResult, Err, type IOResult, None, Ok, type Option, RESULT_FALSE, RESULT_TRUE, RESULT_ZERO, type Result, Some, isOption, isResult, promiseToAsyncResult };
|
|
612
638
|
//# sourceMappingURL=types.d.ts.map
|
package/docs/README.md
CHANGED
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
| Variable | Description |
|
|
27
27
|
| ------ | ------ |
|
|
28
28
|
| [None](variables/None.md) | A constant representing the `None` case of an `Option`, indicating the absence of a value. This constant is frozen to ensure it is immutable and cannot be altered, preserving the integrity of `None` throughout the application. |
|
|
29
|
+
| [RESULT\_FALSE](variables/RESULT_FALSE.md) | Result constant for `false`. Can be used anywhere due to immutability. |
|
|
30
|
+
| [RESULT\_TRUE](variables/RESULT_TRUE.md) | Result constant for `true`. Can be used anywhere due to immutability. |
|
|
31
|
+
| [RESULT\_ZERO](variables/RESULT_ZERO.md) | Result constant for `0`. Can be used anywhere due to immutability. |
|
|
29
32
|
|
|
30
33
|
## Functions
|
|
31
34
|
|
|
@@ -36,4 +39,4 @@
|
|
|
36
39
|
| [Some](functions/Some.md) | Creates an `Option<T>` representing the presence of a value. This function is typically used to construct an `Option` that contains a value, indicating that the operation yielding the value was successful. |
|
|
37
40
|
| [isOption](functions/isOption.md) | Checks if a value is an `Option`. |
|
|
38
41
|
| [isResult](functions/isResult.md) | Checks if a value is a `Result`. |
|
|
39
|
-
| [
|
|
42
|
+
| [promiseToAsyncResult](functions/promiseToAsyncResult.md) | Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`. This allows for promise-based asynchronous operations to be handled in a way that is more in line with the Result pattern. |
|
package/docs/functions/Err.md
CHANGED
|
@@ -43,4 +43,4 @@ if (badResult.isErr()) {
|
|
|
43
43
|
|
|
44
44
|
## Defined in
|
|
45
45
|
|
|
46
|
-
[prelude.ts:
|
|
46
|
+
[prelude.ts:413](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L413)
|
package/docs/functions/Ok.md
CHANGED
|
@@ -43,4 +43,4 @@ if (goodResult.isOk()) {
|
|
|
43
43
|
|
|
44
44
|
## Defined in
|
|
45
45
|
|
|
46
|
-
[prelude.ts:
|
|
46
|
+
[prelude.ts:286](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L286)
|
package/docs/functions/Some.md
CHANGED
|
@@ -42,4 +42,4 @@ if (maybeValue.isSome()) {
|
|
|
42
42
|
|
|
43
43
|
## Defined in
|
|
44
44
|
|
|
45
|
-
[prelude.ts:
|
|
45
|
+
[prelude.ts:55](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L55)
|
|
@@ -32,4 +32,4 @@ Checks if a value is an `Option`.
|
|
|
32
32
|
|
|
33
33
|
## Defined in
|
|
34
34
|
|
|
35
|
-
[
|
|
35
|
+
[helpers.ts:11](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/helpers.ts#L11)
|
|
@@ -33,4 +33,4 @@ Checks if a value is a `Result`.
|
|
|
33
33
|
|
|
34
34
|
## Defined in
|
|
35
35
|
|
|
36
|
-
[
|
|
36
|
+
[helpers.ts:24](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/helpers.ts#L24)
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
5
|
-
[happy-rusty](../README.md) /
|
|
5
|
+
[happy-rusty](../README.md) / promiseToAsyncResult
|
|
6
6
|
|
|
7
|
-
# Function:
|
|
7
|
+
# Function: promiseToAsyncResult()
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
function
|
|
10
|
+
function promiseToAsyncResult<T, E>(p): Promise<Result<T, E>>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Converts a Promise to a Result type, capturing the resolved value in an `Ok`, or the error in an `Err`.
|
|
@@ -36,7 +36,7 @@ A promise that resolves to a `Result<T, E>`. If the input promise `p` resolves,
|
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
38
|
async function example() {
|
|
39
|
-
const result = await
|
|
39
|
+
const result = await promiseToAsyncResult(fetchData());
|
|
40
40
|
if (result.isOk()) {
|
|
41
41
|
console.log('Data:', result.unwrap());
|
|
42
42
|
} else {
|
|
@@ -47,4 +47,4 @@ async function example() {
|
|
|
47
47
|
|
|
48
48
|
## Defined in
|
|
49
49
|
|
|
50
|
-
[
|
|
50
|
+
[extensions.ts:25](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/extensions.ts#L25)
|
package/docs/interfaces/None.md
CHANGED
|
@@ -17,8 +17,8 @@ The type parameter is set to `never` because `None` does not hold a value.
|
|
|
17
17
|
|
|
18
18
|
| Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
|
|
19
19
|
| ------ | ------ | ------ | ------ | ------ | ------ | ------ |
|
|
20
|
-
| `[
|
|
21
|
-
| `[toStringTag]` | `public` | `"Option"` | [object Option]. | - | [`Option`](Option.md).`[toStringTag]` | [
|
|
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/ba112bb228eba4376da813b0604a1f67c4b2f569/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/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L30) |
|
|
22
22
|
|
|
23
23
|
## Methods
|
|
24
24
|
|
|
@@ -55,7 +55,7 @@ This is sometimes called "and then" because it is similar to a logical AND opera
|
|
|
55
55
|
|
|
56
56
|
#### Defined in
|
|
57
57
|
|
|
58
|
-
[prelude.ts:
|
|
58
|
+
[prelude.ts:30](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L30)
|
|
59
59
|
|
|
60
60
|
***
|
|
61
61
|
|
|
@@ -92,7 +92,7 @@ The result of `fn` if `this` is `Some`, otherwise `None`.
|
|
|
92
92
|
|
|
93
93
|
#### Defined in
|
|
94
94
|
|
|
95
|
-
[prelude.ts:
|
|
95
|
+
[prelude.ts:31](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L31)
|
|
96
96
|
|
|
97
97
|
***
|
|
98
98
|
|
|
@@ -129,7 +129,7 @@ This method can be used for comparing `Option` instances in a value-sensitive ma
|
|
|
129
129
|
|
|
130
130
|
#### Defined in
|
|
131
131
|
|
|
132
|
-
[prelude.ts:
|
|
132
|
+
[prelude.ts:36](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L36)
|
|
133
133
|
|
|
134
134
|
***
|
|
135
135
|
|
|
@@ -161,7 +161,7 @@ Throws an error with the provided message if the Option is a `None`.
|
|
|
161
161
|
|
|
162
162
|
#### Defined in
|
|
163
163
|
|
|
164
|
-
[
|
|
164
|
+
[core.ts:76](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L76)
|
|
165
165
|
|
|
166
166
|
***
|
|
167
167
|
|
|
@@ -191,7 +191,7 @@ Returns `None` if the Option is `None`, otherwise calls predicate with the wrapp
|
|
|
191
191
|
|
|
192
192
|
#### Defined in
|
|
193
193
|
|
|
194
|
-
[prelude.ts:
|
|
194
|
+
[prelude.ts:22](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L22)
|
|
195
195
|
|
|
196
196
|
***
|
|
197
197
|
|
|
@@ -215,7 +215,7 @@ Converts from `Option<Option<T>>` to `Option<T>`.
|
|
|
215
215
|
|
|
216
216
|
#### Defined in
|
|
217
217
|
|
|
218
|
-
[prelude.ts:
|
|
218
|
+
[prelude.ts:23](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L23)
|
|
219
219
|
|
|
220
220
|
***
|
|
221
221
|
|
|
@@ -246,7 +246,7 @@ This is primarily for side effects and does not transform the `Option`.
|
|
|
246
246
|
|
|
247
247
|
#### Defined in
|
|
248
248
|
|
|
249
|
-
[
|
|
249
|
+
[core.ts:263](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L263)
|
|
250
250
|
|
|
251
251
|
***
|
|
252
252
|
|
|
@@ -268,7 +268,7 @@ Returns `true` if the Option is a `None` value.
|
|
|
268
268
|
|
|
269
269
|
#### Defined in
|
|
270
270
|
|
|
271
|
-
[
|
|
271
|
+
[core.ts:55](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L55)
|
|
272
272
|
|
|
273
273
|
***
|
|
274
274
|
|
|
@@ -290,7 +290,7 @@ Returns `true` if the Option is a `Some` value.
|
|
|
290
290
|
|
|
291
291
|
#### Defined in
|
|
292
292
|
|
|
293
|
-
[
|
|
293
|
+
[core.ts:50](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L50)
|
|
294
294
|
|
|
295
295
|
***
|
|
296
296
|
|
|
@@ -318,7 +318,7 @@ Returns `true` if the Option is a `Some` value and the predicate returns `true`
|
|
|
318
318
|
|
|
319
319
|
#### Defined in
|
|
320
320
|
|
|
321
|
-
[
|
|
321
|
+
[core.ts:61](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L61)
|
|
322
322
|
|
|
323
323
|
***
|
|
324
324
|
|
|
@@ -352,7 +352,7 @@ Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
|
|
|
352
352
|
|
|
353
353
|
#### Defined in
|
|
354
354
|
|
|
355
|
-
[prelude.ts:
|
|
355
|
+
[prelude.ts:24](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L24)
|
|
356
356
|
|
|
357
357
|
***
|
|
358
358
|
|
|
@@ -387,7 +387,7 @@ Maps an `Option<T>` to `U` by applying a function to the contained value (if any
|
|
|
387
387
|
|
|
388
388
|
#### Defined in
|
|
389
389
|
|
|
390
|
-
[
|
|
390
|
+
[core.ts:159](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L159)
|
|
391
391
|
|
|
392
392
|
***
|
|
393
393
|
|
|
@@ -422,7 +422,7 @@ Maps an `Option<T>` to `U` by applying a function to a contained value (if any),
|
|
|
422
422
|
|
|
423
423
|
#### Defined in
|
|
424
424
|
|
|
425
|
-
[
|
|
425
|
+
[core.ts:167](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L167)
|
|
426
426
|
|
|
427
427
|
***
|
|
428
428
|
|
|
@@ -456,7 +456,7 @@ Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` a
|
|
|
456
456
|
|
|
457
457
|
#### Defined in
|
|
458
458
|
|
|
459
|
-
[
|
|
459
|
+
[core.ts:109](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L109)
|
|
460
460
|
|
|
461
461
|
***
|
|
462
462
|
|
|
@@ -490,7 +490,7 @@ Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` a
|
|
|
490
490
|
|
|
491
491
|
#### Defined in
|
|
492
492
|
|
|
493
|
-
[
|
|
493
|
+
[core.ts:116](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L116)
|
|
494
494
|
|
|
495
495
|
***
|
|
496
496
|
|
|
@@ -527,7 +527,7 @@ This can be used for providing a fallback `Option`.
|
|
|
527
527
|
|
|
528
528
|
#### Defined in
|
|
529
529
|
|
|
530
|
-
[prelude.ts:
|
|
530
|
+
[prelude.ts:32](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L32)
|
|
531
531
|
|
|
532
532
|
***
|
|
533
533
|
|
|
@@ -564,7 +564,7 @@ This method can be used for lazy fallbacks, as `fn` is only evaluated if `this`
|
|
|
564
564
|
|
|
565
565
|
#### Defined in
|
|
566
566
|
|
|
567
|
-
[prelude.ts:
|
|
567
|
+
[prelude.ts:33](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L33)
|
|
568
568
|
|
|
569
569
|
***
|
|
570
570
|
|
|
@@ -586,7 +586,7 @@ Custom `toString` implementation that uses the `Option`'s contained value.
|
|
|
586
586
|
|
|
587
587
|
#### Defined in
|
|
588
588
|
|
|
589
|
-
[
|
|
589
|
+
[core.ts:280](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L280)
|
|
590
590
|
|
|
591
591
|
***
|
|
592
592
|
|
|
@@ -612,7 +612,7 @@ Transposes an `Option` of a `Result` into a `Result` of an `Option`.
|
|
|
612
612
|
|
|
613
613
|
#### Defined in
|
|
614
614
|
|
|
615
|
-
[prelude.ts:
|
|
615
|
+
[prelude.ts:20](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L20)
|
|
616
616
|
|
|
617
617
|
***
|
|
618
618
|
|
|
@@ -638,7 +638,7 @@ Throws an error if the value is a `None`.
|
|
|
638
638
|
|
|
639
639
|
#### Defined in
|
|
640
640
|
|
|
641
|
-
[
|
|
641
|
+
[core.ts:82](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/core.ts#L82)
|
|
642
642
|
|
|
643
643
|
***
|
|
644
644
|
|
|
@@ -672,7 +672,7 @@ Returns the contained `Some` value or a provided default.
|
|
|
672
672
|
|
|
673
673
|
#### Defined in
|
|
674
674
|
|
|
675
|
-
[prelude.ts:
|
|
675
|
+
[prelude.ts:17](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L17)
|
|
676
676
|
|
|
677
677
|
***
|
|
678
678
|
|
|
@@ -706,7 +706,7 @@ Returns the contained `Some` value or computes it from a closure.
|
|
|
706
706
|
|
|
707
707
|
#### Defined in
|
|
708
708
|
|
|
709
|
-
[prelude.ts:
|
|
709
|
+
[prelude.ts:18](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L18)
|
|
710
710
|
|
|
711
711
|
***
|
|
712
712
|
|
|
@@ -732,7 +732,7 @@ A tuple of `Options`, one for each element in the original `Option` of a tuple.
|
|
|
732
732
|
|
|
733
733
|
#### Defined in
|
|
734
734
|
|
|
735
|
-
[prelude.ts:
|
|
735
|
+
[prelude.ts:28](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L28)
|
|
736
736
|
|
|
737
737
|
***
|
|
738
738
|
|
|
@@ -769,7 +769,7 @@ This can be thought of as an exclusive or operation on `Option` values.
|
|
|
769
769
|
|
|
770
770
|
#### Defined in
|
|
771
771
|
|
|
772
|
-
[prelude.ts:
|
|
772
|
+
[prelude.ts:34](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L34)
|
|
773
773
|
|
|
774
774
|
***
|
|
775
775
|
|
|
@@ -807,7 +807,7 @@ An `Option` containing a tuple of the values if both are `Some`, otherwise `None
|
|
|
807
807
|
|
|
808
808
|
#### Defined in
|
|
809
809
|
|
|
810
|
-
[prelude.ts:
|
|
810
|
+
[prelude.ts:26](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L26)
|
|
811
811
|
|
|
812
812
|
***
|
|
813
813
|
|
|
@@ -847,4 +847,4 @@ An `Option` containing the result of `fn` if both `Options` are `Some`, otherwis
|
|
|
847
847
|
|
|
848
848
|
#### Defined in
|
|
849
849
|
|
|
850
|
-
[prelude.ts:
|
|
850
|
+
[prelude.ts:27](https://github.com/JiangJie/happy-rusty/blob/ba112bb228eba4376da813b0604a1f67c4b2f569/src/enum/prelude.ts#L27)
|