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.
@@ -1,10 +1,10 @@
1
- [**happy-rusty**](../index.md) • **Docs**
1
+ [**happy-rusty**](../README.md) • **Docs**
2
2
 
3
3
  ***
4
4
 
5
- [happy-rusty](../index.md) / AsyncIOResult
5
+ [happy-rusty](../README.md) / AsyncIOResult
6
6
 
7
- # Type alias: AsyncIOResult\<T\>
7
+ # Type Alias: AsyncIOResult\<T\>
8
8
 
9
9
  ```ts
10
10
  type AsyncIOResult<T>: Promise<IOResult<T>>;
@@ -13,12 +13,12 @@ type AsyncIOResult<T>: Promise<IOResult<T>>;
13
13
  Represents an asynchronous I/O operation that yields a `Result<T, Error>`.
14
14
  This is a promise that resolves to `Ok(T)` if the I/O operation was successful, or `Err(Error)` if there was an error.
15
15
 
16
- ## Type parameters
16
+ ## Type Parameters
17
17
 
18
- | Type parameter | Description |
19
- | :------ | :------ |
18
+ | Type Parameter | Description |
19
+ | ------ | ------ |
20
20
  | `T` | The type of the value that is produced by a successful I/O operation. |
21
21
 
22
- ## Source
22
+ ## Defined in
23
23
 
24
- [enum/prelude.ts:609](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L609)
24
+ [prelude.ts:628](https://github.com/JiangJie/happy-rusty/blob/7218a182717eb5dbba4bfaf783977bc5e378815a/src/enum/prelude.ts#L628)
@@ -1,10 +1,10 @@
1
- [**happy-rusty**](../index.md) • **Docs**
1
+ [**happy-rusty**](../README.md) • **Docs**
2
2
 
3
3
  ***
4
4
 
5
- [happy-rusty](../index.md) / AsyncOption
5
+ [happy-rusty](../README.md) / AsyncOption
6
6
 
7
- # Type alias: AsyncOption\<T\>
7
+ # Type Alias: AsyncOption\<T\>
8
8
 
9
9
  ```ts
10
10
  type AsyncOption<T>: Promise<Option<T>>;
@@ -13,12 +13,12 @@ type AsyncOption<T>: Promise<Option<T>>;
13
13
  Represents an asynchronous operation that yields an `Option<T>`.
14
14
  This is a promise that resolves to either `Some(T)` if the value is present, or `None` if the value is absent.
15
15
 
16
- ## Type parameters
16
+ ## Type Parameters
17
17
 
18
- | Type parameter | Description |
19
- | :------ | :------ |
18
+ | Type Parameter | Description |
19
+ | ------ | ------ |
20
20
  | `T` | The type of the value that may be contained within the `Option`. |
21
21
 
22
- ## Source
22
+ ## Defined in
23
23
 
