functype 0.46.1 → 0.47.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/dist/cli/index.js CHANGED
@@ -1,645 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{P as e}from"../Valuable-BlffnwkD.js";import{Option as t}from"../option/index.js";import{List as n}from"../list/index.js";const r=`0.46.1`,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)`,`.takeWhile(p)`,`.takeRight(n)`,`.drop(n)`,`.dropWhile(p)`,`.concat(list)`,`.reverse()`,`.distinct()`,`.sorted()`,`.sortBy(f)`,`.zip(list)`,`.zipWithIndex()`,`.prepend(v)`,`.slice(s, e)`],extract:[`.fold(z, f)`,`.reduce(f)`,`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.indexOf(v)`,`.toArray()`],check:[`.isEmpty`,`.nonEmpty`,`.size`,`.contains(v)`],other:[`.groupBy(f)`,`.partition(p)`,`.span(p)`]}},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)`,`.add(v)`],extract:[`.fold(z, f)`,`.toArray()`],check:[`.has(v)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:[`SafeTraversable`,`Collection`,`Serializable`],methods:{create:[`Map([[k, v], ...])`,`Map.of([k, v], ...)`,`Map.empty()`],transform:[`.set(k, v)`,`.delete(k)`,`.map(f)`,`.filter(p)`,`.add(k, v)`],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)`,`.takeRight(n)`,`.drop(n)`,`.takeWhile(p)`,`.dropWhile(p)`,`.concat(ll)`,`.reverse()`,`.distinct()`,`.zip(ll)`,`.zipWithIndex()`],extract:[`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.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)`]}},IO:{description:`Lazy effect type with typed errors and dependency injection`,interfaces:[`Functor`,`Monad`,`Foldable`,`Matchable`],methods:{create:[`IO(() => v)`,`IO.succeed(v)`,`IO.fail(e)`,`IO.sync(f)`,`IO.async(f)`,`IO.tryPromise({try, catch})`,`IO.fromEither(e)`,`IO.fromOption(o)`,`IO.fromTry(t)`],transform:[`.map(f)`,`.flatMap(f)`,`.tap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.run()`,`.runOrThrow()`,`.runSync()`,`.runSyncOrThrow()`,`.runExit()`,`.runOption()`,`.runTry()`,`.fold(onErr, onOk)`,`.match({failure, success})`],check:[],other:[`.catchTag(tag, f)`,`.catchAll(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`,`.delay(ms)`,`.zip(io)`,`.pipe(f)`,`IO.all([...])`,`IO.race([...])`,`IO.bracket(acquire, use, release)`,`IO.gen(function*() {...})`,`IO.Do.bind().map()`,`IO.service(Tag)`,`.provideService(Tag, impl)`,`.provideLayer(layer)`]}},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`],Effect:[`IO`,`Task`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`]},s=()=>{let e=n([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return n(Object.entries(o)).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
- `)},c=(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(`
4
- `).trimEnd()},l=()=>{let e=n([`INTERFACES`,``]);return n(Object.entries(a)).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()},u=e=>JSON.stringify(e,null,2),d=()=>({version:r,categories:o,types:i}),f=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(),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
- take: (n: number) => List<A>
258
- takeWhile: (p: (a: A) => boolean) => List<A>
259
- takeRight: (n: number) => List<A>
260
- get last(): A | undefined
261
- get lastOption(): Option<A>
262
- get tail(): List<A>
263
- get init(): List<A>
264
- reverse: () => List<A>
265
- indexOf: (value: A) => number
266
- prepend: (item: A) => List<A>
267
- distinct: () => List<A>
268
- sorted: (compareFn?: (a: A, b: A) => number) => List<A>
269
- sortBy: <B>(f: (a: A) => B, compareFn?: (a: B, b: B) => number) => List<A>
270
- zip: <B>(other: List<B>) => List<[A, B]>
271
- zipWithIndex: () => List<[A, number]>
272
- groupBy: <K>(f: (a: A) => K) => globalThis.Map<K, List<A>>
273
- partition: (p: (a: A) => boolean) => [List<A>, List<A>]
274
- span: (p: (a: A) => boolean) => [List<A>, List<A>]
275
- slice: (start: number, end: number) => List<A>
276
- /**
277
- * Pattern matches over the List, applying a handler function based on whether it's empty
278
- * @param patterns - Object with handler functions for Empty and NonEmpty variants
279
- * @returns The result of applying the matching handler function
280
- */
281
- match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
282
- }`,Set:`export interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
283
- add: (value: A) => Set<A>
284
- remove: (value: A) => Set<A>
285
- contains: (value: A) => boolean
286
- has: (value: A) => boolean
287
- map: <B>(f: (a: A) => B) => Set<B>
288
- flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>
289
- filter: (p: (a: A) => boolean) => Set<A>
290
- filterNot: (p: (a: A) => boolean) => Set<A>
291
- fold: <U extends Type>(onEmpty: () => U, onValue: (value: A) => U) => U
292
- toList: () => List<A>
293
- toSet: () => Set<A>
294
- toArray: <B = A>() => B[]
295
- toString: () => string
296
- }`,Map:`export interface Map<K, V>
297
- extends
298
- SafeTraversable<K, V>,
299
- Collection<Tuple<[K, V]>>,
300
- Typeable<"Map">,
301
- Serializable<[K, V][]>,
302
- Pipe<[K, V][]>,
303
- Foldable<Tuple<[K, V]>>,
304
- Iterable<[K, V]> {
305
- readonly _tag: "Map"
306
- add(item: Tuple<[K, V]>): Map<K, V>
307
- remove(value: K): Map<K, V>
308
- map<U>(f: (value: V) => U): Map<K, U>
309
- ap<U>(ff: Map<K, (value: V) => U>): Map<K, U>
310
- flatMap<K2, V2>(f: (entry: Tuple<[K, V]>) => Iterable<[K2, V2]>): Map<K2, V2>
311
- flatMapAsync<U>(f: (value: V) => PromiseLike<Map<K, U>>): PromiseLike<Map<K, U>>
312
- get(key: K): Option<V>
313
- getOrElse(key: K, defaultValue: V): V
314
- orElse(key: K, alternative: Option<V>): Option<V>
315
- fold<U extends Type>(onEmpty: () => U, onValue: (value: Tuple<[K, V]>) => U): U
316
- foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K, V]>) => B) => B
317
- foldRight<B>(z: B): (op: (a: Tuple<[K, V]>, b: B) => B) => B
318
- /**
319
- * Pattern matches over the Map, applying a handler function based on whether it's empty
320
- * @param patterns - Object with handler functions for Empty and NonEmpty variants
321
- * @returns The result of applying the matching handler function
322
- */
323
- match<R>(patterns: { Empty: () => R; NonEmpty: (entries: Array<Tuple<[K, V]>>) => R }): R
324
- toValue(): { _tag: "Map"; value: [K, V][] }
325
- }`,Lazy:`export interface Lazy<T extends Type> extends FunctypeBase<T, "Lazy">, Extractable<T>, Pipe<T> {
326
- /** Tag identifying this as a Lazy type */
327
- readonly _tag: "Lazy"
328
- /** Whether the computation has been evaluated */
329
- readonly isEvaluated: boolean
330
- /**
331
- * Returns the computed value or a default value if computation fails
332
- * @param defaultValue - The value to return if computation fails
333
- * @returns The computed value or defaultValue
334
- */
335
- orElse(defaultValue: T): T
336
- /**
337
- * Returns the computed value or null if computation fails
338
- * @returns The computed value or null
339
- */
340
- orNull(): T | null
341
- /**
342
- * Returns the computed value or throws an error if computation fails
343
- * @param error - Optional custom error to throw. If not provided, throws the computation error or a default error
344
- * @returns The computed value
345
- * @throws The specified error, computation error, or a default error
346
- */
347
- orThrow(error?: Error): T
348
- /**
349
- * Returns this Lazy if computation succeeds, otherwise returns the alternative Lazy
350
- * @param alternative - The alternative Lazy to use if computation fails
351
- * @returns This Lazy or the alternative
352
- */
353
- or(alternative: Lazy<T>): Lazy<T>
354
- /**
355
- * Maps the value inside the Lazy using the provided function
356
- * @param f - The mapping function
357
- * @returns A new Lazy containing the mapped value
358
- */
359
- map<U extends Type>(f: (value: T) => U): Lazy<U>
360
- /**
361
- * Applies a wrapped function to a wrapped value (Applicative pattern)
362
- * @param ff - A Lazy containing a function from T to U
363
- * @returns A new Lazy containing the result
364
- */
365
- ap<U extends Type>(ff: Lazy<(value: T) => U>): Lazy<U>
366
- /**
367
- * Maps the value inside the Lazy using an async function
368
- * @param f - The async mapping function
369
- * @returns A Promise of a new Lazy containing the mapped value
370
- */
371
- mapAsync<U extends Type>(f: (value: T) => Promise<U>): Promise<Lazy<U>>
372
- /**
373
- * Maps the value using a function that returns a Lazy
374
- * @param f - The mapping function returning a Lazy
375
- * @returns A new Lazy containing the flattened result
376
- */
377
- flatMap<U extends Type>(f: (value: T) => Lazy<U>): Lazy<U>
378
- /**
379
- * Maps the value using an async function that returns a Lazy
380
- * @param f - The async mapping function returning a Lazy
381
- * @returns A Promise of a new Lazy containing the flattened result
382
- */
383
- flatMapAsync<U extends Type>(f: (value: T) => Promise<Lazy<U>>): Promise<Lazy<U>>
384
- /**
385
- * Returns a Lazy that filters the value based on a predicate
386
- * @param predicate - The predicate function
387
- * @returns A Lazy containing an Option of the value
388
- */
389
- filter(predicate: (value: T) => boolean): Lazy<Option<T>>
390
- /**
391
- * Recovers from a failed computation by providing an alternative value
392
- * @param f - Function that takes the error and returns a recovery value
393
- * @returns A new Lazy that will use the recovery function if computation fails
394
- */
395
- recover(f: (error: unknown) => T): Lazy<T>
396
- /**
397
- * Recovers from a failed computation by providing an alternative Lazy
398
- * @param f - Function that takes the error and returns a recovery Lazy
399
- * @returns A new Lazy that will use the recovery Lazy if computation fails
400
- */
401
- recoverWith(f: (error: unknown) => Lazy<T>): Lazy<T>
402
- /**
403
- * Evaluates the computation and returns it as an Option
404
- * @returns Some containing the value if successful, None if computation fails
405
- */
406
- toOption(): Option<T>
407
- /**
408
- * Evaluates the computation and returns it as an Either
409
- * @returns Right containing the value if successful, Left containing the error if computation fails
410
- */
411
- toEither(): Either<unknown, T>
412
- /**
413
- * Evaluates the computation and returns it as an Either with a mapped error
414
- * @param mapError - Function to map the error
415
- * @returns Right containing the value if successful, Left containing the mapped error if computation fails
416
- */
417
- toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T>
418
- /**
419
- * Evaluates the computation and returns it as a Try
420
- * @returns Try containing the result of the computation
421
- */
422
- toTry(): Try<T>
423
- /**
424
- * Applies an effect function to the value if computation succeeds
425
- * @param f - The effect function
426
- * @returns This Lazy for chaining
427
- */
428
- tap(f: (value: T) => void): Lazy<T>
429
- /**
430
- * Applies an effect function to the error if computation fails
431
- * @param f - The effect function for errors
432
- * @returns This Lazy for chaining
433
- */
434
- tapError(f: (error: unknown) => void): Lazy<T>
435
- /**
436
- * Pattern matching on the Lazy value
437
- * @param f - Function to apply to the computed value
438
- * @returns The result of applying f to the computed value
439
- */
440
- fold<U>(f: (value: T) => U): U
441
- /**
442
- * Pattern matching with success and failure handlers
443
- * @param onFailure - Function to handle computation failure
444
- * @param onSuccess - Function to handle successful computation
445
- * @returns The result of the appropriate handler
446
- */
447
- foldWith<U>(onFailure: (error: unknown) => U, onSuccess: (value: T) => U): U
448
- /**
449
- * Left fold operation
450
- * @param z - Initial value
451
- * @returns Function that takes an operator and applies it
452
- */
453
- foldLeft: <B>(z: B) => (op: (b: B, a: T) => B) => B
454
- /**
455
- * Right fold operation
456
- * @param z - Initial value
457
- * @returns Function that takes an operator and applies it
458
- */
459
- foldRight: <B>(z: B) => (op: (a: T, b: B) => B) => B
460
- /**
461
- * Pattern matching for the Lazy type
462
- * @param patterns - Object with handler for Lazy pattern
463
- * @returns The result of the matched handler
464
- */
465
- match<R>(patterns: { Lazy: (value: T) => R }): R
466
- /**
467
- * Creates a string representation of the Lazy
468
- * @returns String representation showing evaluation status
469
- */
470
- toString(): string
471
- /**
472
- * Converts the Lazy to a value object
473
- * @returns Object representation of the Lazy with evaluation state
474
- */
475
- toValue(): { _tag: "Lazy"; evaluated: boolean; value?: T }
476
- }`,LazyList:`export interface LazyList<A extends Type>
477
- extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
478
- // Iterator protocol
479
- [Symbol.iterator](): Iterator<A>
480
-
481
- // Lazy operations
482
- map<B extends Type>(f: (a: A) => B): LazyList<B>
483
- flatMap<B extends Type>(f: (a: A) => LazyList<B>): LazyList<B>
484
- filter(predicate: (a: A) => boolean): LazyList<A>
485
- take(n: number): LazyList<A>
486
- drop(n: number): LazyList<A>
487
- takeWhile(predicate: (a: A) => boolean): LazyList<A>
488
- dropWhile(predicate: (a: A) => boolean): LazyList<A>
489
- concat(other: LazyList<A>): LazyList<A>
490
- zip<B extends Type>(other: LazyList<B>): LazyList<[A, B]>
491
-
492
- takeRight(n: number): LazyList<A>
493
- reverse(): LazyList<A>
494
- distinct(): LazyList<A>
495
- zipWithIndex(): LazyList<[A, number]>
496
-
497
- // Element access (properties)
498
- get head(): A | undefined
499
- get headOption(): Option<A>
500
- get last(): A | undefined
501
- get lastOption(): Option<A>
502
- get tail(): LazyList<A>
503
- get init(): LazyList<A>
504
-
505
- // Terminal operations (force evaluation)
506
- toList(): List<A>
507
- toArray(): A[]
508
- forEach(f: (a: A) => void): void
509
- reduce<B extends Type>(f: (acc: B, a: A) => B, initial: B): B
510
- find(predicate: (a: A) => boolean): Option<A>
511
- some(predicate: (a: A) => boolean): boolean
512
- every(predicate: (a: A) => boolean): boolean
513
- count(): number
514
-
515
- // Additional methods for clarity
516
- toString(): string
517
- }`,TaskOutcome:`export interface TaskOutcome<T>
518
- extends FunctypeBase<T, "Ok" | "Err">, Extractable<T>, AsyncMonad<T>, Promisable<T>, Doable<T> {
519
- readonly _tag: "Ok" | "Err"
520
- readonly _meta: TaskMetadata
521
-
522
- // Value access
523
- readonly value?: T
524
- readonly error?: Throwable
525
-
526
- // Functional methods
527
- readonly map: <U>(f: (value: T) => U) => TaskOutcome<U>
528
- readonly flatMap: <U>(f: (value: T) => TaskOutcome<U> | Either<Throwable, U>) => TaskOutcome<U>
529
- readonly ap: <U>(ff: TaskOutcome<(value: T) => U>) => TaskOutcome<U>
530
- readonly mapAsync: <U>(f: (value: T) => Promise<U>) => Promise<TaskOutcome<U>>
531
- readonly flatMapAsync: <U>(f: (value: T) => Promise<TaskOutcome<U>>) => Promise<TaskOutcome<U>>
532
-
533
- // Error handling methods
534
- readonly mapError: (f: (error: Throwable) => Throwable) => TaskOutcome<T>
535
- readonly recover: (value: T) => Ok<T>
536
- readonly recoverWith: (f: (error: Throwable) => T) => Ok<T>
537
-
538
- // Type guards
539
- readonly isSuccess: () => this is Ok<T>
540
- readonly isFailure: () => this is Err<T>
541
- readonly isOk: () => this is Ok<T>
542
- readonly isErr: () => this is Err<T>
543
-
544
- // Conversion methods
545
- readonly toEither: () => Either<Throwable, T>
546
- readonly toTry: () => Try<T>
547
- readonly toOption: () => Option<T>
548
- readonly toList: () => List<T>
549
-
550
- // Pattern matching
551
- readonly fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U) => U
552
- readonly match: <U>(patterns: { Ok: (value: T) => U; Err: (error: Throwable) => U }) => U
553
- }`,Tuple:`export interface Tuple<T extends Type[]>
554
- extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
555
- get<K extends number>(index: K): T[K]
556
-
557
- map<U extends Type[]>(f: (value: T) => U): Tuple<U>
558
-
559
- flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>
560
-
561
- toArray(): T
562
-
563
- length: number
564
-
565
- [Symbol.iterator](): Iterator<T[number]>
566
-
567
- toString(): string
568
-
569
- toValue(): { _tag: "Tuple"; value: T }
570
- }`,Stack:`export type Stack<A extends Type> = {
571
- /**
572
- * Push a value onto the top of the stack
573
- * @param value - The value to push
574
- * @returns A new Stack with the value added
575
- */
576
- push(value: A): Stack<A>
577
-
578
- /**
579
- * Remove and return the top value from the stack
580
- * @returns A tuple containing the new Stack and the value
581
- */
582
- pop(): [Stack<A>, Option<A>]
583
-
584
- /**
585
- * Return the top value without removing it
586
- * @returns The top value wrapped in an Option
587
- */
588
- peek(): Option<A>
589
-
590
- /**
591
- * Transforms each element in the stack using the provided function
592
- * @param f - The mapping function
593
- * @returns A new Stack with transformed elements
594
- */
595
- map<B extends Type>(f: (a: A) => B): Stack<B>
596
-
597
- /**
598
- * Maps each element to a Stack and flattens the result
599
- * @param f - The mapping function returning a Stack
600
- * @returns A new flattened Stack
601
- */
602
- flatMap<B extends Type>(f: (a: A) => Stack<B>): Stack<B>
603
-
604
- /**
605
- * Applies a Stack of functions to this Stack
606
- * @param ff - Stack of functions to apply
607
- * @returns A new Stack with applied functions
608
- */
609
- ap<B extends Type>(ff: Stack<(value: A) => B>): Stack<B>
610
-
611
- /**
612
- * Maps each element to an async Stack and flattens the result
613
- * @param f - The async mapping function returning a Stack
614
- * @returns A promise of the new flattened Stack
615
- */
616
- flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Stack<B>>): PromiseLike<Stack<B>>
617
-
618
- /**
619
- * Convert the stack to a List
620
- * @returns A List containing all elements
621
- */
622
- toList(): List<A>
623
-
624
- /**
625
- * Convert the stack to an array
626
- * @returns An array of all elements
627
- */
628
- toArray(): A[]
629
-
630
- /**
631
- * Returns a string representation of the stack
632
- * @returns A string representation
633
- */
634
- toString(): string
635
-
636
- /**
637
- * Pattern matches over the Stack, applying a handler function based on whether it's empty
638
- * @param patterns - Object with handler functions for Empty and NonEmpty variants
639
- * @returns The result of applying the matching handler function
640
- */
641
- match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
642
- } & Traversable<A> &`},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(h[e]).or(n(Object.entries(h)).find(([t])=>t.toLowerCase()===e.toLowerCase()).map(([,e])=>e)),v=()=>{let e=n([`FULL INTERFACE DEFINITIONS`,`=`.repeat(60),``]);return n(Object.entries(h)).foldLeft(e)((e,[t,r])=>e.concat(n([`// ${t}`,r,``,`-`.repeat(60),``]))).toArray().join(`
2
+ import{P as e}from"../Valuable-DeccMyYD.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-D7DbT-2A.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(`
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(`
643
6
  `).trimEnd()},y=()=>{console.log(`functype - API documentation for LLMs
644
7
 
645
8
  USAGE
@@ -661,4 +24,4 @@ EXAMPLES
661
24
  npx functype Option --json # Option as JSON
662
25
  npx functype Option --full # Full TypeScript interface
663
26
  npx functype --full # All full interfaces (large output!)
664
- `)},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=(e,n)=>t(f(e)).fold(()=>b(e),e=>{n.full?_(e.name).fold(()=>x(n.json?u({[e.name]:e.data}):c(e.name,e.data)),t=>x(n.json?u({[e.name]:{...e.data,fullInterface:t}}):t)):x(n.json?u({[e.name]:e.data}):c(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?u(h):v()):x(t.json?u(d()):s())).when(()=>n.headOption.contains(`interfaces`),()=>x(t.json?u(m()):l())).default(()=>n.headOption.fold(()=>x(t.json?u(d()):s()),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=(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)))})();