@consolidados/results 0.1.0 → 0.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.
Files changed (50) hide show
  1. package/package.json +9 -2
  2. package/.release-it.json +0 -20
  3. package/dist/err-B7LUEZ0f.d.cts +0 -128
  4. package/dist/err-B7LUEZ0f.d.ts +0 -128
  5. package/dist/helpers/match.cjs +0 -27
  6. package/dist/helpers/match.cjs.map +0 -1
  7. package/dist/helpers/match.d.cts +0 -13
  8. package/dist/helpers/match.d.ts +0 -13
  9. package/dist/helpers/match.js +0 -25
  10. package/dist/helpers/match.js.map +0 -1
  11. package/dist/index.cjs +0 -301
  12. package/dist/index.cjs.map +0 -1
  13. package/dist/index.d.cts +0 -5
  14. package/dist/index.d.ts +0 -5
  15. package/dist/index.js +0 -295
  16. package/dist/index.js.map +0 -1
  17. package/dist/option/index.cjs +0 -126
  18. package/dist/option/index.cjs.map +0 -1
  19. package/dist/option/index.d.cts +0 -2
  20. package/dist/option/index.d.ts +0 -2
  21. package/dist/option/index.js +0 -123
  22. package/dist/option/index.js.map +0 -1
  23. package/dist/option/option.cjs +0 -126
  24. package/dist/option/option.cjs.map +0 -1
  25. package/dist/option/option.d.cts +0 -25
  26. package/dist/option/option.d.ts +0 -25
  27. package/dist/option/option.js +0 -123
  28. package/dist/option/option.js.map +0 -1
  29. package/dist/option-DpT8KCGE.d.cts +0 -96
  30. package/dist/option-DpT8KCGE.d.ts +0 -96
  31. package/dist/result/index.cjs +0 -156
  32. package/dist/result/index.cjs.map +0 -1
  33. package/dist/result/index.d.cts +0 -2
  34. package/dist/result/index.d.ts +0 -2
  35. package/dist/result/index.js +0 -153
  36. package/dist/result/index.js.map +0 -1
  37. package/dist/result/result.cjs +0 -158
  38. package/dist/result/result.cjs.map +0 -1
  39. package/dist/result/result.d.cts +0 -27
  40. package/dist/result/result.d.ts +0 -27
  41. package/dist/result/result.js +0 -153
  42. package/dist/result/result.js.map +0 -1
  43. package/dist/types/globals.cjs +0 -4
  44. package/dist/types/globals.cjs.map +0 -1
  45. package/dist/types/globals.d.cts +0 -64
  46. package/dist/types/globals.d.ts +0 -64
  47. package/dist/types/globals.js +0 -3
  48. package/dist/types/globals.js.map +0 -1
  49. package/index.ts +0 -3
  50. package/vite.config.ts +0 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@consolidados/results",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Result types, ease and simple",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -11,6 +11,9 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/consolidados/results"
13
13
  },
