@zokugun/xtry 0.12.0 → 0.12.1

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.
@@ -22,9 +22,12 @@ function match(result, handlers) {
22
22
  return handlers.success(result.value);
23
23
  }
24
24
  }
25
- function unwrap(result) {
25
+ function unwrap(result, transform) {
26
26
  if (result.fails) {
27
- if (result.error instanceof Error) {
27
+ if (transform) {
28
+ throw transform(result.error);
29
+ }
30
+ else if (result.error instanceof Error) {
28
31
  throw result.error;
29
32
  }
30
33
  else {
@@ -1,8 +1,16 @@
1
1
  import type { Result } from './result.cjs';
2
- export declare function map<T, E, U>(result: Result<T, E>, transform: (value: T) => U): Result<U, E>;
3
- export declare function match<T, E, R>(result: Result<T, E>, handlers: {
2
+ type LimitedResult<T, E> = {
3
+ error: E;
4
+ fails: true;
5
+ } | {
6
+ fails: false;
7
+ value: T;
8
+ };
9
+ export declare function map<T, E, U>(result: LimitedResult<T, E>, transform: (value: T) => U): Result<U, E>;
10
+ export declare function match<T, E, R>(result: LimitedResult<T, E>, handlers: {
4
11
  failure: (error: E) => R;
5
12
  success: (value: T) => R;
6
13
  }): R;
7
- export declare function unwrap<T, E>(result: Result<T, E>): T;
8
- export declare function unwrapOr<T, E, F>(result: Result<T, E>, fallback: F): F | T;
14
+ export declare function unwrap<T, E>(result: LimitedResult<T, E>, transform?: (error: E) => Error): T;
15
+ export declare function unwrapOr<T, E, F>(result: LimitedResult<T, E>, fallback: F): F | T;
16
+ export {};
@@ -1,8 +1,16 @@
1
1
  import type { Result } from './result.mjs';
2
- export declare function map<T, E, U>(result: Result<T, E>, transform: (value: T) => U): Result<U, E>;
3
- export declare function match<T, E, R>(result: Result<T, E>, handlers: {
2
+ type LimitedResult<T, E> = {
3
+ error: E;
4
+ fails: true;
5
+ } | {
6
+ fails: false;
7
+ value: T;
8
+ };
9
+ export declare function map<T, E, U>(result: LimitedResult<T, E>, transform: (value: T) => U): Result<U, E>;
10
+ export declare function match<T, E, R>(result: LimitedResult<T, E>, handlers: {
4
11
  failure: (error: E) => R;
5
12
  success: (value: T) => R;
6
13
  }): R;
7
- export declare function unwrap<T, E>(result: Result<T, E>): T;
8
- export declare function unwrapOr<T, E, F>(result: Result<T, E>, fallback: F): F | T;
14
+ export declare function unwrap<T, E>(result: LimitedResult<T, E>, transform?: (error: E) => Error): T;
15
+ export declare function unwrapOr<T, E, F>(result: LimitedResult<T, E>, fallback: F): F | T;
16
+ export {};
@@ -16,9 +16,12 @@ export function match(result, handlers) {
16
16
  return handlers.success(result.value);
17
17
  }
18
18
  }
19
- export function unwrap(result) {
19
+ export function unwrap(result, transform) {
20
20
  if (result.fails) {
21
- if (result.error instanceof Error) {
21
+ if (transform) {
22
+ throw transform(result.error);
23
+ }
24
+ else if (result.error instanceof Error) {
22
25
  throw result.error;
23
26
  }
24
27
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zokugun/xtry",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "author": {
5
5
  "name": "Baptiste Augrain",
6
6
  "email": "daiyam@zokugun.org"
@@ -111,7 +111,7 @@
111
111
  "@zokugun/eslint-config-test": "0.2.0",
112
112
  "@zokugun/eslint-config-ts": "0.3.2",
113
113
  "@zokugun/fs-extra-plus": "0.6.1",
114
- "@zokugun/tsc-leda": "0.8.3",
114
+ "@zokugun/tsc-leda": "0.9.0",
115
115
  "eslint": "10.8.1",
116
116
  "fixpack": "4.0.0",
117
117
  "fs-extra": "11.3.5",