@consolidados/results 0.3.0 → 0.5.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.
Files changed (42) hide show
  1. package/README.md +129 -10
  2. package/dist/helpers/match.cjs +24 -42
  3. package/dist/helpers/match.cjs.map +1 -1
  4. package/dist/helpers/match.d.cts +9 -17
  5. package/dist/helpers/match.d.ts +9 -17
  6. package/dist/helpers/match.js +24 -42
  7. package/dist/helpers/match.js.map +1 -1
  8. package/dist/index.cjs +41 -46
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +41 -46
  13. package/dist/index.js.map +1 -1
  14. package/dist/option/index.cjs +17 -4
  15. package/dist/option/index.cjs.map +1 -1
  16. package/dist/option/index.d.cts +1 -1
  17. package/dist/option/index.d.ts +1 -1
  18. package/dist/option/index.js +17 -4
  19. package/dist/option/index.js.map +1 -1
  20. package/dist/option/option.cjs +17 -4
  21. package/dist/option/option.cjs.map +1 -1
  22. package/dist/option/option.d.cts +2 -2
  23. package/dist/option/option.d.ts +2 -2
  24. package/dist/option/option.js +17 -4
  25. package/dist/option/option.js.map +1 -1
  26. package/dist/{option-B_KKIecf.d.cts → option-CYCiGxtw.d.cts} +13 -0
  27. package/dist/{option-B_KKIecf.d.ts → option-CYCiGxtw.d.ts} +13 -0
  28. package/dist/result/index.cjs +9 -2
  29. package/dist/result/index.cjs.map +1 -1
  30. package/dist/result/index.d.cts +1 -1
  31. package/dist/result/index.d.ts +1 -1
  32. package/dist/result/index.js +9 -2
  33. package/dist/result/index.js.map +1 -1
  34. package/dist/result/result.cjs +9 -2
  35. package/dist/result/result.cjs.map +1 -1
  36. package/dist/result/result.d.cts +2 -2
  37. package/dist/result/result.d.ts +2 -2
  38. package/dist/result/result.js +9 -2
  39. package/dist/result/result.js.map +1 -1
  40. package/dist/types/globals.d.cts +9 -17
  41. package/dist/types/globals.d.ts +9 -17
  42. package/package.json +3 -4
package/dist/index.cjs CHANGED
@@ -1,66 +1,51 @@
1
1
  'use strict';
2
2
 
3
3
  // src/helpers/match.ts
