functype 0.18.0 → 0.20.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 (67) hide show
  1. package/README.md +13 -11
  2. package/README.processed.md +2 -11
  3. package/dist/Brand-B-0nKo7I.d.ts +55 -0
  4. package/dist/Brand-Cfr5zy8F.js +2 -0
  5. package/dist/Brand-Cfr5zy8F.js.map +1 -0
  6. package/dist/Tuple-CKxIyX7l.d.ts +178 -0
  7. package/dist/Tuple-CgX4p79w.js +2 -0
  8. package/dist/Tuple-CgX4p79w.js.map +1 -0
  9. package/dist/branded/index.d.ts +2 -54
  10. package/dist/branded/index.js +1 -0
  11. package/dist/cli/index.d.ts +1 -0
  12. package/dist/cli/index.js +660 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/do/index.d.ts +4 -240
  15. package/dist/do/index.js +1 -0
  16. package/dist/either/index.d.ts +4 -2
  17. package/dist/either/index.js +1 -0
  18. package/dist/fpromise/index.d.ts +4 -373
  19. package/dist/fpromise/index.js +1 -0
  20. package/dist/index-Bnjlo4cT.d.ts +3575 -0
  21. package/dist/index.d.ts +4 -1934
  22. package/dist/index.js +1 -0
  23. package/dist/list/index.d.ts +4 -2
  24. package/dist/list/index.js +1 -0
  25. package/dist/map/index.d.ts +4 -58
  26. package/dist/map/index.js +1 -0
  27. package/dist/option/index.d.ts +4 -2
  28. package/dist/option/index.js +1 -0
  29. package/dist/set/index.d.ts +4 -2
  30. package/dist/set/index.js +1 -0
  31. package/dist/src-BOxI0-73.js +20 -0
  32. package/dist/src-BOxI0-73.js.map +1 -0
  33. package/dist/try/index.d.ts +4 -2
  34. package/dist/try/index.js +1 -0
  35. package/dist/tuple/index.d.ts +2 -75
  36. package/dist/tuple/index.js +1 -0
  37. package/package.json +31 -42
  38. package/dist/Either-Ccg0S1uS.d.ts +0 -1015
  39. package/dist/Typeable-DiGVtDnq.d.ts +0 -96
  40. package/dist/branded/index.mjs +0 -2
  41. package/dist/branded/index.mjs.map +0 -1
  42. package/dist/chunk-6ZIR6EKC.mjs +0 -38
  43. package/dist/chunk-6ZIR6EKC.mjs.map +0 -1
  44. package/dist/chunk-7JJIUQXK.mjs +0 -3
  45. package/dist/chunk-7JJIUQXK.mjs.map +0 -1
  46. package/dist/chunk-OR6V4TCO.mjs +0 -2
  47. package/dist/chunk-OR6V4TCO.mjs.map +0 -1
  48. package/dist/do/index.mjs +0 -2
  49. package/dist/do/index.mjs.map +0 -1
  50. package/dist/either/index.mjs +0 -2
  51. package/dist/either/index.mjs.map +0 -1
  52. package/dist/fpromise/index.mjs +0 -2
  53. package/dist/fpromise/index.mjs.map +0 -1
  54. package/dist/index.mjs +0 -2
  55. package/dist/index.mjs.map +0 -1
  56. package/dist/list/index.mjs +0 -2
  57. package/dist/list/index.mjs.map +0 -1
  58. package/dist/map/index.mjs +0 -2
  59. package/dist/map/index.mjs.map +0 -1
  60. package/dist/option/index.mjs +0 -2
  61. package/dist/option/index.mjs.map +0 -1
  62. package/dist/set/index.mjs +0 -2
  63. package/dist/set/index.mjs.map +0 -1
  64. package/dist/try/index.mjs +0 -2
  65. package/dist/try/index.mjs.map +0 -1
  66. package/dist/tuple/index.mjs +0 -2
  67. package/dist/tuple/index.mjs.map +0 -1
