functype 0.48.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,6 +22,7 @@ npx functype --json # JSON output for programmatic use
22
22
 
23
23
  ## Core Principles
24
24
 
25
+ - **Zero Dependencies**: No third-party runtime dependencies — just TypeScript
25
26
  - **Immutability**: All data structures are immutable, promoting predictable and side-effect-free code
26
27
  - **Type Safety**: Leverages TypeScript's type system to ensure compile-time safety
27
28
  - **Composability**: Provides abstractions for building complex programs from simple components
@@ -0,0 +1,54 @@
1
+ //#region src/branded/Brand.d.ts
2
+ type Brand<K extends string, T> = T & {
3
+ readonly __brand: K;
4
+ };
5
+ type Unwrap<T> = T extends Brand<string, infer U> ? U : T;
6
+ type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never;
7
+ /**
8
+ * Brand is a utility for creating nominal typing in TypeScript.
9
+ * It creates phantom types that exist only at compile time.
10
+ * At runtime, the branded value IS the primitive value.
11
+ *
12
+ * @param _brand
13
+ * @param value - The value to brand
14
+ * @returns The value with phantom type brand
15
+ */
16
+ declare function Brand<K extends string, T>(_brand: K, value: T): Brand<K, T>;
17
+ /**
18
+ * Helper to unwrap a branded value to its underlying type
19
+ * Works with both Brand and ValidatedBrand
20
+ * @param branded - The branded value (can be null or undefined)
21
+ * @returns The original value without the brand
22
+ *
23
+ * Note: Also exported as 'unwrap' from 'functype/branded' for convenience
24
+ */
25
+ declare function unwrapBrand<K extends string, T>(branded: Brand<K, T>): T;
26
+ declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null): T | null;
27
+ declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | undefined): T | undefined;
28
+ declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null | undefined): T | null | undefined;
29
+ /**
30
+ * Type guard for checking if a value has a specific brand
31
+ * @param value - The value to check
32
+ * @param _brand - The brand to check for (unused at runtime)
33
+ * @returns True if the value has the specified brand
34
+ *
35
+ * Note: Since brands are phantom types that exist only at compile time,
36
+ * this function can only provide a runtime approximation. It always returns true
37
+ * for non-null values, as we have no way to actually check the brand at runtime.
38
+ * This function is primarily for API consistency and documentation purposes.
39
+ */
40
+ declare function hasBrand<K extends string, T>(value: unknown, _brand: K): value is Brand<K, T>;
41
+ /**
42
+ * Create a branded type constructor for a specific brand
43
+ * @param brand - The brand name
44
+ * @returns A function that brands values with the specified brand
45
+ */
46
+ declare function createBrander<K extends string, T>(brand: K): (value: T) => Brand<K, T>;
47
+ type BrandedString<K extends string> = Brand<K, string>;
48
+ type BrandedNumber<K extends string> = Brand<K, number>;
49
+ type BrandedBoolean<K extends string> = Brand<K, boolean>;
50
+ declare const BrandedString: <K extends string>(brand: K) => (value: string) => BrandedString<K>;
51
+ declare const BrandedNumber: <K extends string>(brand: K) => (value: number) => BrandedNumber<K>;
52
+ declare const BrandedBoolean: <K extends string>(brand: K) => (value: boolean) => BrandedBoolean<K>;
53
+ //#endregion
54
+ export { ExtractBrand as a, hasBrand as c, BrandedString as i, unwrapBrand as l, BrandedBoolean as n, Unwrap as o, BrandedNumber as r, createBrander as s, Brand as t };
@@ -101,4 +101,78 @@ declare function Typeable<Tag extends string, T>({
101
101
  */
102
102
  declare function isTypeable<T>(value: unknown, tag: string): value is T;
103
103
  //#endregion
104
- export { Serializable as a, Foldable as c, isTypeable as i, Type as l, Typeable as n, SerializationMethods as o, TypeableParams as r, Pipe as s, ExtractTag as t };
104
+ //#region src/tuple/Tuple.d.ts
105
+ interface Tuple<T extends Type[]> extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
106
+ readonly [Symbol.toStringTag]: string;
107
+ get<K extends number>(index: K): T[K];
108
+ map<U extends Type[]>(f: (value: T) => U): Tuple<U>;
109
+ flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>;
110
+ toArray(): T;
111
+ length: number;
112
+ [Symbol.iterator](): Iterator<T[number]>;
113
+ toString(): string;
114
+ toValue(): {
115
+ _tag: "Tuple";
116
+ value: T;
117
+ };
118
+ }
119
+ /**
120
+ * Tuple provides a type-safe, fixed-length array with functional operations.
121
+ *
122
+ * @example
123
+ * // Creating tuples
124
+ * const t1 = Tuple([1, "hello", true])
125
+ * const t2 = Tuple.of(1, "hello", true)
126
+ * const pair = Tuple.pair("key", 42)
127
+ *
128
+ * @example
129
+ * // Type-safe access
130
+ * const triple = Tuple.triple("x", 10, true)
131
+ * const first = triple.get(0) // string
132
+ * const second = triple.get(1) // number
133
+ * const third = triple.get(2) // boolean
134
+ *
135
+ * @example
136
+ * // Functional operations
137
+ * const doubled = Tuple([1, 2, 3])
138
+ * .map(arr => arr.map(x => x * 2))
139
+ * .toArray() // [2, 4, 6]
140
+ */
141
+ declare const Tuple: (<T extends Type[]>(values: T) => Tuple<T>) & {
142
+ /**
143
+ * Create a Tuple from multiple arguments
144
+ * @example
145
+ * const t = Tuple.of(1, "hello", true)
146
+ * // TypeScript infers: Tuple<[number, string, boolean]>
147
+ */
148
+ of: <T extends Type[]>(...values: T) => Tuple<T>;
149
+ /**
150
+ * Create a Tuple of size 2 (pair)
151
+ * @example
152
+ * const pair = Tuple.pair("key", 42)
153
+ * // TypeScript infers: Tuple<[string, number]>
154
+ */
155
+ pair: <A extends Type, B extends Type>(first: A, second: B) => Tuple<[A, B]>;
156
+ /**
157
+ * Create a Tuple of size 3 (triple)
158
+ * @example
159
+ * const triple = Tuple.triple("x", 10, true)
160
+ * // TypeScript infers: Tuple<[string, number, boolean]>
161
+ */
162
+ triple: <A extends Type, B extends Type, C extends Type>(first: A, second: B, third: C) => Tuple<[A, B, C]>;
163
+ /**
164
+ * Create an empty Tuple
165
+ * @example
166
+ * const empty = Tuple.empty()
167
+ * // TypeScript infers: Tuple<[]>
168
+ */
169
+ empty: () => Tuple<[]>;
170
+ /**
171
+ * Create a Tuple from an array (alias for constructor)
172
+ * @example
173
+ * const t = Tuple.from([1, 2, 3])
174
+ */
175
+ from: <T extends Type[]>(values: T) => Tuple<T>;
176
+ };
177
+ //#endregion
178
+ export { isTypeable as a, Pipe as c, TypeableParams as i, Foldable as l, ExtractTag as n, Serializable as o, Typeable as r, SerializationMethods as s, Tuple as t, Type as u };
@@ -0,0 +1 @@
1
+ function e(e,t){return Object.assign(e,t)}function t(t,n){return e(t,n)}function n(e){if(e===void 0||typeof e==`symbol`||typeof e==`function`)return;let t=new Set;function n(e){if(e===null)return`null`;switch(typeof e){case`string`:return JSON.stringify(e);case`number`:return isFinite(e)?String(e):`null`;case`boolean`:return String(e);case`bigint`:return`"${e}"`;case`undefined`:case`symbol`:case`function`:return}let r=e;if(t.has(r))return`"[Circular]"`;t.add(r);try{if(`toJSON`in r&&typeof r.toJSON==`function`)return n(r.toJSON());if(Array.isArray(r))return`[${r.map(e=>n(e)??`null`).join(`,`)}]`;let e=Object.keys(r).sort(),t=[];for(let i of e){let e=n(r[i]);e!==void 0&&t.push(`${JSON.stringify(i)}:${e}`)}return`{${t.join(`,`)}}`}finally{t.delete(r)}}try{return n(e)}catch{return}}const r=e=>{let t={[Symbol.toStringTag]:`Tuple`,_tag:`Tuple`,map:t=>i(t(e)),flatMap:t=>t(e),get:t=>e[t],toArray:()=>e,length:e.length,[Symbol.iterator](){let t=0;return{next:()=>t<e.length?{value:e[t++],done:!1}:{value:void 0,done:!0}}},fold:(t,n)=>e.length===0?t():n(e[0]),foldLeft:t=>n=>e.reduce(n,t),foldRight:t=>n=>e.reduceRight((e,t)=>n(t,e),t),pipe:e=>e(t),serialize:()=>({toJSON:()=>JSON.stringify({_tag:`Tuple`,value:e}),toYAML:()=>`_tag: Tuple\nvalue: ${n(e)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`Tuple`,value:e})).toString(`base64`)}),toValue:()=>({_tag:`Tuple`,value:e}),toString:()=>`Tuple(${e.map(e=>String(e)).join(`, `)})`};return t},i=t(e=>r(e),{of:(...e)=>r(e),pair:(e,t)=>r([e,t]),triple:(e,t,n)=>r([e,t,n]),empty:()=>r([]),from:e=>r(e)});export{e as i,n,t as r,i as t};
@@ -1,54 +1,2 @@
1
- //#region src/branded/Brand.d.ts
2
- type Brand<K extends string, T> = T & {
3
- readonly __brand: K;
4
- };
5
- type Unwrap<T> = T extends Brand<string, infer U> ? U : T;
6
- type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never;
7
- /**
8
- * Brand is a utility for creating nominal typing in TypeScript.
9
- * It creates phantom types that exist only at compile time.
10
- * At runtime, the branded value IS the primitive value.
11
- *
12
- * @param _brand
13
- * @param value - The value to brand
14
- * @returns The value with phantom type brand
15
- */
16
- declare function Brand<K extends string, T>(_brand: K, value: T): Brand<K, T>;
17
- /**
18
- * Helper to unwrap a branded value to its underlying type
19
- * Works with both Brand and ValidatedBrand
20
- * @param branded - The branded value (can be null or undefined)
21
- * @returns The original value without the brand
22
- *
23
- * Note: Also exported as 'unwrap' from 'functype/branded' for convenience
24
- */
25
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T>): T;
26
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null): T | null;
27
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | undefined): T | undefined;
28
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null | undefined): T | null | undefined;
29
- /**
30
- * Type guard for checking if a value has a specific brand
31
- * @param value - The value to check
32
- * @param _brand - The brand to check for (unused at runtime)
33
- * @returns True if the value has the specified brand
34
- *
35
- * Note: Since brands are phantom types that exist only at compile time,
36
- * this function can only provide a runtime approximation. It always returns true
37
- * for non-null values, as we have no way to actually check the brand at runtime.
38
- * This function is primarily for API consistency and documentation purposes.
39
- */
40
- declare function hasBrand<K extends string, T>(value: unknown, _brand: K): value is Brand<K, T>;
41
- /**
42
- * Create a branded type constructor for a specific brand
43
- * @param brand - The brand name
44
- * @returns A function that brands values with the specified brand
45
- */
46
- declare function createBrander<K extends string, T>(brand: K): (value: T) => Brand<K, T>;
47
- type BrandedString<K extends string> = Brand<K, string>;
48
- type BrandedNumber<K extends string> = Brand<K, number>;
49
- type BrandedBoolean<K extends string> = Brand<K, boolean>;
50
- declare const BrandedString: <K extends string>(brand: K) => (value: string) => BrandedString<K>;
51
- declare const BrandedNumber: <K extends string>(brand: K) => (value: number) => BrandedNumber<K>;
52
- declare const BrandedBoolean: <K extends string>(brand: K) => (value: boolean) => BrandedBoolean<K>;
53
- //#endregion
1
+ import { a as ExtractBrand, c as hasBrand, i as BrandedString, l as unwrapBrand, n as BrandedBoolean, o as Unwrap, r as BrandedNumber, s as createBrander, t as Brand } from "../Brand-BJIRbUKB.js";
54
2
  export { Brand, BrandedBoolean, BrandedNumber, BrandedString, ExtractBrand, Unwrap, createBrander, hasBrand, unwrapBrand as unwrap, unwrapBrand };
@@ -1 +1 @@
1
- import{a as e,i as t,n,r,t as i}from"../full-interfaces-DXVOawTK.js";export{n as CATEGORIES,i as FULL_INTERFACES,r as INTERFACES,t as TYPES,e as VERSION};
1
+ import{a as e,i as t,n,r,t as i}from"../full-interfaces-DVRjnPWW.js";export{n as CATEGORIES,i as FULL_INTERFACES,r as INTERFACES,t as TYPES,e as VERSION};
package/dist/cli/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{P as e}from"../Valuable-CXh58HBk.js";import{Option as t}from"../option/index.js";import{List as n}from"../list/index.js";import{a as r,i,n as a,r as o,t as s}from"../full-interfaces-DXVOawTK.js";const c=()=>{let e=n([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return n(Object.entries(a)).foldLeft(e)((e,[r,a])=>{let o=e.add(r.toUpperCase());return n(a).foldLeft(o)((e,n)=>t(i[n]).fold(()=>e,t=>{let r=t.interfaces.length>0?` [${t.interfaces.join(`, `)}]`:``;return e.add(` ${n}${r}`).add(` ${t.description}`)})).add(``)}).concat(n([`Use: npx functype <Type> for details`,`Use: npx functype interfaces for interface reference`])).toArray().join(`
3
- `)},l=(e,r)=>{let i=r.interfaces.length>0?` [${r.interfaces.join(`, `)}]`:``,a=n([`create`,`transform`,`extract`,`check`,`other`]),o=n([`${e}<T>${i}`,``,r.description,``]);return a.foldLeft(o)((e,i)=>t(r.methods[i]).filter(e=>e.length>0).fold(()=>e,t=>{let r=e.add(i.toUpperCase());return n(t).foldLeft(r)((e,t)=>e.add(` ${t}`)).add(``)})).toArray().join(`
2
+ import{Ct as e,W as t,ht as n}from"../src-ByDeJzWj.js";import{a as r,i,n as a,r as o,t as s}from"../full-interfaces-DVRjnPWW.js";const c=()=>{let t=n([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return n(Object.entries(a)).foldLeft(t)((t,[r,a])=>{let o=t.add(r.toUpperCase());return n(a).foldLeft(o)((t,n)=>e(i[n]).fold(()=>t,e=>{let r=e.interfaces.length>0?` [${e.interfaces.join(`, `)}]`:``;return t.add(` ${n}${r}`).add(` ${e.description}`)})).add(``)}).concat(n([`Use: npx functype <Type> for details`,`Use: npx functype interfaces for interface reference`])).toArray().join(`
3
+ `)},l=(t,r)=>{let i=r.interfaces.length>0?` [${r.interfaces.join(`, `)}]`:``,a=n([`create`,`transform`,`extract`,`check`,`other`]),o=n([`${t}<T>${i}`,``,r.description,``]);return a.foldLeft(o)((t,i)=>e(r.methods[i]).filter(e=>e.length>0).fold(()=>t,e=>{let r=t.add(i.toUpperCase());return n(e).foldLeft(r)((e,t)=>e.add(` ${t}`)).add(``)})).toArray().join(`
4
4
  `).trimEnd()},u=()=>{let e=n([`INTERFACES`,``]);return n(Object.entries(o)).foldLeft(e)((e,[t,r])=>{let i=r.extends?` extends ${r.extends}`:``,a=e.add(`${t}<A>${i}`).add(` ${r.description}`);return n(r.methods).foldLeft(a)((e,t)=>e.add(` ${t}`)).add(``)}).toArray().join(`
5
- `).trimEnd()},d=e=>JSON.stringify(e,null,2),f=()=>({version:r,categories:a,types:i}),p=e=>t(i[e]).map(t=>({name:e,data:t})).or(n(Object.entries(i)).find(([t])=>t.toLowerCase()===e.toLowerCase()).map(([e,t])=>({name:e,data:t}))).orUndefined(),m=()=>Object.keys(i),h=()=>o,g=e=>{let t=n(e.slice(2));return{flags:{json:t.contains(`--json`),full:t.contains(`--full`),help:t.exists(e=>e===`--help`||e===`-h`)},args:t.filter(e=>!e.startsWith(`--`)&&e!==`-h`)}},_=e=>t(s[e]).or(n(Object.entries(s)).find(([t])=>t.toLowerCase()===e.toLowerCase()).map(([,e])=>e)),v=()=>{let e=n([`FULL INTERFACE DEFINITIONS`,`=`.repeat(60),``]);return n(Object.entries(s)).foldLeft(e)((e,[t,r])=>e.concat(n([`// ${t}`,r,``,`-`.repeat(60),``]))).toArray().join(`
5
+ `).trimEnd()},d=e=>JSON.stringify(e,null,2),f=()=>({version:r,categories:a,types:i}),p=t=>e(i[t]).map(e=>({name:t,data:e})).or(n(Object.entries(i)).find(([e])=>e.toLowerCase()===t.toLowerCase()).map(([e,t])=>({name:e,data:t}))).orUndefined(),m=()=>Object.keys(i),h=()=>o,g=e=>{let t=n(e.slice(2));return{flags:{json:t.contains(`--json`),full:t.contains(`--full`),help:t.exists(e=>e===`--help`||e===`-h`)},args:t.filter(e=>!e.startsWith(`--`)&&e!==`-h`)}},_=t=>e(s[t]).or(n(Object.entries(s)).find(([e])=>e.toLowerCase()===t.toLowerCase()).map(([,e])=>e)),v=()=>{let e=n([`FULL INTERFACE DEFINITIONS`,`=`.repeat(60),``]);return n(Object.entries(s)).foldLeft(e)((e,[t,r])=>e.concat(n([`// ${t}`,r,``,`-`.repeat(60),``]))).toArray().join(`
6
6
  `).trimEnd()},y=()=>{console.log(`functype - API documentation for LLMs
7
7
 
8
8
  USAGE
@@ -24,4 +24,4 @@ EXAMPLES
24
24
  npx functype Option --json # Option as JSON
25
25
  npx functype Option --full # Full TypeScript interface
26
26
  npx functype --full # All full interfaces (large output!)
27
- `)},b=e=>{console.error(`Unknown type: ${e}`),console.error(``),console.error(`Available types: ${m().join(`, `)}`),console.error(``),console.error(`Use: npx functype interfaces - for interface reference`),process.exit(1)},x=e=>console.log(e),S=(e,n)=>t(p(e)).fold(()=>b(e),e=>{n.full?_(e.name).fold(()=>x(n.json?d({[e.name]:e.data}):l(e.name,e.data)),t=>x(n.json?d({[e.name]:{...e.data,fullInterface:t}}):t)):x(n.json?d({[e.name]:e.data}):l(e.name,e.data))});(()=>{let{flags:t,args:n}=g(process.argv);e(!0).when(()=>t.help,()=>y()).when(()=>n.isEmpty,()=>t.full?x(t.json?d(s):v()):x(t.json?d(f()):c())).when(()=>n.headOption.contains(`interfaces`),()=>x(t.json?d(h()):u())).default(()=>n.headOption.fold(()=>x(t.json?d(f()):c()),e=>S(e,t)))})();
27
+ `)},b=e=>{console.error(`Unknown type: ${e}`),console.error(``),console.error(`Available types: ${m().join(`, `)}`),console.error(``),console.error(`Use: npx functype interfaces - for interface reference`),process.exit(1)},x=e=>console.log(e),S=(t,n)=>e(p(t)).fold(()=>b(t),e=>{n.full?_(e.name).fold(()=>x(n.json?d({[e.name]:e.data}):l(e.name,e.data)),t=>x(n.json?d({[e.name]:{...e.data,fullInterface:t}}):t)):x(n.json?d({[e.name]:e.data}):l(e.name,e.data))});(()=>{let{flags:e,args:n}=g(process.argv);t(!0).when(()=>e.help,()=>y()).when(()=>n.isEmpty,()=>e.full?x(e.json?d(s):v()):x(e.json?d(f()):c())).when(()=>n.headOption.contains(`interfaces`),()=>x(e.json?d(h()):u())).default(()=>n.headOption.fold(()=>x(e.json?d(f()):c()),t=>S(t,e)))})();
@@ -1,184 +1,2 @@
1
- import { mn as Doable, nn as Reshapeable, pn as DoResult } from "../Functype-rgysbeU6.js";
2
- import { Try } from "../try/index.js";
3
- import { Option } from "../option/index.js";
4
- import { List } from "../list/index.js";
5
- import { Either } from "../either/index.js";
6
-
7
- //#region src/do/index.d.ts
8
- type OptionLike = {
9
- _tag: "Some" | "None";
10
- isSome(): boolean;
11
- get(): unknown;
12
- };
13
- type EitherLike = {
14
- _tag: "Left" | "Right";
15
- isLeft(): boolean;
16
- isRight(): boolean;
17
- value: unknown;
18
- };
19
- type ListLike = {
20
- _tag: "List";
21
- toArray(): unknown[];
22
- };
23
- type TryLike = {
24
- _tag: "Success" | "Failure";
25
- isSuccess(): boolean;
26
- get(): unknown;
27
- };
28
- /**
29
- * Executes a generator-based monadic comprehension
30
- * Returns the same monad type as the first yielded monad (Scala semantics)
31
- *
32
- * - Option comprehensions return Option (None on short-circuit)
33
- * - Either comprehensions return Either (Left with error on short-circuit)
34
- * - List comprehensions return List (empty or cartesian product)
35
- * - Try comprehensions return Try (Failure with error on short-circuit)
36
- *
37
- * Type Inference Notes:
38
- * - TypeScript infers the correct return type for homogeneous comprehensions
39
- * - For mixed monad types, TypeScript returns a union type
40
- * - Use DoTyped<T> or type assertions for mixed scenarios
41
- *
42
- * @example
43
- * ```typescript
44
- * // Option comprehension returns Option:
45
- * const result = Do(function* () {
46
- * const x = yield* $(Option(5));
47
- * const y = yield* $(Option(10));
48
- * return x + y;
49
- * });
50
- * // result: Option(15)
51
- *
52
- * // Either comprehension returns Either:
53
- * const result = Do(function* () {
54
- * const x = yield* $(Right(5));
55
- * const y = yield* $(Left("error"));
56
- * return x + y;
57
- * });
58
- * // result: Left("error") - error is preserved
59
- *
60
- * // List comprehension returns List with cartesian product:
61
- * const result = Do(function* () {
62
- * const x = yield* $(List([1, 2]));
63
- * const y = yield* $(List([3, 4]));
64
- * return x + y;
65
- * });
66
- * // result: List([4, 5, 5, 6])
67
- *
68
- * // Mixed types - use type assertion or DoTyped:
69
- * const result = Do(function* () {
70
- * const x = yield* $(Option(5));
71
- * const y = yield* $(Right<string, number>(10));
72
- * return x + y;
73
- * }) as Option<number>;
74
- * // result: Option(15)
75
- * ```
76
- *
77
- * @param gen - Generator function that yields monads and returns a result
78
- * @returns The same monad type as the first yield
79
- */
80
- declare function Do<T>(gen: () => Generator<OptionLike, T, unknown>): Option<T>;
81
- declare function Do<L, R>(gen: () => Generator<EitherLike, R, unknown>): Either<L, R>;
82
- declare function Do<T>(gen: () => Generator<ListLike, T, unknown>): List<T>;
83
- declare function Do<T>(gen: () => Generator<TryLike, T, unknown>): Try<T>;
84
- declare function Do<T>(gen: () => Generator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Reshapeable<T>;
85
- declare function Do<T>(gen: () => Generator<unknown, T, unknown>): unknown;
86
- /**
87
- * Executes an async generator-based monadic comprehension
88
- * Returns the same monad type as the first yielded monad
89
- *
90
- * @example
91
- * ```typescript
92
- * const result = await DoAsync(async function* () {
93
- * const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
94
- * const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
95
- * return { user, profile };
96
- * });
97
- * // result type matches first yield
98
- * ```
99
- *
100
- * @param gen - Async generator function that yields monads/promises and returns a result
101
- * @returns Promise of the same monad type as first yield
102
- */
103
- declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike, T, unknown>): Promise<Option<T>>;
104
- declare function DoAsync<L, R>(gen: () => AsyncGenerator<EitherLike, R, unknown>): Promise<Either<L, R>>;
105
- declare function DoAsync<T>(gen: () => AsyncGenerator<ListLike, T, unknown>): Promise<List<T>>;
106
- declare function DoAsync<T>(gen: () => AsyncGenerator<TryLike, T, unknown>): Promise<Try<T>>;
107
- declare function DoAsync<T>(gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>): Promise<Reshapeable<T>>;
108
- declare function DoAsync<T>(gen: () => AsyncGenerator<unknown, T, unknown>): Promise<unknown>;
109
- /**
110
- * Helper function to check if a value implements the Doable interface
111
- * @param value - Value to check
112
- * @returns True if the value implements Doable
113
- */
114
- declare function isDoCapable<T>(value: unknown): value is Doable<T>;
115
- /**
116
- * Manually unwrap a monad using the Doable interface
117
- * Useful for testing or when you need to unwrap outside of a Do-comprehension
118
- *
119
- * @param monad - Monad to unwrap
120
- * @returns The unwrapped value
121
- * @throws Error if the monad cannot be unwrapped
122
- */
123
- declare function unwrap<T>(monad: Doable<T>): T;
124
- /**
125
- * Type helper for Do-notation generators.
126
- * Provides better type hints in IDEs.
127
- *
128
- * @example
129
- * ```typescript
130
- * const result = Do(function* (): DoGenerator<number> {
131
- * const x = yield* $(List([1, 2])) // x is still unknown but return type is clear
132
- * const y = yield* $(List([3, 4]))
133
- * return x + y
134
- * })
135
- * ```
136
- */
137
- type DoGenerator<T, TYield = unknown> = Generator<TYield, T, unknown>;
138
- /**
139
- * Extracts values from monads in Do-notation with type inference.
140
- * The '$' symbol is the universal extraction operator in functional programming.
141
- *
142
- * @example
143
- * ```typescript
144
- * const result = Do(function* () {
145
- * const x = yield* $(Option(5)) // x: number
146
- * const y = yield* $(List([1, 2, 3])) // y: number (for cartesian product)
147
- * const name = yield* $(Right("Alice")) // name: string
148
- * return `${name}: ${x + y}`
149
- * })
150
- * ```
151
- *
152
- * @param monad - Any monad that can be unwrapped (Option, Either, List, Try, etc.)
153
- * @returns A generator that yields the monad and returns its extracted value
154
- */
155
- declare function $<T>(monad: Option<T>): Generator<Option<T>, T, T>;
156
- declare function $<L, R>(monad: Either<L, R>): Generator<Either<L, R>, R, R>;
157
- declare function $<T>(monad: List<T>): Generator<List<T>, T, T>;
158
- declare function $<T>(monad: Try<T>): Generator<Try<T>, T, T>;
159
- declare function $<T>(monad: Doable<T>): Generator<Doable<T>, T, T>;
160
- declare function $<M>(monad: M): Generator<M, InferYieldType<M>, InferYieldType<M>>;
161
- type InferYieldType<M> = M extends {
162
- isSome(): boolean;
163
- get(): infer T;
164
- } ? T : M extends {
165
- isRight(): boolean;
166
- value: infer R;
167
- } ? R : M extends {
168
- toArray(): (infer T)[];
169
- } ? T : M extends {
170
- isSuccess(): boolean;
171
- get(): infer T;
172
- } ? T : M extends Doable<infer T> ? T : unknown;
173
- declare const NoneError: (message?: string) => Error;
174
- interface LeftErrorType<L> extends Error {
175
- value: L;
176
- }
177
- declare const LeftError: <L>(value: L, message?: string) => LeftErrorType<L>;
178
- declare const EmptyListError: (message?: string) => Error;
179
- interface FailureErrorType extends Error {
180
- cause: Error;
181
- }
182
- declare const FailureError: (cause: Error, message?: string) => FailureErrorType;
183
- //#endregion
184
- export { $, Do, DoAsync, DoGenerator, type DoResult, type Doable, EmptyListError, FailureError, FailureErrorType, LeftError, LeftErrorType, NoneError, isDoCapable, unwrap };
1
+ import { Gn as Doable, Wn as DoResult, a as EmptyListError, c as LeftError, d as isDoCapable, f as unwrap, i as DoGenerator, l as LeftErrorType, n as Do, o as FailureError, r as DoAsync, s as FailureErrorType, t as $, u as NoneError } from "../index-OdnROQtM.js";
2
+ export { $, Do, DoAsync, DoGenerator, DoResult, Doable, EmptyListError, FailureError, FailureErrorType, LeftError, LeftErrorType, NoneError, isDoCapable, unwrap };
package/dist/do/index.js CHANGED
@@ -1 +1 @@
1
- import{Option as e}from"../option/index.js";import{Try as t}from"../try/index.js";import{List as n}from"../list/index.js";import{Left as r,Right as i}from"../either/index.js";function a(e){if(!e||typeof e!=`object`||!(`_tag`in e))return`unknown`;switch(e._tag){case`Some`:case`None`:return`Option`;case`Left`:case`Right`:return`Either`;case`List`:return`List`;case`Success`:case`Failure`:return`Try`;default:return`unknown`}}const o={Option:{of:t=>e(t),empty:()=>e.none()},Either:{of:e=>i(e),empty:e=>r(e)},List:{of:e=>n([e]),empty:()=>n([])},Try:{of:e=>t(()=>e),empty:e=>t(()=>{throw e??Error(`Try failed`)})}};function s(e){let t=e(),r=null,i;function s(l){let u=t.next(l);if(u.done)return i?i.of(u.value):n([u.value]);let d=u.value;if(typeof d!=`object`||!d)throw Error(`Do-notation error: All yielded values must be monadic. Use yield* $(Option(value)), yield* $(Right(value)), etc. Raw values should be assigned directly without yielding.`);if(!r&&`_tag`in d&&(r=a(d),r!==`unknown`&&r in o&&(i=o[r]),r===`List`))return c(e);if(`doUnwrap`in d){let e=d.doUnwrap();if(!e.ok){if(!i)return n([]);if(!e.empty&&`error`in e){if(r===`Either`)return i.empty(e.error);if(r===`Try`)return i.empty(e.error instanceof Error?e.error:Error(String(e.error)))}return i.empty()}return s(e.value)}throw Error(`Do-notation error: All yielded values must be monadic. Use yield* $(Option(value)), yield* $(Right(value)), etc. Raw values should be assigned directly without yielding.`)}return s()}function c(e){function t(e){if(typeof e!=`object`||!e||!(`doUnwrap`in e))return[e];let t=e;if(`toArray`in t){let e=t.toArray();return e.length===0?[]:e}let n=t.doUnwrap();return n.ok?[n.value]:[]}function r(n){let i=e(),a=[],o=[],s=0;function c(e){let l=i.next(e);if(l.done){a.push(l.value);return}if(s<n.length){let e=n[s];o.push(e),s++,c(e);return}let u=t(l.value);if(u.length!==0)if(u.length>1){let e=u.flatMap(e=>r([...o,e]));a.push(...e)}else o.push(u[0]),s++,c(u[0])}return c(void 0),a}return n(r([]))}async function l(e){let t=e(),r=null,i;async function s(e){let c=await t.next(e);if(c.done)return i?i.of(c.value):n([c.value]);let l=await Promise.resolve(c.value);if(typeof l!=`object`||!l)return s(l);if(!r&&`_tag`in l&&(r=a(l),r!==`unknown`&&r in o&&(i=o[r])),`doUnwrap`in l){let e=l.doUnwrap();if(!e.ok){if(!i)return n([]);if(!e.empty&&`error`in e){if(r===`Either`)return i.empty(e.error);if(r===`Try`)return i.empty(e.error instanceof Error?e.error:Error(String(e.error)))}return i.empty()}return s(e.value)}return s(l)}return s()}function u(e){return typeof e==`object`&&!!e&&`doUnwrap`in e&&typeof e.doUnwrap==`function`}function d(e){let t=e.doUnwrap();if(t.ok)return t.value;throw`error`in t?t.error:Error(`Cannot unwrap empty monad`)}function*f(e){return yield e}const p=(e=`Cannot unwrap None in Do-notation`)=>{let t=Error(e),n=Object.create(Error.prototype);return n.message=t.message,n.stack=t.stack,n.name=`NoneError`,n},m=(e,t=`Cannot unwrap Left in Do-notation`)=>{let n=Error(t),r=Object.create(Error.prototype);return r.message=n.message,r.stack=n.stack,r.name=`LeftError`,r.value=e,r},h=(e=`Cannot unwrap empty List in Do-notation`)=>{let t=Error(e),n=Object.create(Error.prototype);return n.message=t.message,n.stack=t.stack,n.name=`EmptyListError`,n},g=(e,t=`Cannot unwrap Failure in Do-notation`)=>{let n=Error(t),r=Object.create(Error.prototype);return r.message=n.message,r.stack=n.stack,r.name=`FailureError`,r.cause=e,r};export{f as $,s as Do,l as DoAsync,h as EmptyListError,g as FailureError,m as LeftError,p as NoneError,u as isDoCapable,d as unwrap};
1
+ import{A as e,D as t,F as n,M as r,N as i,O as a,P as o,j as s,k as c}from"../src-ByDeJzWj.js";export{t as $,a as Do,c as DoAsync,e as EmptyListError,s as FailureError,r as LeftError,i as NoneError,o as isDoCapable,n as unwrap};
@@ -1,188 +1,2 @@
1
- import { an as AsyncMonad, dn as Extractable, mn as Doable, n as FunctypeBase, nn as Reshapeable, rn as Promisable } from "../Functype-rgysbeU6.js";
2
- import { l as Type } from "../Typeable-lfO2nRVW.js";
3
- import { Option } from "../option/index.js";
4
- import { List } from "../list/index.js";
5
-
6
- //#region src/either/Either.d.ts
7
- /**
8
- * Either type module
9
- * @module Either
10
- * @category Core
11
- */
12
- interface Either<L extends Type, R extends Type> extends FunctypeBase<R, "Left" | "Right">, Promisable<R>, Doable<R>, Reshapeable<R>, Extractable<R> {
13
- readonly _tag: "Left" | "Right";
14
- value: L | R;
15
- isLeft(): this is Either<L, R> & {
16
- readonly _tag: "Left";
17
- value: L;
18
- };
19
- isRight(): this is Either<L, R> & {
20
- readonly _tag: "Right";
21
- value: R;
22
- };
23
- orElse: (defaultValue: R) => R;
24
- orThrow: (error?: Error) => R;
25
- or(alternative: Either<L, R>): Either<L, R>;
26
- orNull: () => R | null;
27
- orUndefined: () => R | undefined;
28
- readonly map: <U extends Type>(f: (value: R) => U) => Either<L, U>;
29
- ap: <U extends Type>(ff: Either<L, (value: R) => U>) => Either<L, U>;
30
- merge: <L1 extends Type, R1 extends Type>(other: Either<L1, R1>) => Either<L | L1, [R, R1]>;
31
- mapAsync: <U extends Type>(f: (value: R) => Promise<U>) => Promise<Either<L, U>>;
32
- flatMap: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U>;
33
- flatMapAsync: <U extends Type>(f: (value: R) => Promise<Either<L, U>>) => Promise<Either<L, U>>;
34
- toOption: () => Option<R>;
35
- toList: () => List<R>;
36
- toString: () => string;
37
- [Symbol.iterator]: () => Iterator<R>;
38
- yield: () => Generator<R, void, unknown>;
39
- traverse: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U[]>;
40
- lazyMap: <U extends Type>(f: (value: R) => U) => Generator<Either<L, U>, void, unknown>;
41
- tap: (f: (value: R) => void) => Either<L, R>;
42
- tapLeft: (f: (value: L) => void) => Either<L, R>;
43
- mapLeft: <L2 extends Type>(f: (value: L) => L2) => Either<L2, R>;
44
- bimap: <L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R) => R2) => Either<L2, R2>;
45
- fold: <T extends Type>(onLeft: (value: L) => T, onRight: (value: R) => T) => T;
46
- swap: () => Either<R, L>;
47
- /**
48
- * Pipes the value through the provided function based on whether this is a Left or Right
49
- * @param onLeft - The function to apply if this is a Left
50
- * @param onRight - The function to apply if this is a Right
51
- * @returns The result of applying the appropriate function
52
- */
53
- pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R) => U): U;
54
- /**
55
- * Pipes the Either value through the provided function
56
- * @param f - The function to apply to the value (Left or Right)
57
- * @returns The result of applying the function to the value
58
- */
59
- pipe<U extends Type>(f: (value: L | R) => U): U;
60
- /**
61
- * Pattern matches over the Either, applying a handler function based on the variant
62
- * @param patterns - Object with handler functions for Left and Right variants
63
- * @returns The result of applying the matching handler function
64
- */
65
- match<T>(patterns: {
66
- Left: (value: L) => T;
67
- Right: (value: R) => T;
68
- }): T;
69
- /**
70
- * Returns the value and tag for inspection
71
- */
72
- toValue(): {
73
- _tag: "Left" | "Right";
74
- value: L | R;
75
- };
76
- /**
77
- * Custom JSON serialization that excludes getter properties
78
- */
79
- toJSON(): {
80
- _tag: "Left" | "Right";
81
- value: L | R;
82
- };
83
- }
84
- type TestEither<L extends Type, R extends Type> = Either<L, R> & AsyncMonad<R>;
85
- declare const Right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
86
- declare const Left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
87
- declare const isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
88
- value: R;
89
- };
90
- declare const isLeft: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
91
- value: L;
92
- };
93
- declare const tryCatch: <L extends Type, R extends Type>(f: () => R, onError: (error: unknown) => L) => Either<L, R>;
94
- declare const TypeCheckRight: <L extends Type, R extends Type>(value: R) => TestEither<L, R>;
95
- declare const TypeCheckLeft: <L extends Type, R extends Type>(value: L) => TestEither<L, R>;
96
- declare const tryCatchAsync: <L extends Type, R extends Type>(f: () => Promise<R>, onError: (error: unknown) => L) => Promise<Either<L, R>>;
97
- declare const Either: (<L extends Type, R extends Type>(value: R | L, isRight: boolean) => Either<L, R>) & {
98
- /**
99
- * Creates a Left instance
100
- * @param value - The left value
101
- * @returns Left Either
102
- */
103
- left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
104
- /**
105
- * Creates a Right instance
106
- * @param value - The right value
107
- * @returns Right Either
108
- */
109
- right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
110
- /**
111
- * Type guard to check if an Either is Right
112
- * @param either - The Either to check
113
- * @returns True if Either is Right
114
- */
115
- isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
116
- value: R;
117
- };
118
- /**
119
- * Type guard to check if an Either is Left
120
- * @param either - The Either to check
121
- * @returns True if Either is Left
122
- */
123
- isLeft: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
124
- value: L;
125
- };
126
- /**
127
- * Combines an array of Eithers into a single Either containing an array
128
- * @param eithers - Array of Either values
129
- * @returns Either with array of values or first Left encountered
130
- */
131
- sequence: <L extends Type, R extends Type>(eithers: Either<L, R>[]) => Either<L, R[]>;
132
- /**
133
- * Maps an array through a function that returns Either, then sequences the results
134
- * @param arr - Array of values
135
- * @param f - Function that returns Either
136
- * @returns Either with array of results or first Left encountered
137
- */
138
- traverse: <L extends Type, R extends Type, U extends Type>(arr: R[], f: (value: R) => Either<L, U>) => Either<L, U[]>;
139
- /**
140
- * Creates an Either from a nullable value
141
- * @param value - The value that might be null or undefined
142
- * @param leftValue - The value to use for Left if value is null/undefined
143
- * @returns Right if value is not null/undefined, Left otherwise
144
- */
145
- fromNullable: <L extends Type, R extends Type>(value: R | null | undefined, leftValue: L) => Either<L, R>;
146
- /**
147
- * Creates an Either based on a predicate
148
- * @param value - The value to test
149
- * @param predicate - The predicate function
150
- * @param leftValue - The value to use for Left if predicate fails
151
- * @returns Right if predicate passes, Left otherwise
152
- */
153
- fromPredicate: <L extends Type, R extends Type>(value: R, predicate: (value: R) => boolean, leftValue: L) => Either<L, R>;
154
- /**
155
- * Applicative apply - applies a wrapped function to a wrapped value
156
- * @param eitherF - Either containing a function
157
- * @param eitherV - Either containing a value
158
- * @returns Either with function applied to value
159
- */
160
- ap: <L extends Type, R extends Type, U extends Type>(eitherF: Either<L, (value: R) => U>, eitherV: Either<L, R>) => Either<L, U>;
161
- /**
162
- * Creates an Either from a Promise
163
- * @param promise - The Promise to convert
164
- * @param onRejected - Function to convert rejection reason to Left value
165
- * @returns Promise that resolves to Either
166
- */
167
- fromPromise: <L, R>(promise: Promise<R>, onRejected: (reason: unknown) => L) => Promise<Either<L, R>>;
168
- /**
169
- * Creates an Either from JSON string
170
- * @param json - The JSON string
171
- * @returns Either instance
172
- */
173
- fromJSON: <L extends Type, R extends Type>(json: string) => Either<L, R>;
174
- /**
175
- * Creates an Either from YAML string
176
- * @param yaml - The YAML string
177
- * @returns Either instance
178
- */
179
- fromYAML: <L extends Type, R extends Type>(yaml: string) => Either<L, R>;
180
- /**
181
- * Creates an Either from binary string
182
- * @param binary - The binary string
183
- * @returns Either instance
184
- */
185
- fromBinary: <L extends Type, R extends Type>(binary: string) => Either<L, R>;
186
- };
187
- //#endregion
1
+ import { S as tryCatchAsync, _ as TypeCheckLeft, b as isRight, g as TestEither, h as Right, m as Left, p as Either, v as TypeCheckRight, x as tryCatch, y as isLeft } from "../index-OdnROQtM.js";
188
2
  export { Either, Left, Right, TestEither, TypeCheckLeft, TypeCheckRight, isLeft, isRight, tryCatch, tryCatchAsync };
@@ -1,2 +1 @@
1
- import{nt as e}from"../Valuable-CXh58HBk.js";import{t}from"../Companion-VlxcFhzb.js";import{None as n,Some as r}from"../option/index.js";import{Try as i}from"../try/index.js";import{List as a}from"../list/index.js";import o from"safe-stable-stringify";const s=t=>({[Symbol.toStringTag]:`Either`,_tag:`Right`,value:t,isLeft(){return!1},isRight(){return!0},orElse:e=>t,orThrow:()=>t,or:e=>l(t),orNull:()=>t,orUndefined:()=>t,map:e=>l(e(t)),ap:e=>e._tag===`Right`?l(e.value(t)):u(e.value),mapAsync:e=>e(t).then(e=>l(e)).catch(e=>Promise.resolve(u(e))),merge:e=>e.isLeft()?u(e.value):l([t,e.value]),flatMap:e=>e(t),flatMapAsync:e=>e(t).catch(e=>u(e)),toOption:()=>r(t),toList:()=>a([t]),toEither:e=>l(t),toTry:()=>i(()=>t),toJSON(){return{_tag:`Right`,value:t}},toString:()=>`Right(${o(t)})`,*[Symbol.iterator](){yield t},*yield(){yield t},traverse:e=>{let n=e(t);return n.isLeft()?u(n.value):l([n.value])},*lazyMap(e){yield l(e(t))},tap:e=>(e(t),l(t)),tapLeft:e=>l(t),mapLeft:e=>l(t),bimap:(e,n)=>l(n(t)),fold:(e,n)=>n(t),foldLeft:e=>n=>n(e,t),foldRight:e=>n=>n(t,e),match:e=>e.Right(t),swap:()=>u(t),toPromise:()=>Promise.resolve(t),toValue:()=>({_tag:`Right`,value:t}),pipeEither:(e,n)=>n(t),pipe:e=>e(t),serialize:()=>e(`Right`,t),get size(){return 1},get isEmpty(){return!1},contains:e=>t===e,reduce:e=>t,reduceRight:e=>t,count:e=>e(t)?1:0,find:e=>e(t)?r(t):n(),exists:e=>e(t),forEach:e=>e(t),doUnwrap(){return{ok:!0,value:t}}}),c=t=>({[Symbol.toStringTag]:`Either`,_tag:`Left`,value:t,isLeft(){return!0},isRight(){return!1},orElse:e=>e,orThrow:e=>{throw e??t},or:e=>e,orNull:()=>null,orUndefined:()=>void 0,map:e=>u(t),ap:e=>u(t),mapAsync:e=>Promise.resolve(u(t)),merge:e=>u(t),flatMap:e=>u(t),flatMapAsync:e=>Promise.resolve(u(t)),toOption:()=>n(),toList:()=>a(),toEither:e=>u(e),toTry:()=>i(()=>{throw Error(String(t))}),toJSON(){return{_tag:`Left`,value:t}},toString:()=>`Left(${o(t)})`,*[Symbol.iterator](){},*yield(){},traverse:e=>u(t),*lazyMap(e){yield u(t)},tap:e=>u(t),tapLeft:e=>(e(t),u(t)),mapLeft:e=>u(e(t)),bimap:(e,n)=>u(e(t)),fold:(e,n)=>e(t),foldLeft:e=>t=>e,foldRight:e=>t=>e,match:e=>e.Left(t),swap:()=>l(t),toPromise:()=>Promise.reject(t),toValue:()=>({_tag:`Left`,value:t}),pipeEither:(e,n)=>e(t),pipe:e=>e(t),serialize:()=>e(`Left`,t),get size(){return 0},get isEmpty(){return!0},contains:e=>!1,reduce:e=>{throw Error(`Cannot reduce a Left`)},reduceRight:e=>{throw Error(`Cannot reduceRight a Left`)},count:e=>0,find:e=>n(),exists:e=>!1,forEach:e=>{},doUnwrap(){return{ok:!1,empty:!1,error:t}}}),l=e=>s(e),u=e=>c(e),d=e=>e.isRight(),f=e=>e.isLeft(),p=(e,t)=>{try{return l(e())}catch(e){return u(t(e))}},m=e=>s(e);console.assert(m);const h=e=>c(e);console.assert(h);const g=async(e,t)=>{try{return l(await e())}catch(e){return u(t(e))}},_=(e,t)=>t?l(e):u(e),v={left:e=>u(e),right:e=>l(e),isRight:e=>e.isRight(),isLeft:e=>e.isLeft(),sequence:e=>e.reduce((e,t)=>e.isLeft()?e:t.isLeft()?u(t.value):e.map(e=>[...e,t.value]),l([])),traverse:(e,t)=>v.sequence(e.map(t)),fromNullable:(e,t)=>e==null?u(t):l(e),fromPredicate:(e,t,n)=>t(e)?l(e):u(n),ap:(e,t)=>e.flatMap(e=>t.map(e)),fromPromise:async(e,t)=>{try{return l(await e)}catch(e){return u(t(e))}},fromJSON:e=>{let t=JSON.parse(e);return t._tag===`Right`?l(t.value):u(t.value)},fromYAML:e=>{let t=e.split(`
2
- `),n=t[0]?.split(`: `)[1],r=t[1]?.split(`: `)[1];if(!n||!r)throw Error(`Invalid YAML format for Either`);let i=JSON.parse(r);return n===`Right`?l(i):u(i)},fromBinary:e=>{let t=Buffer.from(e,`base64`).toString();return v.fromJSON(t)}},y=t(_,v);export{y as Either,u as Left,l as Right,h as TypeCheckLeft,m as TypeCheckRight,f as isLeft,d as isRight,p as tryCatch,g as tryCatchAsync};
1
+ import{ct as e,dt as t,ft as n,lt as r,mt as i,ot as a,pt as o,st as s,ut as c}from"../src-ByDeJzWj.js";export{a as Either,s as Left,e as Right,r as TypeCheckLeft,c as TypeCheckRight,t as isLeft,n as isRight,o as tryCatch,i as tryCatchAsync};