24
- [enum/prelude.ts:584](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L584)
24
+ [prelude.ts:603](https://github.com/JiangJie/happy-rusty/blob/7218a182717eb5dbba4bfaf783977bc5e378815a/src/enum/prelude.ts#L603)
@@ -1,10 +1,10 @@
1
- [**happy-rusty**](../index.md) • **Docs**
1
+ [**happy-rusty**](../README.md) • **Docs**
2
2
 
3
3
  ***
4
4
 
5
- [happy-rusty](../index.md) / AsyncResult
5
+ [happy-rusty](../README.md) / AsyncResult
6
6
 
7
- # Type alias: AsyncResult\<T, E\>
7
+ # Type Alias: AsyncResult\<T, E\>
8
8
 
9
9
  ```ts
10
10
  type AsyncResult<T, E>: Promise<Result<T, E>>;
@@ -13,13 +13,13 @@ type AsyncResult<T, E>: Promise<Result<T, E>>;
13
13
  Represents an asynchronous operation that yields a `Result<T, E>`.
14
14
  This is a promise that resolves to `Ok(T)` if the operation was successful, or `Err(E)` if there was an error.
15
15
 
16
- ## Type parameters
16
+ ## Type Parameters
17
17
 
18
- | Type parameter | Description |
19
- | :------ | :------ |
18
+ | Type Parameter | Description |
19
+ | ------ | ------ |
20
20
  | `T` | The type of the value that is produced by a successful operation. |
21
21
  | `E` | The type of the error that may be produced by a failed operation. |
22
22
 
23
- ## Source
23
+ ## Defined in
24
24
 
25
- [enum/prelude.ts:593](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L593)
25
+ [prelude.ts:612](https://github.com/JiangJie/happy-rusty/blob/7218a182717eb5dbba4bfaf783977bc5e378815a/src/enum/prelude.ts#L612)
@@ -1,10 +1,10 @@
1
- [**happy-rusty**](../index.md) • **Docs**
1
+ [**happy-rusty**](../README.md) • **Docs**
2
2
 
3
3
  ***
4
4
 
5
- [happy-rusty](../index.md) / IOResult
5
+ [happy-rusty](../README.md) / IOResult
6
6
 
7
- # Type alias: IOResult\<T\>
7
+ # Type Alias: IOResult\<T\>
8
8
 
9
9
  ```ts
10
10
  type IOResult<T>: Result<T, Error>;
@@ -13,12 +13,12 @@ type IOResult<T>: Result<T, Error>;
13
13
  Represents a synchronous operation that yields a `Result<T, Error>`.
14
14
  This is a result that is either `Ok(T)` if the operation was successful, or `Err(Error)` if there was an error.
15
15
 
16
- ## Type parameters
16
+ ## Type Parameters
17
17
 
18
- | Type parameter | Description |
19
- | :------ | :------ |
18
+ | Type Parameter | Description |
19
+ | ------ | ------ |
20
20
  | `T` | The type of the value that is produced by a successful operation. |
21
21
 
22
- ## Source
22
+ ## Defined in
23
23
 
24
- [enum/prelude.ts:601](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L601)
24
+ [prelude.ts:620](https://github.com/JiangJie/happy-rusty/blob/7218a182717eb5dbba4bfaf783977bc5e378815a/src/enum/prelude.ts#L620)
@@ -1,8 +1,8 @@
1
- [**happy-rusty**](../index.md) • **Docs**
1
+ [**happy-rusty**](../README.md) • **Docs**
2
2
 
3
3
  ***
4
4
 
5
- [happy-rusty](../index.md) / None
5
+ [happy-rusty](../README.md) / None
6
6
 
7
7
  # Variable: None
8
8
 
@@ -13,6 +13,6 @@ None: None;
13
13
  A constant representing the `None` case of an `Option`, indicating the absence of a value.
14
14
  This constant is frozen to ensure it is immutable and cannot be altered, preserving the integrity of `None` throughout the application.
15
15
 
16
- ## Source
16
+ ## Defined in
17
17
 
18
- [enum/prelude.ts:288](https://github.com/JiangJie/happy-rusty/blob/15ed105e08c6cc3943e22243c9386336a521d83e/src/enum/prelude.ts#L288)
18
+ [prelude.ts:286](https://github.com/JiangJie/happy-rusty/blob/7218a182717eb5dbba4bfaf783977bc5e378815a/src/enum/prelude.ts#L286)
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Porting some excellent design implementations from Rust to JavaScript.",
4
4
  "author": "jiang115jie@gmail.com",
5
5
  "license": "GPL-3.0",
6
- "version": "1.1.0",
6
+ "version": "1.1.2",
7
7
  "type": "module",
8
8
  "source": "src/mod.ts",
9
9
  "main": "dist/main.cjs",
@@ -47,15 +47,15 @@
47
47
  "Err"
48
48
  ],
49
49
  "devDependencies": {
50
- "@typescript-eslint/eslint-plugin": "^7.12.0",
51
- "@typescript-eslint/parser": "^7.12.0",
50
+ "@typescript-eslint/eslint-plugin": "^7.16.1",
51
+ "@typescript-eslint/parser": "^7.16.1",
52
52
  "eslint": "^8.57.0",
53
- "rollup": "^4.18.0",
53
+ "rollup": "^4.18.1",
54
54
  "rollup-plugin-dts": "^6.1.1",
55
55
  "rollup-plugin-esbuild": "^6.1.1",
56
- "typedoc": "^0.25.13",
57
- "typedoc-plugin-markdown": "^4.0.3",
58
- "typescript": "^5.4.5"
56
+ "typedoc": "^0.26.4",
57
+ "typedoc-plugin-markdown": "^4.2.1",
58
+ "typescript": "^5.5.3"
59
59
  },
60
- "packageManager": "pnpm@9.2.0"
60
+ "packageManager": "pnpm@9.5.0"
61
61
  }
@@ -282,8 +282,6 @@ export interface Option<T> {
282
282
  /**
283
283
  * Represents the absence of a value, as a specialized `Option` type.
284
284
  * The type parameter is set to `never` because `None` does not hold a value.
285
- *
286
- * @extends {Option<never>} Extends the generic `Option` type with `never` to denote no value.
287
285
  */
288
286
  export interface None extends Option<never> {
289
287
  /**
@@ -569,6 +567,27 @@ export interface Result<T, E> {
569
567
  eq(other: Result<T, E>): boolean;
570
568
 
571
569
  // #endregion
570
+
571
+ /**
572
+ * Transforms the current Result into a new Result where the type of the error result is replaced with a new type `F`.
573
+ * The type of the success result remains unchanged.
574
+ * Just same as `result as unknown as Result<T, F>`.
575
+ *
576
+ * @typeParam F - The new type for the error result.
577
+ * @returns `this` but the error result type is `F`.
578
+ */
579
+ asOk<F>(): Result<T, F>;
580
+
581
+ /**
582
+ * Transforms the current Result into a new Result where the type of the success result is replaced with a new type `U`.
583
+ * The type of the error result remains unchanged.
584
+ * Useful where you need to return an Error chained to another type.
585
+ * Just same as `result as unknown as Result<U, E>`.
586
+ *
587
+ * @typeParam U - The new type for the success result.
588
+ * @returns `this` but the success result type is `U`.
589
+ */
590
+ asErr<U>(): Result<U, E>;
572
591
  }
573
592
 
574
593
  /**
@@ -830,6 +849,13 @@ export function Ok<T, E>(value: T): Result<T, E> {
830
849
  assertResult(other);
831
850
  return other.isOk() && other.unwrap() === value;
832
851
  },
852
+
853
+ asOk<F>(): Result<T, F> {
854
+ return ok as unknown as Result<T, F>;
855
+ },
856
+ asErr(): never {
857
+ throw new TypeError('Called `Result::asErr()` on an `Ok` value');
858
+ },
833
859
  } as const;
834
860
 
835
861
  return ok;
@@ -901,6 +927,13 @@ export function Err<T, E>(error: E): Result<T, E> {
901
927
  assertResult(other);
902
928
  return other.isErr() && other.unwrapErr() === error;
903
929
  },
930
+
931
+ asOk(): never {
932
+ throw new TypeError('Called `Result::asOk()` on an `Err` value');
933
+ },
934
+ asErr<U>(): Result<U, E> {
935
+ return err as unknown as Result<U, E>;
936
+ },
904
937
  } as const;
905
938
 
906
939
  return err;