@@ -0,0 +1,660 @@
1
+ #!/usr/bin/env node
2
+ import"../Brand-Cfr5zy8F.js";import"../Tuple-CgX4p79w.js";import{L as e,ct as t,gt as n}from"../src-BOxI0-73.js";const r=`0.18.2`,i={Option:{description:`Safe nullable handling - Some<T> or None`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Matchable`,`Serializable`,`Traversable`],methods:{create:[`Option(v)`,`Option.none()`,`Some(v)`,`None()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.ap(ff)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.orNull()`,`.match({Some, None})`],check:[`.isSome`,`.isNone`,`.isDefined`,`.isEmpty`]}},Either:{description:`Error handling with Left (error) or Right (success)`,interfaces:[`Functor`,`Monad`,`Foldable`,`Traversable`,`PromiseLike`],methods:{create:[`Right(v)`,`Left(e)`,`Either.right(v)`,`Either.left(e)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapLeft(f)`,`.swap()`],extract:[`.fold(l, r)`,`.orElse(d)`,`.orThrow()`,`.match({Left, Right})`],check:[`.isRight`,`.isLeft`]}},Try:{description:`Wrap operations that may throw - Success<T> or Failure`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Matchable`,`Serializable`,`Traversable`],methods:{create:[`Try(() => expr)`,`Success(v)`,`Failure(e)`],transform:[`.map(f)`,`.flatMap(f)`,`.recover(f)`,`.recoverWith(f)`],extract:[`.fold(f, s)`,`.orElse(d)`,`.orThrow()`,`.toOption()`,`.toEither()`],check:[`.isSuccess`,`.isFailure`]}},List:{description:`Immutable array with functional operations`,interfaces:[`Functor`,`Monad`,`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`List([...])`,`List.of(...)`,`List.empty()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.take(n)`,`.drop(n)`],extract:[`.fold(z, f)`,`.reduce(f)`,`.head`,`.tail`,`.toArray()`],check:[`.isEmpty`,`.nonEmpty`,`.size`,`.contains(v)`]}},Set:{description:`Immutable set of unique values`,interfaces:[`Functor`,`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Set([...])`,`Set.of(...)`,`Set.empty()`],transform:[`.map(f)`,`.filter(p)`,`.union(s)`,`.intersection(s)`,`.difference(s)`],extract:[`.fold(z, f)`,`.toArray()`],check:[`.has(v)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:[`SafeTraversable`,`Collection`,`Serializable`],methods:{create:[`Map([...])`,`Map.of(...)`,`Map.empty()`],transform:[`.set(k, v)`,`.delete(k)`,`.map(f)`,`.filter(p)`],extract:[`.get(k)`,`.keys()`,`.values()`,`.entries()`,`.fold(z, f)`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Lazy:{description:`Deferred computation with memoization`,interfaces:[`Functor`,`Monad`,`Foldable`,`Extractable`,`Serializable`,`Traversable`],methods:{create:[`Lazy(() => expr)`],transform:[`.map(f)`,`.flatMap(f)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.get()`],check:[`.isEvaluated`]}},LazyList:{description:`Lazy sequences for large/infinite data`,interfaces:[`Functor`,`Monad`,`Iterable`],methods:{create:[`LazyList.from(iter)`,`LazyList.range(start, end)`,`LazyList.infinite(f)`],transform:[`.map(f)`,`.filter(p)`,`.take(n)`,`.drop(n)`,`.concat(ll)`],extract:[`.head`,`.tail`,`.toArray()`],check:[`.isEmpty`]}},Task:{description:`Async operations with cancellation and progress`,interfaces:[],methods:{create:[`Task.of(v)`,`Task.from(promise)`,`Task.sync(f)`,`Task.async(f)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`],extract:[`.run()`,`.cancel()`],other:[`.onProgress(cb)`,`.onCancel(cb)`]}},FPromise:{description:`Enhanced Promise with functional methods`,interfaces:[`PromiseLike`],methods:{create:[`FPromise.of(v)`,`FPromise.from(promise)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`,`.recover(f)`],extract:[`.toPromise()`,`.cancel()`]}},Cond:{description:`Conditional expression builder - replace if-else chains`,interfaces:[],methods:{create:[`Cond<T>()`],other:[`.case(pred, result)`,`.otherwise(result)`,`.eval()`]}},Match:{description:`Pattern matching - replace switch statements`,interfaces:[],methods:{create:[`Match(value)`],other:[`.case(pattern, result)`,`.when(pred, result)`,`.default(result)`,`.done()`]}},Brand:{description:`Nominal typing without runtime overhead`,interfaces:[],methods:{create:[`Brand<K, T>(value)`],extract:[`.unwrap()`,`.toString()`]}},ValidatedBrand:{description:`Branded types with runtime validation`,interfaces:[],methods:{create:[`ValidatedBrand(validator)`,`.of(v)`,`.from(v)`,`.unsafeOf(v)`],check:[`.is(v)`],other:[`.refine(validator)`]}},Tuple:{description:`Fixed-size typed array`,interfaces:[`Typeable`,`Valuable`,`Iterable`],methods:{create:[`Tuple([a, b, ...])`,`Tuple.of(a, b, ...)`],extract:[`.first`,`.second`,`.toArray()`],transform:[`.map(f)`]}},Stack:{description:`Immutable LIFO stack`,interfaces:[`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Stack()`,`Stack.of(...)`],transform:[`.push(v)`,`.pop()`],extract:[`.peek()`,`.toArray()`],check:[`.isEmpty`,`.size`]}}},a={Functor:{description:`Transform contained values`,methods:[`.map<B>(f: A => B): Functor<B>`]},Applicative:{extends:`Functor`,description:`Apply wrapped functions`,methods:[`.ap<B>(ff: Applicative<A => B>): Applicative<B>`]},Monad:{extends:`Applicative`,description:`Chain operations returning wrapped values`,methods:[`.flatMap<B>(f: A => Monad<B>): Monad<B>`]},Foldable:{description:`Extract via pattern matching`,methods:[`.fold<B>(empty: () => B, f: A => B): B`,`.foldLeft<B>(z: B, op: (B, A) => B): B`,`.foldRight<B>(z: B, op: (A, B) => B): B`]},Extractable:{description:`Get contained value with fallback`,methods:[`.orElse(d: T): T`,`.orThrow(e?: Error): T`,`.orNull(): T | null`,`.orUndefined(): T | undefined`]},Matchable:{description:`Pattern match on type variants`,methods:[`.match<R>(patterns: Record<Tag, Handler>): R`]},Traversable:{description:`Iterate and check contents`,methods:[`.size: number`,`.isEmpty: boolean`,`.contains(v: A): boolean`,`.reduce<B>(f, init): B`]},Collection:{description:`Collection operations`,methods:[`.toArray(): A[]`,`.forEach(f: A => void): void`]},Serializable:{description:`Convert to string formats`,methods:[`.serialize().toJSON(): string`,`.serialize().toYAML(): string`]}},o={Core:[`Option`,`Either`,`Try`],Collection:[`List`,`Set`,`Map`,`LazyList`,`Tuple`,`Stack`],Async:[`Task`,`FPromise`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`]},s=()=>{let e=t([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return t(Object.entries(o)).foldLeft(e)((e,[r,a])=>{let o=e.add(r.toUpperCase());return t(a).foldLeft(o)((e,t)=>n(i[t]).fold(()=>e,n=>{let r=n.interfaces.length>0?` [${n.interfaces.join(`, `)}]`:``;return e.add(` ${t}${r}`).add(` ${n.description}`)})).add(``)}).concat(t([`Use: npx functype <Type> for details`,`Use: npx functype interfaces for interface reference`])).toArray().join(`
3
+ `)},c=(e,r)=>{let i=r.interfaces.length>0?` [${r.interfaces.join(`, `)}]`:``,a=t([`create`,`transform`,`extract`,`check`,`other`]),o=t([`${e}<T>${i}`,``,r.description,``]);return a.foldLeft(o)((e,i)=>n(r.methods[i]).filter(e=>e.length>0).fold(()=>e,n=>{let r=e.add(i.toUpperCase());return t(n).foldLeft(r)((e,t)=>e.add(` ${t}`)).add(``)})).toArray().join(`
4
+ `).trimEnd()},l=()=>{let e=t([`INTERFACES`,``]);return t(Object.entries(a)).foldLeft(e)((e,[n,r])=>{let i=r.extends?` extends ${r.extends}`:``,a=e.add(`${n}<A>${i}`).add(` ${r.description}`);return t(r.methods).foldLeft(a)((e,t)=>e.add(` ${t}`)).add(``)}).toArray().join(`
5
+ `).trimEnd()},u=e=>JSON.stringify(e,null,2),d=()=>({version:r,categories:o,types:i}),f=e=>n(i[e]).map(t=>({name:e,data:t})).or(t(Object.entries(i)).find(([t])=>t.toLowerCase()===e.toLowerCase()).map(([e,t])=>({name:e,data:t}))).orUndefined(),p=()=>Object.keys(i),m=()=>a,h={Option:`export interface Option<T extends Type> extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
6
+ /** The contained value (undefined for None) */
7
+ readonly value: T | undefined
8
+ /** Whether this Option contains no value */
9
+ isEmpty: boolean
10
+ /**
11
+ * Returns true if this Option is a Some (contains a value)
12
+ * @returns true if this Option contains a value, false otherwise
13
+ */
14
+ isSome(): this is Option<T> & { value: T; isEmpty: false }
15
+ /**
16
+ * Returns true if this Option is a None (contains no value)
17
+ * @returns true if this Option is empty, false otherwise
18
+ */
19
+ isNone(): this is Option<T> & { value: undefined; isEmpty: true }
20
+ /**
21
+ * Returns the contained value or a default value if None
22
+ * @param defaultValue - The value to return if this Option is None
23
+ * @returns The contained value or defaultValue
24
+ */
25
+ orElse(defaultValue: T): T
26
+ /**
27
+ * Returns the contained value or throws an error if None
28
+ * @param error - Optional custom error to throw. If not provided, throws a default error
29
+ * @returns The contained value
30
+ * @throws The specified error or a default error if the Option is None
31
+ */
32
+ orThrow(error?: Error): T
33
+ /**
34
+ * Returns this Option if it contains a value, otherwise returns the alternative container
35
+ * @param alternative - The alternative Option to return if this is None
36
+ * @returns This Option or the alternative
37
+ */
38
+ or(alternative: Option<T>): Option<T>
39
+ /**
40
+ * Returns the contained value or null if None
41
+ * @returns The contained value or null
42
+ */
43
+ orNull(): T | null
44
+ /**
45
+ * Returns the contained value or undefined if None
46
+ * @returns The contained value or undefined
47
+ */
48
+ orUndefined(): T | undefined
49
+ /**
50
+ * Maps the value inside the Option using the provided function
51
+ * @param f - The mapping function
52
+ * @returns A new Option containing the mapped value, or None if this Option is None
53
+ */
54
+ map<U extends Type>(f: (value: T) => U): Option<U>
55
+ /**
56
+ * Applies a wrapped function to a wrapped value (Applicative pattern)
57
+ * @param ff - An Option containing a function from T to U
58
+ * @returns A new Option containing the result of applying the function
59
+ */
60
+ ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>
61
+ /**
62
+ * Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
63
+ * @param predicate - The predicate function to test the value
64
+ * @returns This Option or None
65
+ */
66
+ filter(predicate: (value: T) => boolean): Option<T>
67
+ /**
68
+ * Maps the value using a function that returns an Option
69
+ * @param f - The mapping function returning an Option
70
+ * @returns The result of applying f to the contained value, or None if this Option is None
71
+ */
72
+ flatMap<U extends Type>(f: (value: T) => Option<U>): Option<U>
73
+ /**
74
+ * Maps the value using an async function that returns an Option
75
+ * @param f - The async mapping function returning an Option
76
+ * @returns Promise of the result of applying f to the contained value, or None if this Option is None
77
+ */
78
+ flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>
79
+ /**
80
+ * Applies a binary operator to a start value and the contained value
81
+ * @param f - The binary operator
82
+ * @returns The result of the reduction
83
+ */
84
+ reduce<U>(f: (acc: U, value: T) => U): U
85
+ /**
86
+ * Applies a binary operator to the contained value and a start value
87
+ * @param f - The binary operator
88
+ * @returns The result of the reduction
89
+ */
90
+ reduceRight<U>(f: (acc: U, value: T) => U): U
91
+ /**
92
+ * Pattern matches over the Option, applying onNone if None and onSome if Some
93
+ * @param onNone - Function to apply if the Option is None
94
+ * @param onSome - Function to apply if the Option has a value
95
+ * @returns The result of applying the appropriate function
96
+ */
97
+ fold<U>(onNone: () => U, onSome: (value: T) => U): U
98
+ /**
99
+ * Left-associative fold using the provided zero value and operation
100
+ * @param z - Zero/identity value
101
+ * @returns A function that takes an operation to apply
102
+ */
103
+ foldLeft<B>(z: B): (op: (b: B, a: T) => B) => B
104
+ /**
105
+ * Right-associative fold using the provided zero value and operation
106
+ * @param z - Zero/identity value
107
+ * @returns A function that takes an operation to apply
108
+ */
109
+ foldRight<B>(z: B): (op: (a: T, b: B) => B) => B
110
+ /**
111
+ * Converts this Option to a List
112
+ * @returns A List containing the value if Some, or empty List if None
113
+ */
114
+ toList(): List<T>
115
+ /**
116
+ * Checks if this Option contains the specified value
117
+ * @param value - The value to check for
118
+ * @returns true if this Option contains the value, false otherwise
119
+ */
120
+ contains(value: T): boolean
121
+ /** The number of elements in this Option (0 or 1) */
122
+ size: number
123
+ /**
124
+ * Converts this Option to an Either
125
+ * @param left - The value to use for Left if this Option is None
126
+ * @returns Either.Right with the contained value if Some, or Either.Left with left if None
127
+ */
128
+ toEither<E>(left: E): Either<E, T>
129
+ /**
130
+ * Returns a string representation of this Option
131
+ * @returns A string representation
132
+ */
133
+ toString(): string
134
+ /**
135
+ * Returns a simple object representation of this Option
136
+ * @returns An object with _tag and value properties
137
+ */
138
+ toValue(): { _tag: "Some" | "None"; value: T }
139
+ /**
140
+ * Pattern matches over the Option, applying a handler function based on the variant
141
+ * @param patterns - Object with handler functions for Some and None variants
142
+ * @returns The result of applying the matching handler function
143
+ */
144
+ match<R>(patterns: { Some: (value: T) => R; None: () => R }): R
145
+ }`,Either:`export interface Either<L extends Type, R extends Type>
146
+ extends FunctypeBase<R, "Left" | "Right">, Promisable<R>, Doable<R>, Reshapeable<R>, Extractable<R> {
147
+ readonly _tag: "Left" | "Right"
148
+ value: L | R
149
+ isLeft(): this is Either<L, R> & { readonly _tag: "Left"; value: L }
150
+ isRight(): this is Either<L, R> & { readonly _tag: "Right"; value: R }
151
+ orElse: (defaultValue: R) => R
152
+ orThrow: (error?: Error) => R
153
+ or(alternative: Either<L, R>): Either<L, R>
154
+ orNull: () => R | null
155
+ orUndefined: () => R | undefined
156
+ readonly map: <U extends Type>(f: (value: R) => U) => Either<L, U>
157
+ ap: <U extends Type>(ff: Either<L, (value: R) => U>) => Either<L, U>
158
+ merge: <L1 extends Type, R1 extends Type>(other: Either<L1, R1>) => Either<L | L1, [R, R1]>
159
+ mapAsync: <U extends Type>(f: (value: R) => Promise<U>) => Promise<Either<L, U>>
160
+ flatMap: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U>
161
+ flatMapAsync: <U extends Type>(f: (value: R) => Promise<Either<L, U>>) => Promise<Either<L, U>>
162
+ toOption: () => Option<R>
163
+ toList: () => List<R>
164
+ toString: () => string
165
+ [Symbol.iterator]: () => Iterator<R>
166
+ yield: () => Generator<R, void, unknown>
167
+ traverse: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U[]>
168
+ lazyMap: <U extends Type>(f: (value: R) => U) => Generator<Either<L, U>, void, unknown>
169
+ tap: (f: (value: R) => void) => Either<L, R>
170
+ tapLeft: (f: (value: L) => void) => Either<L, R>
171
+ mapLeft: <L2 extends Type>(f: (value: L) => L2) => Either<L2, R>
172
+ bimap: <L2 extends Type, R2 extends Type>(fl: (value: L) => L2, fr: (value: R) => R2) => Either<L2, R2>
173
+ fold: <T extends Type>(onLeft: (value: L) => T, onRight: (value: R) => T) => T
174
+ swap: () => Either<R, L>
175
+ /**
176
+ * Pipes the value through the provided function based on whether this is a Left or Right
177
+ * @param onLeft - The function to apply if this is a Left
178
+ * @param onRight - The function to apply if this is a Right
179
+ * @returns The result of applying the appropriate function
180
+ */
181
+ pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R) => U): U
182
+
183
+ /**
184
+ * Pipes the Either value through the provided function
185
+ * @param f - The function to apply to the value (Left or Right)
186
+ * @returns The result of applying the function to the value
187
+ */
188
+ pipe<U extends Type>(f: (value: L | R) => U): U
189
+ /**
190
+ * Pattern matches over the Either, applying a handler function based on the variant
191
+ * @param patterns - Object with handler functions for Left and Right variants
192
+ * @returns The result of applying the matching handler function
193
+ */
194
+ match<T>(patterns: { Left: (value: L) => T; Right: (value: R) => T }): T
195
+ /**
196
+ * Returns the value and tag for inspection
197
+ */
198
+ toValue(): { _tag: "Left" | "Right"; value: L | R }
199
+ /**
200
+ * Custom JSON serialization that excludes getter properties
201
+ */
202
+ toJSON(): { _tag: "Left" | "Right"; value: L | R }
203
+ }`,Try:`export interface Try<T>
204
+ extends FunctypeBase<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
205
+ readonly _tag: TypeNames
206
+ readonly error: Error | undefined
207
+ isSuccess(): this is Try<T> & { readonly _tag: "Success"; error: undefined }
208
+ isFailure(): this is Try<T> & { readonly _tag: "Failure"; error: Error }
209
+ orElse: (defaultValue: T) => T
210
+ orThrow: (error?: Error) => T
211
+ or: (alternative: Try<T>) => Try<T>
212
+ orNull: () => T | null
213
+ orUndefined: () => T | undefined
214
+ toOption: () => Option<T>
215
+ toEither: <E extends Type>(leftValue: E) => Either<E, T>
216
+ toList: () => List<T>
217
+ toTry: () => Try<T>
218
+ map: <U>(f: (value: T) => U) => Try<U>
219
+ ap: <U>(ff: Try<(value: T) => U>) => Try<U>
220
+ flatMap: <U>(f: (value: T) => Try<U>) => Try<U>
221
+ flatMapAsync: <U>(f: (value: T) => Promise<Try<U>>) => Promise<Try<U>>
222
+ /**
223
+ * Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
224
+ * @param onFailure - Function to apply if the Try is Failure
225
+ * @param onSuccess - Function to apply if the Try is Success
226
+ * @returns The result of applying the appropriate function
227
+ */
228
+ fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U
229
+ toString: () => string
230
+ /**
231
+ * Pattern matches over the Try, applying a handler function based on the variant
232
+ * @param patterns - Object with handler functions for Success and Failure variants
233
+ * @returns The result of applying the matching handler function
234
+ */
235
+ match<R>(patterns: { Success: (value: T) => R; Failure: (error: Error) => R }): R
236
+ toValue(): { _tag: TypeNames; value: T | Error }
237
+ }`,List:`export interface List<A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
238
+ readonly length: number
239
+ readonly [Symbol.iterator]: () => Iterator<A>
240
+ // Override these to return List instead of FunctypeCollection
241
+ map: <B>(f: (a: A) => B) => List<B>
242
+ ap: <B>(ff: List<(value: A) => B>) => List<B>
243
+ flatMap: <B>(f: (a: A) => Iterable<B>) => List<B>
244
+ flatMapAsync: <B>(f: (a: A) => PromiseLike<Iterable<B>>) => PromiseLike<List<B>>
245
+ // Override filter for type guard support
246
+ filter<S extends A>(predicate: (a: A) => a is S): List<S>
247
+ filter(predicate: (a: A) => unknown): List<A>
248
+ filterNot: (p: (a: A) => boolean) => List<A>
249
+ // List-specific methods
250
+ /** @internal */
251
+ filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>
252
+ remove: (value: A) => List<A>
253
+ removeAt: (index: number) => List<A>
254
+ add: (item: A) => List<A>
255
+ get: (index: number) => Option<A>
256
+ concat: (other: List<A>) => List<A>
257
+ /**
258
+ * Pattern matches over the List, applying a handler function based on whether it's empty
259
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
260
+ * @returns The result of applying the matching handler function
261
+ */
262
+ match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
263
+ }`,Set:`export interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
264
+ add: (value: A) => Set<A>
265
+ remove: (value: A) => Set<A>
266
+ contains: (value: A) => boolean
267
+ has: (value: A) => boolean
268
+ map: <B>(f: (a: A) => B) => Set<B>
269
+ flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>
270
+ filter: (p: (a: A) => boolean) => Set<A>
271
+ filterNot: (p: (a: A) => boolean) => Set<A>
272
+ fold: <U extends Type>(onEmpty: () => U, onValue: (value: A) => U) => U
273
+ toList: () => List<A>
274
+ toSet: () => Set<A>
275
+ toArray: <B = A>() => B[]
276
+ toString: () => string
277
+ }`,Map:`export interface Map<K, V>
278
+ extends
279
+ SafeTraversable<K, V>,
280
+ Collection<Tuple<[K, V]>>,
281
+ Typeable<"Map">,
282
+ Serializable<[K, V][]>,
283
+ Pipe<[K, V][]>,
284
+ Foldable<Tuple<[K, V]>>,
285
+ Iterable<[K, V]> {
286
+ readonly _tag: "Map"
287
+ add(item: Tuple<[K, V]>): Map<K, V>
288
+ remove(value: K): Map<K, V>
289
+ map<U>(f: (value: V) => U): Map<K, U>
290
+ ap<U>(ff: Map<K, (value: V) => U>): Map<K, U>
291
+ flatMap<K2, V2>(f: (entry: Tuple<[K, V]>) => Iterable<[K2, V2]>): Map<K2, V2>
292
+ flatMapAsync<U>(f: (value: V) => PromiseLike<Map<K, U>>): PromiseLike<Map<K, U>>
293
+ get(key: K): Option<V>
294
+ getOrElse(key: K, defaultValue: V): V
295
+ orElse(key: K, alternative: Option<V>): Option<V>
296
+ fold<U extends Type>(onEmpty: () => U, onValue: (value: Tuple<[K, V]>) => U): U
297
+ foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K, V]>) => B) => B
298
+ foldRight<B>(z: B): (op: (a: Tuple<[K, V]>, b: B) => B) => B
299
+ /**
300
+ * Pattern matches over the Map, applying a handler function based on whether it's empty
301
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
302
+ * @returns The result of applying the matching handler function
303
+ */
304
+ match<R>(patterns: { Empty: () => R; NonEmpty: (entries: Array<Tuple<[K, V]>>) => R }): R
305
+ toValue(): { _tag: "Map"; value: [K, V][] }
306
+ }`,Lazy:`export interface Lazy<T extends Type> extends FunctypeBase<T, "Lazy">, Extractable<T>, Pipe<T> {
307
+ /** Tag identifying this as a Lazy type */
308
+ readonly _tag: "Lazy"
309
+ /** Whether the computation has been evaluated */
310
+ readonly isEvaluated: boolean
311
+ /**
312
+ * Returns the computed value or a default value if computation fails
313
+ * @param defaultValue - The value to return if computation fails
314
+ * @returns The computed value or defaultValue
315
+ */
316
+ orElse(defaultValue: T): T
317
+ /**
318
+ * Returns the computed value or null if computation fails
319
+ * @returns The computed value or null
320
+ */
321
+ orNull(): T | null
322
+ /**
323
+ * Returns the computed value or throws an error if computation fails
324
+ * @param error - Optional custom error to throw. If not provided, throws the computation error or a default error
325
+ * @returns The computed value
326
+ * @throws The specified error, computation error, or a default error
327
+ */
328
+ orThrow(error?: Error): T
329
+ /**
330
+ * Returns this Lazy if computation succeeds, otherwise returns the alternative Lazy
331
+ * @param alternative - The alternative Lazy to use if computation fails
332
+ * @returns This Lazy or the alternative
333
+ */
334
+ or(alternative: Lazy<T>): Lazy<T>
335
+ /**
336
+ * Maps the value inside the Lazy using the provided function
337
+ * @param f - The mapping function
338
+ * @returns A new Lazy containing the mapped value
339
+ */
340
+ map<U extends Type>(f: (value: T) => U): Lazy<U>
341
+ /**
342
+ * Applies a wrapped function to a wrapped value (Applicative pattern)
343
+ * @param ff - A Lazy containing a function from T to U
344
+ * @returns A new Lazy containing the result
345
+ */
346
+ ap<U extends Type>(ff: Lazy<(value: T) => U>): Lazy<U>
347
+ /**
348
+ * Maps the value inside the Lazy using an async function
349
+ * @param f - The async mapping function
350
+ * @returns A Promise of a new Lazy containing the mapped value
351
+ */
352
+ mapAsync<U extends Type>(f: (value: T) => Promise<U>): Promise<Lazy<U>>
353
+ /**
354
+ * Maps the value using a function that returns a Lazy
355
+ * @param f - The mapping function returning a Lazy
356
+ * @returns A new Lazy containing the flattened result
357
+ */
358
+ flatMap<U extends Type>(f: (value: T) => Lazy<U>): Lazy<U>
359
+ /**
360
+ * Maps the value using an async function that returns a Lazy
361
+ * @param f - The async mapping function returning a Lazy
362
+ * @returns A Promise of a new Lazy containing the flattened result
363
+ */
364
+ flatMapAsync<U extends Type>(f: (value: T) => Promise<Lazy<U>>): Promise<Lazy<U>>
365
+ /**
366
+ * Returns a Lazy that filters the value based on a predicate
367
+ * @param predicate - The predicate function
368
+ * @returns A Lazy containing an Option of the value
369
+ */
370
+ filter(predicate: (value: T) => boolean): Lazy<Option<T>>
371
+ /**
372
+ * Recovers from a failed computation by providing an alternative value
373
+ * @param f - Function that takes the error and returns a recovery value
374
+ * @returns A new Lazy that will use the recovery function if computation fails
375
+ */
376
+ recover(f: (error: unknown) => T): Lazy<T>
377
+ /**
378
+ * Recovers from a failed computation by providing an alternative Lazy
379
+ * @param f - Function that takes the error and returns a recovery Lazy
380
+ * @returns A new Lazy that will use the recovery Lazy if computation fails
381
+ */
382
+ recoverWith(f: (error: unknown) => Lazy<T>): Lazy<T>
383
+ /**
384
+ * Evaluates the computation and returns it as an Option
385
+ * @returns Some containing the value if successful, None if computation fails
386
+ */
387
+ toOption(): Option<T>
388
+ /**
389
+ * Evaluates the computation and returns it as an Either
390
+ * @returns Right containing the value if successful, Left containing the error if computation fails
391
+ */
392
+ toEither(): Either<unknown, T>
393
+ /**
394
+ * Evaluates the computation and returns it as an Either with a mapped error
395
+ * @param mapError - Function to map the error
396
+ * @returns Right containing the value if successful, Left containing the mapped error if computation fails
397
+ */
398
+ toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T>
399
+ /**
400
+ * Evaluates the computation and returns it as a Try
401
+ * @returns Try containing the result of the computation
402
+ */
403
+ toTry(): Try<T>
404
+ /**
405
+ * Applies an effect function to the value if computation succeeds
406
+ * @param f - The effect function
407
+ * @returns This Lazy for chaining
408
+ */
409
+ tap(f: (value: T) => void): Lazy<T>
410
+ /**
411
+ * Applies an effect function to the error if computation fails
412
+ * @param f - The effect function for errors
413
+ * @returns This Lazy for chaining
414
+ */
415
+ tapError(f: (error: unknown) => void): Lazy<T>
416
+ /**
417
+ * Pattern matching on the Lazy value
418
+ * @param f - Function to apply to the computed value
419
+ * @returns The result of applying f to the computed value
420
+ */
421
+ fold<U>(f: (value: T) => U): U
422
+ /**
423
+ * Pattern matching with success and failure handlers
424
+ * @param onFailure - Function to handle computation failure
425
+ * @param onSuccess - Function to handle successful computation
426
+ * @returns The result of the appropriate handler
427
+ */
428
+ foldWith<U>(onFailure: (error: unknown) => U, onSuccess: (value: T) => U): U
429
+ /**
430
+ * Left fold operation
431
+ * @param z - Initial value
432
+ * @returns Function that takes an operator and applies it
433
+ */
434
+ foldLeft: <B>(z: B) => (op: (b: B, a: T) => B) => B
435
+ /**
436
+ * Right fold operation
437
+ * @param z - Initial value
438
+ * @returns Function that takes an operator and applies it
439
+ */
440
+ foldRight: <B>(z: B) => (op: (a: T, b: B) => B) => B
441
+ /**
442
+ * Pattern matching for the Lazy type
443
+ * @param patterns - Object with handler for Lazy pattern
444
+ * @returns The result of the matched handler
445
+ */
446
+ match<R>(patterns: { Lazy: (value: T) => R }): R
447
+ /**
448
+ * Creates a string representation of the Lazy
449
+ * @returns String representation showing evaluation status
450
+ */
451
+ toString(): string
452
+ /**
453
+ * Converts the Lazy to a value object
454
+ * @returns Object representation of the Lazy with evaluation state
455
+ */
456
+ toValue(): { _tag: "Lazy"; evaluated: boolean; value?: T }
457
+ }`,LazyList:`export interface LazyList<A extends Type>
458
+ extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
459
+ // Iterator protocol
460
+ [Symbol.iterator](): Iterator<A>
461
+
462
+ // Lazy operations
463
+ map<B extends Type>(f: (a: A) => B): LazyList<B>
464
+ flatMap<B extends Type>(f: (a: A) => LazyList<B>): LazyList<B>
465
+ filter(predicate: (a: A) => boolean): LazyList<A>
466
+ take(n: number): LazyList<A>
467
+ drop(n: number): LazyList<A>
468
+ takeWhile(predicate: (a: A) => boolean): LazyList<A>
469
+ dropWhile(predicate: (a: A) => boolean): LazyList<A>
470
+ concat(other: LazyList<A>): LazyList<A>
471
+ zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>
472
+
473
+ // Terminal operations (force evaluation)
474
+ toList(): List<A>
475
+ toArray(): A[]
476
+ forEach(f: (a: A) => void): void
477
+ reduce<B extends Type>(f: (acc: B, a: A) => B, initial: B): B
478
+ find(predicate: (a: A) => boolean): Option<A>
479
+ some(predicate: (a: A) => boolean): boolean
480
+ every(predicate: (a: A) => boolean): boolean
481
+ count(): number
482
+ first(): Option<A>
483
+ last(): Option<A>
484
+
485
+ // Additional methods for clarity
486
+ toString(): string
487
+ }`,TaskOutcome:`export interface TaskOutcome<T>
488
+ extends FunctypeBase<T, "Ok" | "Err">, Extractable<T>, AsyncMonad<T>, Promisable<T>, Doable<T> {
489
+ readonly _tag: "Ok" | "Err"
490
+ readonly _meta: TaskMetadata
491
+
492
+ // Value access
493
+ readonly value?: T
494
+ readonly error?: Throwable
495
+
496
+ // Functional methods
497
+ readonly map: <U>(f: (value: T) => U) => TaskOutcome<U>
498
+ readonly flatMap: <U>(f: (value: T) => TaskOutcome<U> | Either<Throwable, U>) => TaskOutcome<U>
499
+ readonly ap: <U>(ff: TaskOutcome<(value: T) => U>) => TaskOutcome<U>
500
+ readonly mapAsync: <U>(f: (value: T) => Promise<U>) => Promise<TaskOutcome<U>>
501
+ readonly flatMapAsync: <U>(f: (value: T) => Promise<TaskOutcome<U>>) => Promise<TaskOutcome<U>>
502
+
503
+ // Error handling methods
504
+ readonly mapError: (f: (error: Throwable) => Throwable) => TaskOutcome<T>
505
+ readonly recover: (value: T) => Ok<T>
506
+ readonly recoverWith: (f: (error: Throwable) => T) => Ok<T>
507
+
508
+ // Type guards
509
+ readonly isSuccess: () => this is Ok<T>
510
+ readonly isFailure: () => this is Err<T>
511
+ readonly isOk: () => this is Ok<T>
512
+ readonly isErr: () => this is Err<T>
513
+
514
+ // Conversion methods
515
+ readonly toEither: () => Either<Throwable, T>
516
+ readonly toTry: () => Try<T>
517
+ readonly toOption: () => Option<T>
518
+ readonly toList: () => List<T>
519
+
520
+ // Pattern matching
521
+ readonly fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U) => U
522
+ readonly match: <U>(patterns: { Ok: (value: T) => U; Err: (error: Throwable) => U }) => U
523
+ }`,FPromise:`export type FPromise<T extends Type, E extends Type = unknown> = PromiseLike<T> & {
524
+ readonly _tag: "FPromise"
525
+
526
+ // FPromise methods
527
+ tap: (f: (value: T) => void) => FPromise<T, E>
528
+ mapError: <E2>(f: (error: E, context: ErrorContext) => E2) => FPromise<T, E2>
529
+ tapError: (f: (error: E) => void) => FPromise<T, E>
530
+ recover: (fallback: T) => FPromise<T, never>
531
+ recoverWith: (f: (error: E) => T) => FPromise<T, never>
532
+ recoverWithF: <E2>(f: (error: E) => FPromise<T, E2>) => FPromise<T, E2>
533
+ filterError: <E2 extends E>(
534
+ predicate: (error: E) => boolean,
535
+ handler: (error: E) => FPromise<T, E2>,
536
+ ) => FPromise<T, E>
537
+ logError: (logger: (error: E, context: ErrorContext) => void) => FPromise<T, E>
538
+ toPromise: () => Promise<T>
539
+ toEither: () => Promise<Either<E, T>>
540
+ fold: <R extends Type>(onError: (error: E) => R, onSuccess: (value: T) => R) => FPromise<R, never>
541
+
542
+ // Functor implementation
543
+ map: <U extends Type>(f: (value: T) => U) => FPromise<U, E>
544
+
545
+ // AsyncFunctor implementation
546
+ flatMap: <U extends Type>(f: (value: T) => FPromise<U, E> | PromiseLike<U>) => FPromise<U, E>
547
+ flatMapAsync: <U extends Type>(f: (value: T) => PromiseLike<U>) => Promise<U>
548
+ }`,Tuple:`export interface Tuple<T extends Type[]>
549
+ extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
550
+ get<K extends number>(index: K): T[K]
551
+
552
+ map<U extends Type[]>(f: (value: T) => U): Tuple<U>
553
+
554
+ flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>
555
+
556
+ toArray(): T
557
+
558
+ length: number
559
+
560
+ [Symbol.iterator](): Iterator<T[number]>
561
+
562
+ toString(): string
563
+
564
+ toValue(): { _tag: "Tuple"; value: T }
565
+ }`,Stack:`export type Stack<A extends Type> = {
566
+ /**
567
+ * Push a value onto the top of the stack
568
+ * @param value - The value to push
569
+ * @returns A new Stack with the value added
570
+ */
571
+ push(value: A): Stack<A>
572
+
573
+ /**
574
+ * Remove and return the top value from the stack
575
+ * @returns A tuple containing the new Stack and the value
576
+ */
577
+ pop(): [Stack<A>, Option<A>]
578
+
579
+ /**
580
+ * Return the top value without removing it
581
+ * @returns The top value wrapped in an Option
582
+ */
583
+ peek(): Option<A>
584
+
585
+ /**
586
+ * Transforms each element in the stack using the provided function
587
+ * @param f - The mapping function
588
+ * @returns A new Stack with transformed elements
589
+ */
590
+ map<B extends Type>(f: (a: A) => B): Stack<B>
591
+
592
+ /**
593
+ * Maps each element to a Stack and flattens the result
594
+ * @param f - The mapping function returning a Stack
595
+ * @returns A new flattened Stack
596
+ */
597
+ flatMap<B extends Type>(f: (a: A) => Stack<B>): Stack<B>
598
+
599
+ /**
600
+ * Applies a Stack of functions to this Stack
601
+ * @param ff - Stack of functions to apply
602
+ * @returns A new Stack with applied functions
603
+ */
604
+ ap<B extends Type>(ff: Stack<(value: A) => B>): Stack<B>
605
+
606
+ /**
607
+ * Maps each element to an async Stack and flattens the result
608
+ * @param f - The async mapping function returning a Stack
609
+ * @returns A promise of the new flattened Stack
610
+ */
611
+ flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Stack<B>>): PromiseLike<Stack<B>>
612
+
613
+ /**
614
+ * Convert the stack to a List
615
+ * @returns A List containing all elements
616
+ */
617
+ toList(): List<A>
618
+
619
+ /**
620
+ * Convert the stack to an array
621
+ * @returns An array of all elements
622
+ */
623
+ toArray(): A[]
624
+
625
+ /**
626
+ * Returns a string representation of the stack
627
+ * @returns A string representation
628
+ */
629
+ toString(): string
630
+
631
+ /**
632
+ * Pattern matches over the Stack, applying a handler function based on whether it's empty
633
+ * @param patterns - Object with handler functions for Empty and NonEmpty variants
634
+ * @returns The result of applying the matching handler function
635
+ */
636
+ match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
637
+ } & Traversable<A> &`},g=e=>{let n=t(e.slice(2));return{flags:{json:n.includes(`--json`),full:n.includes(`--full`),help:n.exists(e=>e===`--help`||e===`-h`)},args:n.filter(e=>!e.startsWith(`--`)&&e!==`-h`)}},_=e=>n(h[e]).or(t(Object.entries(h)).find(([t])=>t.toLowerCase()===e.toLowerCase()).map(([,e])=>e)),v=()=>{let e=t([`FULL INTERFACE DEFINITIONS`,`=`.repeat(60),``]);return t(Object.entries(h)).foldLeft(e)((e,[n,r])=>e.concat(t([`// ${n}`,r,``,`-`.repeat(60),``]))).toArray().join(`
638
+ `).trimEnd()},y=()=>{console.log(`functype - API documentation for LLMs
639
+
640
+ USAGE
641
+ npx functype Show overview of all types
642
+ npx functype <Type> Show detailed type documentation
643
+ npx functype interfaces Show interface reference
644
+
645
+ OPTIONS
646
+ --full Show full TypeScript interface with JSDoc
647
+ --json Output as JSON instead of markdown
648
+ --help, -h Show this help message
649
+
650
+ EXAMPLES
651
+ npx functype # Overview of all data structures
652
+ npx functype Option # Detailed Option documentation
653
+ npx functype either # Case-insensitive lookup
654
+ npx functype interfaces # All interface definitions
655
+ npx functype --json # Overview as JSON
656
+ npx functype Option --json # Option as JSON
657
+ npx functype Option --full # Full TypeScript interface
658
+ npx functype --full # All full interfaces (large output!)
659
+ `)},b=e=>{console.error(`Unknown type: ${e}`),console.error(``),console.error(`Available types: ${p().join(`, `)}`),console.error(``),console.error(`Use: npx functype interfaces - for interface reference`),process.exit(1)},x=e=>console.log(e),S=(t,r)=>n(f(t)).fold(()=>b(t),t=>e(r.full).when(!0,()=>_(t.name).fold(()=>x(r.json?u({[t.name]:t.data}):c(t.name,t.data)),e=>x(r.json?u({[t.name]:{...t.data,fullInterface:e}}):e))).default(()=>x(r.json?u({[t.name]:t.data}):c(t.name,t.data))));(()=>{let{flags:t,args:n}=g(process.argv);e(!0).when(t.help,()=>y()).when(n.isEmpty(),()=>e(t.full).when(!0,()=>x(t.json?u(h):v())).default(()=>x(t.json?u(d()):s()))).when(n.head().contains(`interfaces`),()=>x(t.json?u(m()):l())).default(()=>n.head().fold(()=>x(t.json?u(d()):s()),e=>S(e,t)))})();
660
+ //# sourceMappingURL=index.js.map