4
+ var TAG = Symbol.for("@consolidados/results.tag");
4
5
  function match(matcher, cases, discriminant) {
5
- if (typeof matcher === "string" || typeof matcher === "number" || typeof matcher === "symbol") {
6
+ const t = typeof matcher;
7
+ if (t === "string" || t === "number" || t === "symbol") {
6
8
  const handler = cases[matcher];
7
- if (handler) {
9
+ if (handler) return handler();
10
+ if (cases.default) return cases.default();
11
+ throw new Error(`No case found for value: ${String(matcher)}`);
12
+ }
13
+ if (matcher !== null && t === "object") {
14
+ const tag = matcher[TAG];
15
+ if (tag !== void 0) {
16
+ const handler = cases[tag];
17
+ if (!handler) throw new Error(`Missing case for ${tag}`);
18
+ if (tag === "Ok" || tag === "Some") return handler(matcher.unwrap());
19
+ if (tag === "Err") return handler(matcher.unwrapErr());
8
20
  return handler();
9
21
  }
10
- if (cases.default) {
11
- return cases.default();
22
+ if (discriminant) {
23
+ const dv = matcher[discriminant];
24
+ const handler = cases[dv];
25
+ if (handler) return handler(matcher);
26
+ if (cases.default) return cases.default(matcher);
27
+ throw new Error(`No case found for discriminant value: ${String(dv)}`);
12
28
  }
13
- throw new Error(`No case found for value: ${String(matcher)}`);
14
- }
15
- if (typeof matcher === "object" && matcher !== null && !discriminant) {
16
- for (const key in cases) {
29
+ for (const key in matcher) {
17
30
  if (key === "default") continue;
18
- if (key in matcher) {
31
+ if (key in cases) {
19
32
  const handler = cases[key];
20
33
  if (handler) {
21
34
  return typeof handler === "function" ? handler(matcher[key]) : handler();
22
35
  }
23
36
  }
24
37
  }
25
- if (cases.default) {
26
- return cases.default();
27
- }
28
- }
29
- if (discriminant && typeof matcher === "object" && matcher !== null) {
30
- const discriminantValue = matcher[discriminant];
31
- const handler = cases[discriminantValue];
32
- if (handler) {
33
- return handler(matcher);
34
- }
35
- if (cases.default) {
36
- return cases.default(matcher);
37
- }
38
- throw new Error(
39
- `No case found for discriminant value: ${String(discriminantValue)}`
40
- );
41
- }
42
- if (typeof matcher === "object" && matcher !== null && "isOk" in matcher && matcher.isOk()) {
43
- if (!cases.Ok) throw new Error("Missing case for Ok");
44
- return cases.Ok(matcher.unwrap());
45
- }
46
- if (typeof matcher === "object" && matcher !== null && "isErr" in matcher && matcher.isErr()) {
47
- if (!cases.Err) throw new Error("Missing case for Err");
48
- return cases.Err(matcher.unwrapErr());
49
- }
50
- if (typeof matcher === "object" && matcher !== null && "isSome" in matcher && matcher.isSome()) {
51
- if (!cases.Some) throw new Error("Missing case for Some");
52
- return cases.Some(matcher.unwrap());
53
- }
54
- if (typeof matcher === "object" && matcher !== null && "isNone" in matcher && matcher.isNone()) {
55
- if (!cases.None) throw new Error("Missing case for None");
56
- return cases.None();
38
+ if (cases.default) return cases.default();
57
39
  }
58
40
  throw new Error("Invalid matcher or missing case");
59
41
  }
60
- global.match = match;
42
+ globalThis.match = match;
61
43
 
62
44
  // src/result/__internal__/return-types/err.ts
45
+ var TAG2 = Symbol.for("@consolidados/results.tag");
63
46
  var Err = class _Err {
47
+ /** Hidden tag — read by `match()` for O(1) dispatch. */
48
+ [TAG2] = "Err";
64
49
  error;
65
50
  /**
66
51
  * Creates a new `Err` instance with the given error value.
@@ -171,6 +156,7 @@ var Err = class _Err {
171
156
  };
172
157
 
173
158
  // src/result/__internal__/return-types/ok.ts
159
+ var TAG3 = Symbol.for("@consolidados/results.tag");
174
160
  var Ok = class _Ok {
175
161
  /**
176
162
  * Creates a new `Ok` instance with the given value.
@@ -179,6 +165,9 @@ var Ok = class _Ok {
179
165
  constructor(_value) {
180
166
  this._value = _value;
181
167
  }
168
+ /** Hidden tag — read by `match()` for O(1) dispatch. Symbol-keyed so it
169
+ * doesn't appear in `for...in`, `Object.keys`, or `JSON.stringify`. */
170
+ [TAG3] = "Ok";
182
171
  /**
183
172
  * Checks if this result is an `Ok`.
184
173
  * @returns `true` because this is an `Ok`.
@@ -286,10 +275,11 @@ function Ok2(value) {
286
275
  function Err2(error) {
287
276
  return new Err(error);
288
277
  }
289
- global.Ok = Ok2;
290
- global.Err = Err2;
278
+ globalThis.Ok = Ok2;
279
+ globalThis.Err = Err2;
291
280
 
292
281
  // src/option/__internal__/return-types/some.ts
282
+ var TAG4 = Symbol.for("@consolidados/results.tag");
293
283
  var Some2 = class _Some {
294
284
  /**
295
285
  * Creates a new `Some` option with the given value.
@@ -298,6 +288,8 @@ var Some2 = class _Some {
298
288
  constructor(_value) {
299
289
  this._value = _value;
300
290
  }
291
+ /** Hidden tag — read by `match()` for O(1) dispatch. */
292
+ [TAG4] = "Some";
301
293
  /**
302
294
  * Checks if this option is a `Some`.
303
295
  * @returns `true` if this option is a `Some`, otherwise `false`.
@@ -382,7 +374,10 @@ var Some2 = class _Some {
382
374
  };
383
375
 
384
376
  // src/option/__internal__/return-types/none.ts
377
+ var TAG5 = Symbol.for("@consolidados/results.tag");
385
378
  var None3 = class {
379
+ /** Hidden tag — read by `match()` for O(1) dispatch. */
380
+ [TAG5] = "None";
386
381
  /**
387
382
  * Checks if this option is a `Some`.
388
383
  * @returns `false` because this is a `None`.
@@ -479,8 +474,8 @@ function None2() {
479
474
  }
480
475
  return NONE_INSTANCE;
481
476
  }
482
- global.Some = Some3;
483
- global.None = None2;
477
+ globalThis.Some = Some3;
478
+ globalThis.None = None2;
484
479
 
485
480
  exports.Err = Err2;
486
481
  exports.None = None2;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helpers/match.ts","../src/result/__internal__/return-types/err.ts","../src/result/__internal__/return-types/ok.ts","../src/result/result.ts","../src/option/__internal__/return-types/some.ts","../src/option/__internal__/return-types/none.ts","../src/option/option.ts"],"names":["Ok","Err","Some","None"],"mappings":";;;AAkHO,SAAS,KAAA,CACd,OACA,EAAA,KAAA,EACA,YACG,EAAA;AAEH,EACE,IAAA,OAAO,YAAY,QACnB,IAAA,OAAO,YAAY,QACnB,IAAA,OAAO,YAAY,QACnB,EAAA;AACA,IAAM,MAAA,OAAA,GAA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A,aAAgB,EAAgB,EAAA;AAC9B,IAAA,OAAO,EAAG,EAAA;AAAA;AACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAQ,KAAU,EAAA;AAChB,IAAA,OAAOF,KAAI,KAAK,CAAA;AAAA;AAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAU,UAAkD,EAAA;AAC1D,IAAA,OAAOE,KAAY,EAAA;AAAA;AAEvB,CAAA;;;ACrFA,SAASD,MAAQ,KAAuB,EAAA;AACvC,EAAO,OAAA,IAAIA,MAAS,KAAK,CAAA;AAC1B;AAEA,IAAI,aAAiC,GAAA,IAAA;AAWrC,SAASC,KAAiB,GAAA;AACzB,EAAA,IAAI,CAAC,aAAe,EAAA;AACnB,IAAA,aAAA,GAAgB,IAAIA,KAAS,EAAA;AAAA;AAE9B,EAAO,OAAA,aAAA;AACR;AAEC,MAAA,CAAe,IAAOD,GAAAA,KAAAA;AACtB,MAAA,CAAe,IAAOC,GAAAA,KAAAA","file":"index.cjs","sourcesContent":["import type { Option } from \"../option\";\nimport type { Result } from \"../result\";\n\n// Utility types for mixed primitive + object unions\ntype PrimitiveMembers<T> = Extract<T, PropertyKey>;\ntype ObjectKeys<T> = T extends object ? keyof T : never;\ntype ObjectPropertyType<T, K extends PropertyKey> = T extends object\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\n// Helper to determine if a key K is a primitive member or object key\ntype HandlerFor<T, K extends PropertyKey, R> = K extends PrimitiveMembers<T>\n ? () => R\n : K extends ObjectKeys<T>\n ? (value: ObjectPropertyType<T, K>) => R\n : never;\n\n// Build cases type with a single mapped type\ntype MatchCases<T, R, HasDefault extends boolean = false> = (HasDefault extends true\n ? Partial<{\n [K in PrimitiveMembers<T> | ObjectKeys<T>]: HandlerFor<T, K, R>;\n }>\n : {\n [K in PrimitiveMembers<T> | ObjectKeys<T>]: HandlerFor<T, K, R>;\n }) &\n (HasDefault extends true ? { default: () => R } : {});\n\n// Overload for Result type\nexport function match<T, E, R>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => R;\n Err: (error: E) => R;\n },\n): R;\n\n// Overload for Option type\nexport function match<T, R>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => R;\n None: () => R;\n },\n): R;\n\n// Overload for mixed primitive + object unions WITH default (cases optional)\nexport function match<T extends PropertyKey | object, R>(\n matcher: T,\n cases: MatchCases<T, R, true>,\n): R;\n\n// Overload for mixed primitive + object unions WITHOUT default (exhaustive)\nexport function match<T extends PropertyKey | object, R>(\n matcher: T,\n cases: MatchCases<T, R, false>,\n): R;\n\n// Overload for discriminated unions with default case\nexport function match<\n T extends { [K in D]: string | number | symbol },\n D extends keyof T,\n R,\n>(\n matcher: T,\n cases: { [K in T[D]]?: (value: Extract<T, { [P in D]: K }>) => R } & {\n default: (value: T) => R;\n },\n discriminant: D,\n): R;\n\n// Overload for discriminated unions without default case (exhaustive)\nexport function match<\n T extends { [K in D]: string | number | symbol },\n D extends keyof T,\n R,\n>(\n matcher: T,\n cases: { [K in T[D]]: (value: Extract<T, { [P in D]: K }>) => R },\n discriminant: D,\n): R;\n\n// Overload for primitives with default case\nexport function match<T extends PropertyKey, R>(\n matcher: T,\n cases: Partial<Record<T, () => R>> & { default: () => R },\n): R;\n\n// Overload for primitives without default case (exhaustive)\nexport function match<T extends PropertyKey, R>(\n matcher: T,\n cases: Record<T, () => R>,\n): R;\n\n// Result -> Option conversion\nexport function match<T, E>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => Option<T>;\n Err: (error: E) => Option<T>;\n },\n): Option<T>;\n\n// Option -> Result conversion\nexport function match<T, E>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => Result<T, E>;\n None: () => Result<T, E>;\n },\n): Result<T, E>;\n\n// Implementation\nexport function match<T, E, R>(\n matcher: Result<T, E> | Option<T> | any,\n cases: any,\n discriminant?: keyof any,\n): R {\n // Handle primitives (string, number, symbol) FIRST\n if (\n typeof matcher === \"string\" ||\n typeof matcher === \"number\" ||\n typeof matcher === \"symbol\"\n ) {\n const handler = cases[matcher];\n\n if (handler) {\n return handler();\n }\n\n if (cases.default) {\n return cases.default();\n }\n\n throw new Error(`No case found for value: ${String(matcher)}`);\n }\n\n // NEW: Handle objects with specific property keys (like { Other: [...] })\n // This must come BEFORE discriminated union check to handle mixed unions\n if (typeof matcher === \"object\" && matcher !== null && !discriminant) {\n // Check if any case key matches a property in the matcher object\n for (const key in cases) {\n if (key === \"default\") continue;\n\n if (key in matcher) {\n const handler = cases[key];\n if (handler) {\n return typeof handler === \"function\"\n ? handler(matcher[key])\n : handler();\n }\n }\n }\n\n // If no match found and there's a default, use it\n if (cases.default) {\n return cases.default();\n }\n }\n\n // Handle discriminated unions\n if (discriminant && typeof matcher === \"object\" && matcher !== null) {\n const discriminantValue = matcher[discriminant];\n const handler = cases[discriminantValue];\n\n if (handler) {\n return handler(matcher);\n }\n\n if (cases.default) {\n return cases.default(matcher);\n }\n\n throw new Error(\n `No case found for discriminant value: ${String(discriminantValue)}`,\n );\n }\n\n // Early return for Result.Ok\n if (\n typeof matcher === \"object\" &&\n matcher !== null &&\n \"isOk\" in matcher &&\n matcher.isOk()\n ) {\n if (!cases.Ok) throw new Error(\"Missing case for Ok\");\n return cases.Ok(matcher.unwrap());\n }\n\n // Early return for Result.Err\n if (\n typeof matcher === \"object\" &&\n matcher !== null &&\n \"isErr\" in matcher &&\n matcher.isErr()\n ) {\n if (!cases.Err) throw new Error(\"Missing case for Err\");\n return cases.Err(matcher.unwrapErr() as E);\n }\n\n // Early return for Option.Some\n if (\n typeof matcher === \"object\" &&\n matcher !== null &&\n \"isSome\" in matcher &&\n matcher.isSome()\n ) {\n if (!cases.Some) throw new Error(\"Missing case for Some\");\n return cases.Some(matcher.unwrap());\n }\n\n // Early return for Option.None\n if (\n typeof matcher === \"object\" &&\n matcher !== null &&\n \"isNone\" in matcher &&\n matcher.isNone()\n ) {\n if (!cases.None) throw new Error(\"Missing case for None\");\n return cases.None();\n }\n\n throw new Error(\"Invalid matcher or missing case\");\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).match = match;\n","import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`. Can be any type (Error, string, enum, etc).\n */\nexport class Err<E> implements ResultDefinition<never, E> {\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance. Can be any type.\n */\n constructor(error: E) {\n // Store error as-is - conversion is handled by factory function\n this.error = error;\n // Object.setPrototypeOf(this, Err.prototype);\n //\n // if (Error.captureStackTrace) {\n // Error.captureStackTrace(this, Err);\n // }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error. Can be any type.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @template F The type of the error in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance cast to the new error type.\n */\n flatMap<U, F = E>(\n _fn: (value: never) => ResultDefinition<U, F>,\n ): ResultDefinition<U, E> {\n return this as unknown as ResultDefinition<U, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Returns the inner error. After an `isErr()` type guard, TypeScript narrows the return type to `E`.\n * Without a type guard, returns `T | E` (use `isOk()` or `isErr()` for type narrowing).\n * @returns The error value contained in this `Err`.\n */\n value(): E {\n return this.error;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise returns the provided default value.\n * @template U The type of the default value.\n * @param defaultValue The value to return since this is an `Err`.\n * @returns The provided default value.\n */\n unwrapOr<U>(defaultValue: U): U {\n return defaultValue;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise computes and returns the result of the provided function.\n * @template U The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The result of calling the provided function with the error.\n */\n unwrapOrElse<U>(fn: (error: E) => U): U {\n return fn(this.error);\n }\n\n /**\n * Returns this `Err` if it is `Err`, otherwise returns the result of the provided function.\n * @template T The type of the alternative success value.\n * @template F The type of the alternative error.\n * @param fn The function to compute the alternative result.\n * @returns The result of calling the provided function with the error.\n */\n orElse<T, F>(\n fn: (error: E) => ResultDefinition<T, F>,\n ): ResultDefinition<T, F> {\n return fn(this.error);\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /**\n * Creates a new `Ok` instance with the given value.\n * @param _value The value to wrap in the `Ok` instance.\n */\n constructor(private _value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this._value;\n }\n\n /**\n * Returns the inner value. After an `isOk()` type guard, TypeScript narrows the return type to `T`.\n * Without a type guard, returns `T | E` (use `isOk()` or `isErr()` for type narrowing).\n * @returns The value contained in this `Ok`.\n */\n value(): T {\n return this._value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this._value)) as unknown as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @template E The type of the error in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U, E = never>(\n fn: (value: T) => ResultDefinition<U, E>,\n ): ResultDefinition<U, E> {\n return fn(this._value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`). Can be any type.\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n mapErr<U>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise returns the provided default value.\n * @template U The type of the default value.\n * @param defaultValue The value to return if this is an `Err`.\n * @returns The value contained in this `Ok`.\n */\n unwrapOr<U>(defaultValue: U): T {\n return this._value;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise computes and returns the result of the provided function.\n * @template U The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The value contained in this `Ok`.\n */\n unwrapOrElse<U>(fn: (error: never) => U): T {\n return this._value;\n }\n\n /**\n * Returns this `Ok` if it is `Ok`, otherwise returns the result of the provided function.\n * @template F The type of the alternative error.\n * @param fn The function to compute the alternative result.\n * @returns The original `Ok` instance.\n */\n orElse<F>(fn: (error: never) => ResultDefinition<T, F>): ResultDefinition<T, F> {\n return this as unknown as ResultDefinition<T, F>;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return Some(this._value);\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates an Err - strings are converted to Error, everything else preserved\n */\nfunction Err<E>(error: E): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(global as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n","import type { None as NoneType } from \"./none\";\nimport type { Option } from \"./option\";\nimport { None } from \"../../option\";\nimport { Ok } from \"@/result\";\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /**\n * Creates a new `Some` option with the given value.\n * @param _value The value to be wrapped in the `Some` option.\n */\n constructor(private _value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is NoneType {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this._value;\n }\n\n /**\n * Returns the inner value. After an `isSome()` type guard, TypeScript narrows the return type to `T`.\n * Without a type guard, returns `T | undefined` (use `isSome()` or `isNone()` for type narrowing).\n * @returns The value held by this `Some` option.\n */\n value(): T {\n return this._value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this._value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this._value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this._value;\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the function provided.\n * @template U The type of the default value.\n * @param _fn A function to compute the default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOrElse<U>(_fn: () => U): T {\n return this._value;\n }\n\n /**\n * Converts this `Option` to a `Result`, using the provided error value if this is `None`.\n * @template E The type of the error.\n * @param _error The error value to use if this is `None` (ignored since this is `Some`).\n * @returns An `Ok` result containing the value from this `Some`.\n */\n okOr<E>(_error: E) {\n return Ok(this._value);\n }\n\n /**\n * Filters this `Option` based on a predicate function.\n * @param predicate The function to test the value.\n * @returns This `Some` if the predicate returns true, otherwise `None`.\n */\n filter(predicate: (value: T) => boolean): Option<T> {\n return predicate(this._value) ? this : None();\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\nimport { None as NoneFactory } from \"../../option\";\nimport { Err } from \"@/result\";\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Returns `undefined` for a `None` option. After an `isNone()` type guard, TypeScript narrows the return type to `undefined`.\n * Without a type guard, returns `T | undefined` (use `isSome()` or `isNone()` for type narrowing).\n * Unlike `unwrap()`, this method does not throw an error.\n * @returns `undefined` because this is a `None`.\n */\n value(): undefined {\n return undefined;\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The singleton `None` instance.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return NoneFactory();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The singleton `None` instance.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return NoneFactory();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n /**\n * Computes and returns the default value using the provided function, since `None` has no value.\n * @template T The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The result of calling the provided function.\n */\n unwrapOrElse<T>(fn: () => T): T {\n return fn();\n }\n\n /**\n * Converts this `Option` to a `Result`, using the provided error value since this is `None`.\n * @template E The type of the error.\n * @param error The error value to use.\n * @returns An `Err` result containing the provided error.\n */\n okOr<E>(error: E) {\n return Err(error);\n }\n\n /**\n * Filters this `Option` based on a predicate function.\n * @param _predicate The function to test the value (ignored since this is `None`).\n * @returns `None` since there is no value to filter.\n */\n filter<T>(_predicate: (value: never) => boolean): Option<T> {\n return NoneFactory();\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\nlet NONE_INSTANCE: NoneType | null = null;\n\n/**\n * Returns the singleton `None` instance, representing an `Option` with no value.\n * Uses a singleton pattern to reduce memory allocations.\n * @returns The singleton `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\tif (!NONE_INSTANCE) {\n\t\tNONE_INSTANCE = new NoneType();\n\t}\n\treturn NONE_INSTANCE;\n}\n\n(global as any).Some = Some;\n(global as any).None = None;\n\nexport { None, Some, Option };\n"]}
1
+ {"version":3,"sources":["../src/helpers/match.ts","../src/result/__internal__/return-types/err.ts","../src/result/__internal__/return-types/ok.ts","../src/result/result.ts","../src/option/__internal__/return-types/some.ts","../src/option/__internal__/return-types/none.ts","../src/option/option.ts"],"names":["TAG","Ok","Err","Some","None"],"mappings":";;;AAKA,IAAM,GAAA,GAAM,MAAO,CAAA,GAAA,CAAI,2BAA2B,CAAA;AA+F3C,SAAS,KAAA,CACd,OACA,EAAA,KAAA,EACA,YACG,EAAA;AA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IAAA,OAAOF,KAAI,KAAK,CAAA;AAAA;AAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAU,UAAkD,EAAA;AAC1D,IAAA,OAAOE,KAAY,EAAA;AAAA;AAEvB,CAAA;;;AC5FA,SAASD,MAAQ,KAAuB,EAAA;AACvC,EAAO,OAAA,IAAIA,MAAS,KAAK,CAAA;AAC1B;AAEA,IAAI,aAAiC,GAAA,IAAA;AAWrC,SAASC,KAAiB,GAAA;AACzB,EAAA,IAAI,CAAC,aAAe,EAAA;AACnB,IAAA,aAAA,GAAgB,IAAIA,KAAS,EAAA;AAAA;AAE9B,EAAO,OAAA,aAAA;AACR;AAEC,UAAA,CAAmB,IAAOD,GAAAA,KAAAA;AAC1B,UAAA,CAAmB,IAAOC,GAAAA,KAAAA","file":"index.cjs","sourcesContent":["import type { Option } from \"../option\";\nimport type { Result } from \"../result\";\n\n// Hidden discriminant tag — set by Ok/Err/Some/None instances for O(1) dispatch.\n// Same Symbol as the one declared in the variant classes via Symbol.for.\nconst TAG = Symbol.for(\"@consolidados/results.tag\");\n\n// Utility types for mixed primitive + object unions\ntype PrimitiveMembers<T> = Extract<T, PropertyKey>;\ntype ObjectKeys<T> = T extends object ? keyof T : never;\ntype ObjectPropertyType<T, K extends PropertyKey> = T extends object\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\n// Helper to determine if a key K is a primitive member or object key\ntype HandlerFor<T, K extends PropertyKey, R> = K extends PrimitiveMembers<T>\n ? () => R\n : K extends ObjectKeys<T>\n ? (value: ObjectPropertyType<T, K>) => R\n : never;\n\n// Build cases type with a single mapped type\ntype MatchCases<T, R, HasDefault extends boolean = false> = (HasDefault extends true\n ? Partial<{\n [K in PrimitiveMembers<T> | ObjectKeys<T>]: HandlerFor<T, K, R>;\n }>\n : {\n [K in PrimitiveMembers<T> | ObjectKeys<T>]: HandlerFor<T, K, R>;\n }) &\n (HasDefault extends true ? { default: () => R } : {});\n\n// Overload for Result type\nexport function match<T, E, ROk, RErr>(\n matcher: Result<T, E>,\n cases: {\n Ok: (value: T) => ROk;\n Err: (error: E) => RErr;\n },\n): ROk | RErr;\n\n// Overload for Option type\nexport function match<T, RSome, RNone>(\n matcher: Option<T>,\n cases: {\n Some: (value: T) => RSome;\n None: () => RNone;\n },\n): RSome | RNone;\n\n// Overload for mixed primitive + object unions WITH default (cases optional)\nexport function match<T extends PropertyKey | object, R>(\n matcher: T,\n cases: MatchCases<T, R, true>,\n): R;\n\n// Overload for mixed primitive + object unions WITHOUT default (exhaustive)\nexport function match<T extends PropertyKey | object, R>(\n matcher: T,\n cases: MatchCases<T, R, false>,\n): R;\n\n// Overload for discriminated unions with default case\nexport function match<\n T extends { [K in D]: string | number | symbol },\n D extends keyof T,\n R,\n>(\n matcher: T,\n cases: { [K in T[D]]?: (value: Extract<T, { [P in D]: K }>) => R } & {\n default: (value: T) => R;\n },\n discriminant: D,\n): R;\n\n// Overload for discriminated unions without default case (exhaustive)\nexport function match<\n T extends { [K in D]: string | number | symbol },\n D extends keyof T,\n R,\n>(\n matcher: T,\n cases: { [K in T[D]]: (value: Extract<T, { [P in D]: K }>) => R },\n discriminant: D,\n): R;\n\n// Overload for primitives with default case\nexport function match<T extends PropertyKey, R>(\n matcher: T,\n cases: Partial<Record<T, () => R>> & { default: () => R },\n): R;\n\n// Overload for primitives without default case (exhaustive)\nexport function match<T extends PropertyKey, R>(\n matcher: T,\n cases: Record<T, () => R>,\n): R;\n\n// Implementation\nexport function match<T, E, R>(\n matcher: Result<T, E> | Option<T> | any,\n cases: any,\n discriminant?: keyof any,\n): R {\n // 1) Primitives (string/number/symbol) — direct key lookup, O(1).\n const t = typeof matcher;\n if (t === \"string\" || t === \"number\" || t === \"symbol\") {\n const handler = cases[matcher];\n if (handler) return handler();\n if (cases.default) return cases.default();\n throw new Error(`No case found for value: ${String(matcher)}`);\n }\n\n if (matcher !== null && t === \"object\") {\n // 2) Tagged variant (Ok/Err/Some/None) — single Symbol read + single lookup.\n // The Symbol property is invisible to `for...in`, `Object.keys`, and\n // `JSON.stringify`, so mixed unions with plain-object variants are\n // unaffected.\n const tag = matcher[TAG];\n if (tag !== undefined) {\n const handler = cases[tag];\n if (!handler) throw new Error(`Missing case for ${tag}`);\n if (tag === \"Ok\" || tag === \"Some\") return handler(matcher.unwrap());\n if (tag === \"Err\") return handler(matcher.unwrapErr() as E);\n // tag === \"None\"\n return handler();\n }\n\n // 3) Discriminated union via explicit `discriminant` arg — O(1).\n if (discriminant) {\n const dv = matcher[discriminant];\n const handler = cases[dv];\n if (handler) return handler(matcher);\n if (cases.default) return cases.default(matcher);\n throw new Error(`No case found for discriminant value: ${String(dv)}`);\n }\n\n // 4) Mixed primitive + object union — iterate matcher's own enumerable\n // keys (usually 1 for tagged variant objects like `{ Other: [...] }`)\n // and look up by key in cases. This flips the loop from O(cases)\n // to O(matcher-keys), which is effectively O(1) for tagged variants.\n for (const key in matcher) {\n if (key === \"default\") continue;\n if (key in cases) {\n const handler = cases[key];\n if (handler) {\n return typeof handler === \"function\"\n ? handler(matcher[key])\n : handler();\n }\n }\n }\n if (cases.default) return cases.default();\n }\n\n throw new Error(\"Invalid matcher or missing case\");\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(globalThis as any).match = match;\n","import type { Ok } from \"./ok\";\nimport type { ResultDefinition } from \"./result\";\n\n// Hidden discriminant tag for O(1) dispatch in `match`.\n// Symbol.for ensures the same global symbol regardless of bundling.\nconst TAG = Symbol.for(\"@consolidados/results.tag\");\n\n/**\n * Represents a failed result (`Err`) that contains an error value.\n * @template E The type of the error contained in this `Err`. Can be any type (Error, string, enum, etc).\n */\nexport class Err<E> implements ResultDefinition<never, E> {\n /** Hidden tag — read by `match()` for O(1) dispatch. */\n readonly [TAG] = \"Err\" as const;\n private error: E;\n /**\n * Creates a new `Err` instance with the given error value.\n * @param error The error to wrap in the `Err` instance. Can be any type.\n */\n constructor(error: E) {\n // Store error as-is - conversion is handled by factory function\n this.error = error;\n // Object.setPrototypeOf(this, Err.prototype);\n //\n // if (Error.captureStackTrace) {\n // Error.captureStackTrace(this, Err);\n // }\n }\n\n /**\n * Checks if this result is an `Ok`.\n * @returns `false` because this is an `Err`.\n */\n isOk(): this is Ok<never> {\n return false;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `true` because this is an `Err`.\n */\n isErr(): this is Err<E> {\n return true;\n }\n\n /**\n * Retrieves the value contained in this result. Since this is an `Err`, an error is thrown.\n * @throws An error because `unwrap` is called on an `Err`.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on an Err value\");\n }\n\n /**\n * Maps the value (if any). Since this is an `Err`, the mapping function is ignored, and the original `Err` is returned.\n * @template U The type of the value (ignored for `Err`).\n * @param _fn The mapping function for values (not used).\n * @returns The original `Err` instance.\n */\n map<U>(_fn: (value: never) => U): ResultDefinition<never, E> {\n return this as unknown as ResultDefinition<never, E>;\n }\n\n /**\n * Maps the error value using a transformation function and returns a new `Result` with the transformed error.\n * @template U The type of the transformed error. Can be any type.\n * @param fn The transformation function to apply to the error value.\n * @returns A new `Err` containing the transformed error.\n */\n mapErr<U>(fn: (err: E) => U): ResultDefinition<never, U> {\n return new Err<U>(fn(this.error)) as unknown as ResultDefinition<never, U>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value (which does not exist) of this `Err`.\n * @template U The type of the value in the resulting `Result`.\n * @template F The type of the error in the resulting `Result`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The original `Err` instance cast to the new error type.\n */\n flatMap<U, F = E>(\n _fn: (value: never) => ResultDefinition<U, F>,\n ): ResultDefinition<U, E> {\n return this as unknown as ResultDefinition<U, E>;\n }\n\n /**\n * Retrieves the error value contained in this `Err`.\n * @returns The error value contained in this `Err`.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Returns the inner error. After an `isErr()` type guard, TypeScript narrows the return type to `E`.\n * Without a type guard, returns `T | E` (use `isOk()` or `isErr()` for type narrowing).\n * @returns The error value contained in this `Err`.\n */\n value(): E {\n return this.error;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise returns the provided default value.\n * @template U The type of the default value.\n * @param defaultValue The value to return since this is an `Err`.\n * @returns The provided default value.\n */\n unwrapOr<U>(defaultValue: U): U {\n return defaultValue;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise computes and returns the result of the provided function.\n * @template U The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The result of calling the provided function with the error.\n */\n unwrapOrElse<U>(fn: (error: E) => U): U {\n return fn(this.error);\n }\n\n /**\n * Returns this `Err` if it is `Err`, otherwise returns the result of the provided function.\n * @template T The type of the alternative success value.\n * @template F The type of the alternative error.\n * @param fn The function to compute the alternative result.\n * @returns The result of calling the provided function with the error.\n */\n orElse<T, F>(\n fn: (error: E) => ResultDefinition<T, F>,\n ): ResultDefinition<T, F> {\n return fn(this.error);\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return None();\n }\n}\n","import type { ResultDefinition } from \"./result\";\nimport type { Err } from \"./err\";\n\n// Hidden discriminant tag for O(1) dispatch in `match`.\n// Symbol.for ensures the same global symbol regardless of bundling.\nconst TAG = Symbol.for(\"@consolidados/results.tag\");\n\n/**\n * Represents a successful result (`Ok`) that contains a value.\n * @template T The type of the value contained in this `Ok`.\n */\nexport class Ok<T> implements ResultDefinition<T, never> {\n /** Hidden tag — read by `match()` for O(1) dispatch. Symbol-keyed so it\n * doesn't appear in `for...in`, `Object.keys`, or `JSON.stringify`. */\n readonly [TAG] = \"Ok\" as const;\n\n /**\n * Creates a new `Ok` instance with the given value.\n * @param _value The value to wrap in the `Ok` instance.\n */\n constructor(private _value: T) {}\n /**\n * Checks if this result is an `Ok`.\n * @returns `true` because this is an `Ok`.\n */\n isOk(): this is Ok<T> {\n return true;\n }\n\n /**\n * Checks if this result is an `Err`.\n * @returns `false` because this is an `Ok`.\n */\n isErr(): this is Err<never> {\n return false;\n }\n\n /**\n * Retrieves the value contained in this `Ok`.\n * @returns The value contained in this `Ok`.\n */\n unwrap(): T {\n return this._value;\n }\n\n /**\n * Returns the inner value. After an `isOk()` type guard, TypeScript narrows the return type to `T`.\n * Without a type guard, returns `T | E` (use `isOk()` or `isErr()` for type narrowing).\n * @returns The value contained in this `Ok`.\n */\n value(): T {\n return this._value;\n }\n\n /**\n * Applies a transformation function to the value contained in this `Ok` and returns a new `Result` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Ok` containing the transformed value.\n */\n map<U>(fn: (value: T) => U): ResultDefinition<U, never> {\n return new Ok(fn(this._value)) as unknown as ResultDefinition<U, never>;\n }\n\n /**\n * Applies a transformation function that returns a `Result` to the value contained in this `Ok`.\n * @template U The type of the value in the resulting `Result`.\n * @template E The type of the error in the resulting `Result`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U, E = never>(\n fn: (value: T) => ResultDefinition<U, E>,\n ): ResultDefinition<U, E> {\n return fn(this._value);\n }\n\n /**\n * Maps the error value (if any). Since this is an `Ok`, the error mapping function is ignored, and the original `Ok` is returned.\n * @template U The type of the error (ignored for `Ok`). Can be any type.\n * @param _fn The mapping function for errors (not used).\n * @returns The original `Ok` instance.\n */\n mapErr<U>(_fn: (err: never) => U): ResultDefinition<T, U> {\n return this as unknown as ResultDefinition<T, U>;\n }\n\n /**\n * Retrieves the error contained in this result. Since this is an `Ok`, an error is thrown.\n * @throws An error because `unwrapErr` is called on an `Ok`.\n */\n unwrapErr(): never {\n throw new Error(\"Called unwrapErr on an Ok value\");\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise returns the provided default value.\n * @template U The type of the default value.\n * @param defaultValue The value to return if this is an `Err`.\n * @returns The value contained in this `Ok`.\n */\n unwrapOr<U>(defaultValue: U): T {\n return this._value;\n }\n\n /**\n * Returns the contained value if `Ok`, otherwise computes and returns the result of the provided function.\n * @template U The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The value contained in this `Ok`.\n */\n unwrapOrElse<U>(fn: (error: never) => U): T {\n return this._value;\n }\n\n /**\n * Returns this `Ok` if it is `Ok`, otherwise returns the result of the provided function.\n * @template F The type of the alternative error.\n * @param fn The function to compute the alternative result.\n * @returns The original `Ok` instance.\n */\n orElse<F>(fn: (error: never) => ResultDefinition<T, F>): ResultDefinition<T, F> {\n return this as unknown as ResultDefinition<T, F>;\n }\n\n /**\n * Converts `Result` type to `Option` type.\n * @returns `Some` if the result is `Ok`, `None` if the result is `Err`.\n */\n ok() {\n return Some(this._value);\n }\n}\n","import {\n Err as ErrType,\n Ok as OkType,\n type Result,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Ok` instance, representing a successful result.\n * @template T The type of the value contained in the `Ok`.\n * @param value The value to wrap in the `Ok` instance.\n * @returns An `Ok` instance containing the given value.\n * @example\n * const result = Ok(42);\n * console.log(result.isOk()); // true\n * console.log(result.unwrap()); // 42\n */\nfunction Ok<T>(value: T): OkType<T> {\n return new OkType(value);\n}\n\n/**\n * Creates an Err - strings are converted to Error, everything else preserved\n */\nfunction Err<E>(error: E): ErrType<E> {\n return new ErrType(error);\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(globalThis as any).Ok = Ok;\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n(globalThis as any).Err = Err;\n\nexport { Err, Ok, Result, ErrType, OkType };\n","import type { None as NoneType } from \"./none\";\nimport type { Option } from \"./option\";\nimport { None } from \"../../option\";\nimport { Ok } from \"@/result\";\n\n// Hidden discriminant tag for O(1) dispatch in `match`.\n// Symbol.for ensures the same global symbol regardless of bundling.\nconst TAG = Symbol.for(\"@consolidados/results.tag\");\n\n/**\n * Represents a `Some` option, which holds a value.\n * @template T The type of the value held by this `Some` instance.\n */\nexport class Some<T> {\n /** Hidden tag — read by `match()` for O(1) dispatch. */\n readonly [TAG] = \"Some\" as const;\n\n /**\n * Creates a new `Some` option with the given value.\n * @param _value The value to be wrapped in the `Some` option.\n */\n constructor(private _value: T) { }\n\n /**\n * Checks if this option is a `Some`.\n * @returns `true` if this option is a `Some`, otherwise `false`.\n */\n isSome(): this is Some<T> {\n return true;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `false` because this is a `Some`.\n */\n isNone(): this is NoneType {\n return false;\n }\n\n /**\n * Unwraps the value held by this `Some` option.\n * @returns The value held by this `Some` option.\n */\n unwrap(): T {\n return this._value;\n }\n\n /**\n * Returns the inner value. After an `isSome()` type guard, TypeScript narrows the return type to `T`.\n * Without a type guard, returns `T | undefined` (use `isSome()` or `isNone()` for type narrowing).\n * @returns The value held by this `Some` option.\n */\n value(): T {\n return this._value;\n }\n\n /**\n * Applies a transformation function to the value held by this `Some` option and returns a new `Option` with the transformed value.\n * @template U The type of the transformed value.\n * @param fn The transformation function to apply to the value.\n * @returns A new `Some` option containing the transformed value.\n */\n map<U>(fn: (value: T) => U): Option<U> {\n return new Some(fn(this._value));\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value held by this `Some` option.\n * @template U The type of the value in the resulting `Option`.\n * @param fn The transformation function to apply to the value.\n * @returns The result of applying the transformation function.\n */\n flatMap<U>(fn: (value: T) => Option<U>): Option<U> {\n return fn(this._value);\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the default value provided.\n * @param _ A default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOr(_: T): T {\n return this._value;\n }\n\n /**\n * Returns the value held by this `Some` option, ignoring the function provided.\n * @template U The type of the default value.\n * @param _fn A function to compute the default value (ignored in this implementation).\n * @returns The value held by this `Some` option.\n */\n unwrapOrElse<U>(_fn: () => U): T {\n return this._value;\n }\n\n /**\n * Converts this `Option` to a `Result`, using the provided error value if this is `None`.\n * @template E The type of the error.\n * @param _error The error value to use if this is `None` (ignored since this is `Some`).\n * @returns An `Ok` result containing the value from this `Some`.\n */\n okOr<E>(_error: E) {\n return Ok(this._value);\n }\n\n /**\n * Filters this `Option` based on a predicate function.\n * @param predicate The function to test the value.\n * @returns This `Some` if the predicate returns true, otherwise `None`.\n */\n filter(predicate: (value: T) => boolean): Option<T> {\n return predicate(this._value) ? this : None();\n }\n}\n","import type { Some } from \"./some\";\nimport type { Option } from \"./option\";\nimport { None as NoneFactory } from \"../../option\";\nimport { Err } from \"@/result\";\n\n// Hidden discriminant tag for O(1) dispatch in `match`.\n// Symbol.for ensures the same global symbol regardless of bundling.\nconst TAG = Symbol.for(\"@consolidados/results.tag\");\n\n/**\n * Represents a `None` option, which holds no value.\n */\nexport class None {\n /** Hidden tag — read by `match()` for O(1) dispatch. */\n readonly [TAG] = \"None\" as const;\n\n /**\n * Checks if this option is a `Some`.\n * @returns `false` because this is a `None`.\n */\n isSome(): this is Some<never> {\n return false;\n }\n\n /**\n * Checks if this option is a `None`.\n * @returns `true` because this is a `None`.\n */\n isNone(): this is None {\n return true;\n }\n\n /**\n * Attempts to unwrap the value from this `None` option.\n * @throws An error because `None` has no value.\n */\n unwrap(): never {\n throw new Error(\"Called unwrap on a None value\");\n }\n\n /**\n * Returns `undefined` for a `None` option. After an `isNone()` type guard, TypeScript narrows the return type to `undefined`.\n * Without a type guard, returns `T | undefined` (use `isSome()` or `isNone()` for type narrowing).\n * Unlike `unwrap()`, this method does not throw an error.\n * @returns `undefined` because this is a `None`.\n */\n value(): undefined {\n return undefined;\n }\n\n /**\n * Applies a transformation function to the value (which does not exist) of this `None` option.\n * @template U The type of the value that would have been returned.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The singleton `None` instance.\n */\n map<U>(_fn: (value: never) => U): Option<U> {\n return NoneFactory();\n }\n\n /**\n * Applies a transformation function that returns an `Option` to the value (which does not exist) of this `None` option.\n * @template U The type of the value in the resulting `Option`.\n * @param _fn The transformation function (ignored in this implementation).\n * @returns The singleton `None` instance.\n */\n flatMap<U>(_fn: (value: never) => Option<U>): Option<U> {\n return NoneFactory();\n }\n\n /**\n * Returns the default value provided, since `None` has no value.\n * @template T The type of the default value.\n * @param defaultValue The value to return.\n * @returns The default value provided.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n /**\n * Computes and returns the default value using the provided function, since `None` has no value.\n * @template T The type of the default value.\n * @param fn The function to compute the default value.\n * @returns The result of calling the provided function.\n */\n unwrapOrElse<T>(fn: () => T): T {\n return fn();\n }\n\n /**\n * Converts this `Option` to a `Result`, using the provided error value since this is `None`.\n * @template E The type of the error.\n * @param error The error value to use.\n * @returns An `Err` result containing the provided error.\n */\n okOr<E>(error: E) {\n return Err(error);\n }\n\n /**\n * Filters this `Option` based on a predicate function.\n * @param _predicate The function to test the value (ignored since this is `None`).\n * @returns `None` since there is no value to filter.\n */\n filter<T>(_predicate: (value: never) => boolean): Option<T> {\n return NoneFactory();\n }\n}\n","import {\n\tSome as SomeType,\n\tNone as NoneType,\n\ttype Option,\n} from \"./__internal__/return-types\";\n\n/**\n * Creates a new `Some` instance, representing an `Option` with a value.\n * @template T The type of the value contained in the `Some`.\n * @param value The value to wrap in the `Some` instance.\n * @returns A `Some` instance containing the given value.\n * @example\n * const option = Some(42);\n * console.log(option.isSome()); // true\n * console.log(option.unwrap()); // 42\n */\nfunction Some<T>(value: T): SomeType<T> {\n\treturn new SomeType(value);\n}\n\nlet NONE_INSTANCE: NoneType | null = null;\n\n/**\n * Returns the singleton `None` instance, representing an `Option` with no value.\n * Uses a singleton pattern to reduce memory allocations.\n * @returns The singleton `None` instance.\n * @example\n * const option = None();\n * console.log(option.isNone()); // true\n * console.log(option.unwrap()); // throws Error: \"Called unwrap on a None value\"\n */\nfunction None(): NoneType {\n\tif (!NONE_INSTANCE) {\n\t\tNONE_INSTANCE = new NoneType();\n\t}\n\treturn NONE_INSTANCE;\n}\n\n(globalThis as any).Some = Some;\n(globalThis as any).None = None;\n\nexport { None, Some, Option };\n"]}
package/dist/index.d.cts CHANGED
@@ -2,4 +2,4 @@ import './types/globals.cjs';
2
2
  export { match } from './helpers/match.cjs';
3
3
  export { None, Some } from './option/option.cjs';
4
4
  export { Err, Ok } from './result/result.cjs';
5
- export { O as Option, R as Result } from './option-B_KKIecf.cjs';
5
+ export { O as Option, R as Result } from './option-CYCiGxtw.cjs';
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ import './types/globals.js';
2
2
  export { match } from './helpers/match.js';
3
3
  export { None, Some } from './option/option.js';
4
4
  export { Err, Ok } from './result/result.js';
5
- export { O as Option, R as Result } from './option-B_KKIecf.js';
5
+ export { O as Option, R as Result } from './option-CYCiGxtw.js';
package/dist/index.js CHANGED
@@ -1,64 +1,49 @@
1
1
  // src/helpers/match.ts
2
+ var TAG = Symbol.for("@consolidados/results.tag");
2
3
  function match(matcher, cases, discriminant) {
3
- if (typeof matcher === "string" || typeof matcher === "number" || typeof matcher === "symbol") {
4
+ const t = typeof matcher;
5
+ if (t === "string" || t === "number" || t === "symbol") {
4
6
  const handler = cases[matcher];
5
- if (handler) {
7
+ if (handler) return handler();
8
+ if (cases.default) return cases.default();
9
+ throw new Error(`No case found for value: ${String(matcher)}`);
10
+ }
11
+ if (matcher !== null && t === "object") {
12
+ const tag = matcher[TAG];
13
+ if (tag !== void 0) {
14
+ const handler = cases[tag];
15
+ if (!handler) throw new Error(`Missing case for ${tag}`);
16
+ if (tag === "Ok" || tag === "Some") return handler(matcher.unwrap());
17
+ if (tag === "Err") return handler(matcher.unwrapErr());
6
18
  return handler();
7
19
  }
8
- if (cases.default) {
9
- return cases.default();
20
+ if (discriminant) {
21
+ const dv = matcher[discriminant];
22
+ const handler = cases[dv];
23
+ if (handler) return handler(matcher);
24
+ if (cases.default) return cases.default(matcher);
25
+ throw new Error(`No case found for discriminant value: ${String(dv)}`);
10
26
  }
11
- throw new Error(`No case found for value: ${String(matcher)}`);
12
- }
13
- if (typeof matcher === "object" && matcher !== null && !discriminant) {
14
- for (const key in cases) {
27
+ for (const key in matcher) {
15
28
  if (key === "default") continue;
16
- if (key in matcher) {
29
+ if (key in cases) {
17
30
  const handler = cases[key];
18
31
  if (handler) {
19
32
  return typeof handler === "function" ? handler(matcher[key]) : handler();
20
33
  }
21
34
  }
22
35
  }
23
- if (cases.default) {
24
- return cases.default();
25
- }
26
- }
27
- if (discriminant && typeof matcher === "object" && matcher !== null) {
28
- const discriminantValue = matcher[discriminant];
29
- const handler = cases[discriminantValue];
30
- if (handler) {
31
- return handler(matcher);
32
- }
33
- if (cases.default) {
34
- return cases.default(matcher);
35
- }
36
- throw new Error(
37
- `No case found for discriminant value: ${String(discriminantValue)}`
38
- );
39
- }
40
- if (typeof matcher === "object" && matcher !== null && "isOk" in matcher && matcher.isOk()) {
41
- if (!cases.Ok) throw new Error("Missing case for Ok");
42
- return cases.Ok(matcher.unwrap());
43
- }
44
- if (typeof matcher === "object" && matcher !== null && "isErr" in matcher && matcher.isErr()) {
45
- if (!cases.Err) throw new Error("Missing case for Err");
46
- return cases.Err(matcher.unwrapErr());
47
- }
48
- if (typeof matcher === "object" && matcher !== null && "isSome" in matcher && matcher.isSome()) {
49
- if (!cases.Some) throw new Error("Missing case for Some");
50
- return cases.Some(matcher.unwrap());
51
- }
52
- if (typeof matcher === "object" && matcher !== null && "isNone" in matcher && matcher.isNone()) {
53
- if (!cases.None) throw new Error("Missing case for None");
54
- return cases.None();
36
+ if (cases.default) return cases.default();
55
37
  }
56
38
  throw new Error("Invalid matcher or missing case");
57
39
  }
58
- global.match = match;
40
+ globalThis.match = match;
59
41
 
60
42
  // src/result/__internal__/return-types/err.ts
43
+ var TAG2 = Symbol.for("@consolidados/results.tag");
61
44
  var Err = class _Err {
45
+ /** Hidden tag — read by `match()` for O(1) dispatch. */
46
+ [TAG2] = "Err";
62
47
  error;
63
48
  /**
64
49
  * Creates a new `Err` instance with the given error value.
@@ -169,6 +154,7 @@ var Err = class _Err {
169
154
  };
170
155
 
171
156
  // src/result/__internal__/return-types/ok.ts
157
+ var TAG3 = Symbol.for("@consolidados/results.tag");
172
158
  var Ok = class _Ok {
173
159
  /**
174
160
  * Creates a new `Ok` instance with the given value.
@@ -177,6 +163,9 @@ var Ok = class _Ok {
177
163
  constructor(_value) {
178
164
  this._value = _value;
179
165
  }
166
+ /** Hidden tag — read by `match()` for O(1) dispatch. Symbol-keyed so it
167
+ * doesn't appear in `for...in`, `Object.keys`, or `JSON.stringify`. */
168
+ [TAG3] = "Ok";
180
169
  /**
181
170
  * Checks if this result is an `Ok`.
182
171
  * @returns `true` because this is an `Ok`.
@@ -284,10 +273,11 @@ function Ok2(value) {
284
273
  function Err2(error) {
285
274
  return new Err(error);
286
275
  }
287
- global.Ok = Ok2;
288
- global.Err = Err2;
276
+ globalThis.Ok = Ok2;
277
+ globalThis.Err = Err2;
289
278
 
290
279
  // src/option/__internal__/return-types/some.ts
280
+ var TAG4 = Symbol.for("@consolidados/results.tag");
291
281
  var Some2 = class _Some {
292
282
  /**
293
283
  * Creates a new `Some` option with the given value.
@@ -296,6 +286,8 @@ var Some2 = class _Some {
296
286
  constructor(_value) {
297
287
  this._value = _value;
298
288
  }
289
+ /** Hidden tag — read by `match()` for O(1) dispatch. */
290
+ [TAG4] = "Some";
299
291
  /**
300
292
  * Checks if this option is a `Some`.
301
293
  * @returns `true` if this option is a `Some`, otherwise `false`.
@@ -380,7 +372,10 @@ var Some2 = class _Some {
380
372
  };
381
373
 
382
374
  // src/option/__internal__/return-types/none.ts
375
+ var TAG5 = Symbol.for("@consolidados/results.tag");
383
376
  var None3 = class {
377
+ /** Hidden tag — read by `match()` for O(1) dispatch. */
378
+ [TAG5] = "None";
384
379
  /**
385
380
  * Checks if this option is a `Some`.
386
381
  * @returns `false` because this is a `None`.
@@ -477,8 +472,8 @@ function None2() {
477
472
  }
478
473
  return NONE_INSTANCE;
479
474
  }
480
- global.Some = Some3;
481
- global.None = None2;
475
+ globalThis.Some = Some3;
476
+ globalThis.None = None2;
482
477
 
483
478
  export { Err2 as Err, None2 as None, Ok2 as Ok, Some3 as Some, match };
484
479
  //# sourceMappingURL=index.js.map