14
+ "files": [
15
+ "dist"
16
+ ],
14
17
  "exports": {
15
18
  "./option": {
16
19
  "types": "./dist/option/index.d.ts",
@@ -39,7 +42,9 @@
39
42
  "scripts": {
40
43
  "build": "rm -rf dist && tsup",
41
44
  "test": "vitest run",
42
- "release": "release-it"
45
+ "release": "release-it",
46
+ "format-and-lint": "biome check .",
47
+ "format-and-lint:fix": "biome check . --write"
43
48
  },
44
49
  "keywords": [
45
50
  "Rust",
@@ -54,7 +59,9 @@
54
59
  "author": "Johnny Carreiro",
55
60
  "license": "ISC",
56
61
  "devDependencies": {
62
+ "@release-it/conventional-changelog": "^10.0.0",
57
63
  "@types/node": "^22.13.13",
64
+ "biome": "^0.3.3",
58
65
  "release-it": "^18.1.2",
59
66
  "tsup": "^8.4.0",
60
67
  "typescript": "^5.8.2",
package/.release-it.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/release-it/schema/release-it.json",
3
- "git": {
4
- "requireBranch": "main",
5
- "commitMessage": "chore: release v${version}"
6
- },
7
- "hooks": {
8
- "before:init": ["git pull", "pnpm run test"],
9
- "afeter:bump": ["pnpm run build", "npx auto-changelog -p"]
10
- },
11
- "github": {
12
- "release": true
13
- },
14
- "npm": {
15
- "publish": true
16
- },
17
- "publishConfig": {
18
- "access": "public"
19
- }
20
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * Represents a successful result (`Ok`) that contains a value.
3
- * @template T The type of the value contained in this `Ok`.
4
- */
5
- declare class Ok<T> implements ResultDefinition<T, never> {
6
- private value;
7
- /**
8
- * Creates a new `Ok` instance with the given value.
9
- * @param value The value to wrap in the `Ok` instance.
10
- */
11
- constructor(value: T);
12
- /**
13
- * Checks if this result is an `Ok`.
14
- * @returns `true` because this is an `Ok`.
15
- */
16
- isOk(): this is Ok<T>;
17
- /**
18
- * Checks if this result is an `Err`.
19
- * @returns `false` because this is an `Ok`.
20
- */
21
- isErr(): this is Err<never>;
22
- /**
23
- * Retrieves the value contained in this `Ok`.
24
- * @returns The value contained in this `Ok`.
25
- */
26
- unwrap(): T;
27
- /**
28
- * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.
29
- * @template U The type of the transformed value.
30
- * @param fn The transformation function to apply to the value.
31
- * @returns A new `Ok` containing the transformed value.
32
- */
33
- map<U>(fn: (value: T) => U): ResultDefinition<U, never>;
34
- /**
35
- * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.
36
- * @template U The type of the value in the resulting `Result`.
37
- * @param fn The transformation function to apply to the value.
38
- * @returns The result of applying the transformation function.
39
- */
40
- flatMap<U>(fn: (value: T) => ResultDefinition<U, never>): ResultDefinition<U, never>;
41
- /**
42
- * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.
43
- * @template U The type of the error (ignored for `Ok`).
44
- * @param _fn The mapping function for errors (not used).
45
- * @returns The original `Ok` instance.
46
- */
47
- mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U>;
48
- /**
49
- * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.
50
- * @throws An error because `unwrapErr` is called on an `Ok`.
51
- */
52
- unwrapErr(): never;
53
- }
54
-
55
- type OkType<T> = [T] extends [never] ? never : T;
56
- type ErrType<E> = [E] extends [never] ? never : E;
57
- /**
58
- * Represents the result of an operation that can either succeed (`Ok`) or fail (`Err`).
59
- */
60
- type Result<T, E extends Error> = Ok<OkType<T>> | Err<ErrType<E>>;
61
- /**
62
- * Represents the result methods that must be implemented for success (`Ok`) or failure (`Err`).
63
- */
64
- interface ResultDefinition<T = never, E = never> {
65
- isOk(): this is Ok<T>;
66
- isErr(): this is Err<E extends Error ? E : Error>;
67
- unwrap(): T;
68
- unwrapErr(): E;
69
- map<U>(fn: (value: T) => U): ResultDefinition<U, E>;
70
- flatMap<U>(fn: (value: T) => ResultDefinition<U, E>): ResultDefinition<U, E>;
71
- mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<T, U>;
72
- }
73
-
74
- /**
75
- * Represents a failed result (`Err`) that contains an error value.
76
- * @template E The type of the error contained in this `Err`.
77
- */
78
- declare class Err<E extends Error> extends Error implements ResultDefinition<never, E> {
79
- private error;
80
- /**
81
- * Creates a new `Err` instance with the given error value.
82
- * @param error The error to wrap in the `Err` instance.
83
- */
84
- constructor(error: E | string);
85
- /**
86
- * Checks if this result is an `Ok`.
87
- * @returns `false` because this is an `Err`.
88
- */
89
- isOk(): this is Ok<never>;
90
- /**
91
- * Checks if this result is an `Err`.
92
- * @returns `true` because this is an `Err`.
93
- */
94
- isErr(): this is Err<E extends Error ? E : Error>;
95
- /**
96
- * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.
97
- * @throws An error because `unwrap` is called on an `Err`.
98
- */
99
- unwrap(): never;
100
- /**
101
- * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.
102
- * @template U The type of the value (ignored for `Err`).
103
- * @param _fn The mapping function for values (not used).
104
- * @returns The original `Err` instance.
105
- */
106
- map<U>(_fn: (value: never) => U): ResultDefinition<never, E>;
107
- /**
108
- * Maps the error value using a transformation function and returns a new `Result` with the transformed error.
109
- * @template U The type of the transformed error.
110
- * @param fn The transformation function to apply to the error value.
111
- * @returns A new `Err` containing the transformed error.
112
- */
113
- mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U>;
114
- /**
115
- * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.
116
- * @template U The type of the value in the resulting `Result`.
117
- * @param _fn The transformation function (ignored in this implementation).
118
- * @returns The original `Err` instance.
119
- */
120
- flatMap<U>(_fn: (value: never) => ResultDefinition<U, never>): ResultDefinition<never, E>;
121
- /**
122
- * Retrieves the error value contained in this `Err`.
123
- * @returns The error value contained in this `Err`.
124
- */
125
- unwrapErr(): E;
126
- }
127
-
128
- export { Err as E, Ok as O, type Result as R };
@@ -1,128 +0,0 @@
1
- /**
2
- * Represents a successful result (`Ok`) that contains a value.
3
- * @template T The type of the value contained in this `Ok`.
4
- */
5
- declare class Ok<T> implements ResultDefinition<T, never> {
6
- private value;
7
- /**
8
- * Creates a new `Ok` instance with the given value.
9
- * @param value The value to wrap in the `Ok` instance.
10
- */
11
- constructor(value: T);
12
- /**
13
- * Checks if this result is an `Ok`.
14
- * @returns `true` because this is an `Ok`.
15
- */
16
- isOk(): this is Ok<T>;
17
- /**
18
- * Checks if this result is an `Err`.
19
- * @returns `false` because this is an `Ok`.
20
- */
21
- isErr(): this is Err<never>;
22
- /**
23
- * Retrieves the value contained in this `Ok`.
24
- * @returns The value contained in this `Ok`.
25
- */
26
- unwrap(): T;
27
- /**
28
- * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.
29
- * @template U The type of the transformed value.
30
- * @param fn The transformation function to apply to the value.
31
- * @returns A new `Ok` containing the transformed value.
32
- */
33
- map<U>(fn: (value: T) => U): ResultDefinition<U, never>;
34
- /**
35
- * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.
36
- * @template U The type of the value in the resulting `Result`.
37
- * @param fn The transformation function to apply to the value.
38
- * @returns The result of applying the transformation function.
39
- */
40
- flatMap<U>(fn: (value: T) => ResultDefinition<U, never>): ResultDefinition<U, never>;
41
- /**
42
- * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.
43
- * @template U The type of the error (ignored for `Ok`).
44
- * @param _fn The mapping function for errors (not used).
45
- * @returns The original `Ok` instance.
46
- */
47
- mapErr<U extends Error>(_fn: (err: never) => U): ResultDefinition<T, U>;
48
- /**
49
- * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.
50
- * @throws An error because `unwrapErr` is called on an `Ok`.
51
- */
52
- unwrapErr(): never;
53
- }
54
-
55
- type OkType<T> = [T] extends [never] ? never : T;
56
- type ErrType<E> = [E] extends [never] ? never : E;
57
- /**
58
- * Represents the result of an operation that can either succeed (`Ok`) or fail (`Err`).
59
- */
60
- type Result<T, E extends Error> = Ok<OkType<T>> | Err<ErrType<E>>;
61
- /**
62
- * Represents the result methods that must be implemented for success (`Ok`) or failure (`Err`).
63
- */
64
- interface ResultDefinition<T = never, E = never> {
65
- isOk(): this is Ok<T>;
66
- isErr(): this is Err<E extends Error ? E : Error>;
67
- unwrap(): T;
68
- unwrapErr(): E;
69
- map<U>(fn: (value: T) => U): ResultDefinition<U, E>;
70
- flatMap<U>(fn: (value: T) => ResultDefinition<U, E>): ResultDefinition<U, E>;
71
- mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<T, U>;
72
- }
73
-
74
- /**
75
- * Represents a failed result (`Err`) that contains an error value.
76
- * @template E The type of the error contained in this `Err`.
77
- */
78
- declare class Err<E extends Error> extends Error implements ResultDefinition<never, E> {
79
- private error;
80
- /**
81
- * Creates a new `Err` instance with the given error value.
82
- * @param error The error to wrap in the `Err` instance.
83
- */
84
- constructor(error: E | string);
85
- /**
86
- * Checks if this result is an `Ok`.
87
- * @returns `false` because this is an `Err`.
88
- */
89
- isOk(): this is Ok<never>;
90
- /**
91
- * Checks if this result is an `Err`.
92
- * @returns `true` because this is an `Err`.
93
- */
94
- isErr(): this is Err<E extends Error ? E : Error>;
95
- /**
96
- * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.
97
- * @throws An error because `unwrap` is called on an `Err`.
98
- */
99
- unwrap(): never;
100
- /**
101
- * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.
102
- * @template U The type of the value (ignored for `Err`).
103
- * @param _fn The mapping function for values (not used).
104
- * @returns The original `Err` instance.
105
- */
106
- map<U>(_fn: (value: never) => U): ResultDefinition<never, E>;
107
- /**
108
- * Maps the error value using a transformation function and returns a new `Result` with the transformed error.
109
- * @template U The type of the transformed error.
110
- * @param fn The transformation function to apply to the error value.
111
- * @returns A new `Err` containing the transformed error.
112
- */
113
- mapErr<U extends Error>(fn: (err: E) => U): ResultDefinition<never, U>;
114
- /**
115
- * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.
116
- * @template U The type of the value in the resulting `Result`.
117
- * @param _fn The transformation function (ignored in this implementation).
118
- * @returns The original `Err` instance.
119
- */
120
- flatMap<U>(_fn: (value: never) => ResultDefinition<U, never>): ResultDefinition<never, E>;
121
- /**
122
- * Retrieves the error value contained in this `Err`.
123
- * @returns The error value contained in this `Err`.
124
- */
125
- unwrapErr(): E;
126
- }
127
-
128
- export { Err as E, Ok as O, type Result as R };
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- // src/helpers/match.ts
4
- function match(matcher, cases) {
5
- if ("isOk" in matcher && matcher.isOk()) {
6
- if (!cases.Ok) throw new Error("Missing case for Ok");
7
- return cases.Ok(matcher.unwrap());
8
- }
9
- if ("isErr" in matcher && matcher.isErr()) {
10
- if (!cases.Err) throw new Error("Missing case for Err");
11
- return cases.Err(matcher.unwrapErr());
12
- }
13
- if ("isSome" in matcher && matcher.isSome()) {
14
- if (!cases.Some) throw new Error("Missing case for Some");
15
- return cases.Some(matcher.unwrap());
16
- }
17
- if ("isNone" in matcher && matcher.isNone()) {
18
- if (!cases.None) throw new Error("Missing case for None");
19
- return cases.None();
20
- }
21
- throw new Error("Invalid matcher or missing case");
22
- }
23
- global.match = match;
24
-
25
- exports.match = match;
26
- //# sourceMappingURL=match.cjs.map
27
- //# sourceMappingURL=match.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/helpers/match.ts"],"names":[],"mappings":";;;AAiBO,SAAS,KAAA,CACf,SACA,KAMI,EAAA;AACJ,EAAA,IAAI,MAAU,IAAA,OAAA,IAAW,OAAQ,CAAA,IAAA,EAAQ,EAAA;AACxC,IAAA,IAAI,CAAC,KAAM,CAAA,EAAA,EAAU,MAAA,IAAI,MAAM,qBAAqB,CAAA;AACpD,IAAA,OAAO,KAAM,CAAA,EAAA,CAAG,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGjC,EAAA,IAAI,OAAW,IAAA,OAAA,IAAW,OAAQ,CAAA,KAAA,EAAS,EAAA;AAC1C,IAAA,IAAI,CAAC,KAAM,CAAA,GAAA,EAAW,MAAA,IAAI,MAAM,sBAAsB,CAAA;AACtD,IAAA,OAAO,KAAM,CAAA,GAAA,CAAI,OAAQ,CAAA,SAAA,EAAgB,CAAA;AAAA;AAG1C,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC5C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,uBAAuB,CAAA;AACxD,IAAA,OAAO,KAAM,CAAA,IAAA,CAAK,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGnC,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC5C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,uBAAuB,CAAA;AACxD,IAAA,OAAO,MAAM,IAAK,EAAA;AAAA;AAGnB,EAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAClD;AAEC,MAAA,CAAe,KAAQ,GAAA,KAAA","file":"match.cjs","sourcesContent":["import { Result } from \"../result\";\nimport { Option } from \"../option\";\n\nexport function match<T, E extends Error, R>(\n\tmatcher: Result<T, E>,\n\tcases: {\n\t\tOk: (value: T) => R;\n\t\tErr: (error: E) => R;\n\t},\n): R;\nexport function match<T, R>(\n\tmatcher: Option<T>,\n\tcases: {\n\t\tSome: (value: T) => R;\n\t\tNone: () => R;\n\t},\n): R;\nexport function match<T, E extends Error, R>(\n\tmatcher: Result<T, E> | Option<T>,\n\tcases: {\n\t\tOk?: (value: T) => R;\n\t\tErr?: (error: E) => R;\n\t\tSome?: (value: T) => R;\n\t\tNone?: () => R;\n\t},\n): R {\n\tif (\"isOk\" in matcher && matcher.isOk()) {\n\t\tif (!cases.Ok) throw new Error(\"Missing case for Ok\");\n\t\treturn cases.Ok(matcher.unwrap());\n\t}\n\n\tif (\"isErr\" in matcher && matcher.isErr()) {\n\t\tif (!cases.Err) throw new Error(\"Missing case for Err\");\n\t\treturn cases.Err(matcher.unwrapErr() as E);\n\t}\n\n\tif (\"isSome\" in matcher && matcher.isSome()) {\n\t\tif (!cases.Some) throw new Error(\"Missing case for Some\");\n\t\treturn cases.Some(matcher.unwrap());\n\t}\n\n\tif (\"isNone\" in matcher && matcher.isNone()) {\n\t\tif (!cases.None) throw new Error(\"Missing case for None\");\n\t\treturn cases.None();\n\t}\n\n\tthrow new Error(\"Invalid matcher or missing case\");\n}\n\n(global as any).match = match;\n"]}
@@ -1,13 +0,0 @@
1
- import { R as Result } from '../err-B7LUEZ0f.cjs';
2
- import { O as Option } from '../option-DpT8KCGE.cjs';
3
-
4
- declare function match<T, E extends Error, R>(matcher: Result<T, E>, cases: {
5
- Ok: (value: T) => R;
6
- Err: (error: E) => R;
7
- }): R;
8
- declare function match<T, R>(matcher: Option<T>, cases: {
9
- Some: (value: T) => R;
10
- None: () => R;
11
- }): R;
12
-
13
- export { match };
@@ -1,13 +0,0 @@
1
- import { R as Result } from '../err-B7LUEZ0f.js';
2
- import { O as Option } from '../option-DpT8KCGE.js';
3
-
4
- declare function match<T, E extends Error, R>(matcher: Result<T, E>, cases: {
5
- Ok: (value: T) => R;
6
- Err: (error: E) => R;
7
- }): R;
8
- declare function match<T, R>(matcher: Option<T>, cases: {
9
- Some: (value: T) => R;
10
- None: () => R;
11
- }): R;
12
-
13
- export { match };
@@ -1,25 +0,0 @@
1
- // src/helpers/match.ts
2
- function match(matcher, cases) {
3
- if ("isOk" in matcher && matcher.isOk()) {
4
- if (!cases.Ok) throw new Error("Missing case for Ok");
5
- return cases.Ok(matcher.unwrap());
6
- }
7
- if ("isErr" in matcher && matcher.isErr()) {
8
- if (!cases.Err) throw new Error("Missing case for Err");
9
- return cases.Err(matcher.unwrapErr());
10
- }
11
- if ("isSome" in matcher && matcher.isSome()) {
12
- if (!cases.Some) throw new Error("Missing case for Some");
13
- return cases.Some(matcher.unwrap());
14
- }
15
- if ("isNone" in matcher && matcher.isNone()) {
16
- if (!cases.None) throw new Error("Missing case for None");
17
- return cases.None();
18
- }
19
- throw new Error("Invalid matcher or missing case");
20
- }
21
- global.match = match;
22
-
23
- export { match };
24
- //# sourceMappingURL=match.js.map
25
- //# sourceMappingURL=match.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/helpers/match.ts"],"names":[],"mappings":";AAiBO,SAAS,KAAA,CACf,SACA,KAMI,EAAA;AACJ,EAAA,IAAI,MAAU,IAAA,OAAA,IAAW,OAAQ,CAAA,IAAA,EAAQ,EAAA;AACxC,IAAA,IAAI,CAAC,KAAM,CAAA,EAAA,EAAU,MAAA,IAAI,MAAM,qBAAqB,CAAA;AACpD,IAAA,OAAO,KAAM,CAAA,EAAA,CAAG,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGjC,EAAA,IAAI,OAAW,IAAA,OAAA,IAAW,OAAQ,CAAA,KAAA,EAAS,EAAA;AAC1C,IAAA,IAAI,CAAC,KAAM,CAAA,GAAA,EAAW,MAAA,IAAI,MAAM,sBAAsB,CAAA;AACtD,IAAA,OAAO,KAAM,CAAA,GAAA,CAAI,OAAQ,CAAA,SAAA,EAAgB,CAAA;AAAA;AAG1C,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC5C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,uBAAuB,CAAA;AACxD,IAAA,OAAO,KAAM,CAAA,IAAA,CAAK,OAAQ,CAAA,MAAA,EAAQ,CAAA;AAAA;AAGnC,EAAA,IAAI,QAAY,IAAA,OAAA,IAAW,OAAQ,CAAA,MAAA,EAAU,EAAA;AAC5C,IAAA,IAAI,CAAC,KAAM,CAAA,IAAA,EAAY,MAAA,IAAI,MAAM,uBAAuB,CAAA;AACxD,IAAA,OAAO,MAAM,IAAK,EAAA;AAAA;AAGnB,EAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA;AAClD;AAEC,MAAA,CAAe,KAAQ,GAAA,KAAA","file":"match.js","sourcesContent":["import { Result } from \"../result\";\nimport { Option } from \"../option\";\n\nexport function match<T, E extends Error, R>(\n\tmatcher: Result<T, E>,\n\tcases: {\n\t\tOk: (value: T) => R;\n\t\tErr: (error: E) => R;\n\t},\n): R;\nexport function match<T, R>(\n\tmatcher: Option<T>,\n\tcases: {\n\t\tSome: (value: T) => R;\n\t\tNone: () => R;\n\t},\n): R;\nexport function match<T, E extends Error, R>(\n\tmatcher: Result<T, E> | Option<T>,\n\tcases: {\n\t\tOk?: (value: T) => R;\n\t\tErr?: (error: E) => R;\n\t\tSome?: (value: T) => R;\n\t\tNone?: () => R;\n\t},\n): R {\n\tif (\"isOk\" in matcher && matcher.isOk()) {\n\t\tif (!cases.Ok) throw new Error(\"Missing case for Ok\");\n\t\treturn cases.Ok(matcher.unwrap());\n\t}\n\n\tif (\"isErr\" in matcher && matcher.isErr()) {\n\t\tif (!cases.Err) throw new Error(\"Missing case for Err\");\n\t\treturn cases.Err(matcher.unwrapErr() as E);\n\t}\n\n\tif (\"isSome\" in matcher && matcher.isSome()) {\n\t\tif (!cases.Some) throw new Error(\"Missing case for Some\");\n\t\treturn cases.Some(matcher.unwrap());\n\t}\n\n\tif (\"isNone\" in matcher && matcher.isNone()) {\n\t\tif (!cases.None) throw new Error(\"Missing case for None\");\n\t\treturn cases.None();\n\t}\n\n\tthrow new Error(\"Invalid matcher or missing case\");\n}\n\n(global as any).match = match;\n"]}