functype 0.58.0 → 0.59.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/{Tuple-DwyoW0ZP.d.ts → Tuple-CPZd_XgN.d.ts} +3 -3
- package/dist/cli/exports.js +1 -1
- package/dist/cli/index.js +5 -5
- package/dist/do/index.d.ts +1 -1
- package/dist/do/index.js +1 -1
- package/dist/either/index.d.ts +1 -1
- package/dist/either/index.js +1 -1
- package/dist/{full-interfaces-CiSsM7TZ.js → full-interfaces-B2NCRIHu.js} +31 -46
- package/dist/{index-nHF45wRc.d.ts → index-DeOx26aF.d.ts} +150 -68
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/list/index.d.ts +1 -1
- package/dist/list/index.js +1 -1
- package/dist/map/index.d.ts +1 -1
- package/dist/map/index.js +1 -1
- package/dist/option/index.d.ts +1 -1
- package/dist/option/index.js +1 -1
- package/dist/set/index.d.ts +1 -1
- package/dist/set/index.js +1 -1
- package/dist/src-Co3npRp-.js +19 -0
- package/dist/try/index.d.ts +1 -1
- package/dist/try/index.js +1 -1
- package/dist/tuple/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/src-Dfm6mrTr.js +0 -19
|
@@ -15,7 +15,7 @@ type Type = unknown;
|
|
|
15
15
|
*
|
|
16
16
|
* @typeParam A - The type of elements in the data structure
|
|
17
17
|
*/
|
|
18
|
-
interface Foldable<A> {
|
|
18
|
+
interface Foldable<out A> {
|
|
19
19
|
/**
|
|
20
20
|
* Left-associative fold using the provided zero value and operation
|
|
21
21
|
* @param z - Zero/identity value
|
|
@@ -35,7 +35,7 @@ interface Foldable<A> {
|
|
|
35
35
|
* Pipe interface for functional data structures
|
|
36
36
|
* @typeParam T - The type of value to pipe
|
|
37
37
|
*/
|
|
38
|
-
interface Pipe<T extends Type> {
|
|
38
|
+
interface Pipe<out T extends Type> {
|
|
39
39
|
/**
|
|
40
40
|
* Pipes the value through the provided function
|
|
41
41
|
* @param f - The function to apply to the value
|
|
@@ -54,7 +54,7 @@ interface SerializationMethods<T> {
|
|
|
54
54
|
toYAML(): string;
|
|
55
55
|
toBinary(): string;
|
|
56
56
|
}
|
|
57
|
-
interface Serializable<T> {
|
|
57
|
+
interface Serializable<out T> {
|
|
58
58
|
serialize(): SerializationMethods<T>;
|
|
59
59
|
}
|
|
60
60
|
//#endregion
|
package/dist/cli/exports.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n,r,t as i}from"../full-interfaces-
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"../full-interfaces-B2NCRIHu.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{
|
|
3
|
-
`)},l=(
|
|
4
|
-
`).trimEnd()},u=()=>{let e=
|
|
5
|
-
`).trimEnd()},d=e=>JSON.stringify(e,null,2),f=()=>({version:r,categories:a,types:i}),p=
|
|
2
|
+
import{J as e,kt as t,yt as n}from"../src-Co3npRp-.js";import{a as r,i,n as a,r as o,t as s}from"../full-interfaces-B2NCRIHu.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(`
|
|
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=(
|
|
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)))})();
|
package/dist/do/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as EmptyListError, c as LeftError,
|
|
1
|
+
import { a as EmptyListError, c as LeftError, d as isDoCapable, dr as Doable, 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, ur as DoResult } from "../index-DeOx26aF.js";
|
|
2
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{
|
|
1
|
+
import{F as e,I as t,L as n,M as r,N as i,P as a,R as o,j as s,z as c}from"../src-Co3npRp-.js";export{s as $,r as Do,i as DoAsync,a as EmptyListError,e as FailureError,t as LeftError,n as NoneError,o as isDoCapable,c as unwrap};
|
package/dist/either/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as isRight, S as isLeft, T as tryCatchAsync, _ as Right, b as TypeCheckLeft, g as LeftOf, h as Left, m as EitherBase, p as Either, v as RightOf, w as tryCatch, x as TypeCheckRight, y as TestEither } from "../index-
|
|
1
|
+
import { C as isRight, S as isLeft, T as tryCatchAsync, _ as Right, b as TypeCheckLeft, g as LeftOf, h as Left, m as EitherBase, p as Either, v as RightOf, w as tryCatch, x as TypeCheckRight, y as TestEither } from "../index-DeOx26aF.js";
|
|
2
2
|
export { Either, EitherBase, Left, LeftOf, Right, RightOf, TestEither, TypeCheckLeft, TypeCheckRight, isLeft, isRight, tryCatch, tryCatchAsync };
|
package/dist/either/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_t as e,dt as t,ft as n,gt as r,ht as i,mt as a,pt as o,ut as s,vt as c}from"../src-Co3npRp-.js";export{s as Either,t as Left,n as Right,o as TypeCheckLeft,a as TypeCheckRight,i as isLeft,r as isRight,e as tryCatch,c as tryCatchAsync};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const e=`0.
|
|
2
|
-
extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>,
|
|
1
|
+
const e=`0.59.0`,t={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)`,`.foldAsync(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)`,`Either.void()`],transform:[`.map(f)`,`.flatMap(f)`,`.mapLeft(f)`,`.swap()`],extract:[`.fold(l, r)`,`.foldAsync(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)`,`Try.success(v)`,`Try.failure(e)`,`Try.fromPromise(p)`],transform:[`.map(f)`,`.flatMap(f)`,`.recover(f)`,`.recoverWith(f)`],extract:[`.fold(f, s)`,`.foldAsync(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`]}},Obj:{description:`Immutable object wrapper with fluent operations`,interfaces:[`KVTraversable`,`Foldable`,`Matchable`,`Extractable`,`Serializable`,`Reshapeable`,`Doable`],methods:{create:[`Obj({...})`,`Obj.of({...})`,`Obj.empty()`],transform:[`.set(k, v)`,`.assign(partial)`,`.merge(obj)`,`.when(cond, partial)`,`.omit(...keys)`,`.pick(...keys)`,`.map(f)`,`.flatMap(f)`],extract:[`.get(k)`,`.value()`,`.keys()`,`.values()`,`.entries()`,`.fold(n, s)`,`.match({Obj})`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:[`KVTraversable`,`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 tracking. Returns TaskOutcome<T> (Ok/Err) which implements Functor, AsyncMonad, Foldable, Extractable, Serializable`,interfaces:[],methods:{create:[`Task(params).Async(fn, errFn)`,`Task(params).Sync(fn, errFn)`,`Task.ok(value)`,`Task.err(error)`,`Task.fromEither(either)`,`Task.fromTry(try)`,`Task.fromPromise(fn)`,`Task.fromNodeCallback(fn)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.fold(onErr, onOk)`,`.match({Ok, Err})`,`.orElse(v)`,`.orThrow()`,`.toEither()`,`.toOption()`],other:[`Task.cancellable(fn)`,`Task.withProgress(fn, onProgress)`,`Task.race(tasks, timeout?)`,`Task.getErrorChain(error)`,`Task.formatErrorChain(error)`]}},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`]}},Http:{description:`HTTP fetch wrapper returning IO<never, HttpError, HttpResponse<unknown>> by default. Provide a validate function to get typed responses (BYOV: bring your own validator). Works with Zod, TypeBox, Valibot, or manual validators.`,interfaces:[],methods:{create:[`Http.get(url, { validate }?)`,`Http.post(url, { body, validate }?)`,`Http.put(url, { body, validate }?)`,`Http.patch(url, { body, validate }?)`,`Http.delete(url, { validate }?)`,`Http.request({ url, validate })`,`Http.client(config)`],transform:[`.map(f)`,`.flatMap(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`],extract:[`.run()`,`.runOrThrow()`,`.runOption()`,`.runTry()`],check:[],other:[`.catchTag(tag, handler)`,`.catchAll(handler)`,`.mapError(f)`,`.recover(fallback)`]}},HttpError:{description:`Three-variant ADT for HTTP failures: NetworkError | HttpStatusError | DecodeError`,interfaces:[],methods:{create:[`HttpError.networkError(url, method, cause)`,`HttpError.httpStatusError(url, method, status, statusText, body)`,`HttpError.decodeError(url, method, body, cause)`],check:[`HttpError.isNetworkError(e)`,`HttpError.isHttpStatusError(e)`,`HttpError.isDecodeError(e)`],other:[`HttpError.match(error, { NetworkError, HttpStatusError, DecodeError })`]}}},n={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`]}},r={Core:[`Option`,`Either`,`Try`,`Obj`],Collection:[`List`,`Set`,`Map`,`LazyList`,`Tuple`,`Stack`],Effect:[`IO`,`Task`,`Http`,`HttpError`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`]},i={Option:`export interface Option<out T extends Type>
|
|
2
|
+
extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
3
3
|
/** The contained value (undefined for None) */
|
|
4
4
|
readonly value: T | undefined
|
|
5
5
|
/** Whether this Option contains no value */
|
|
@@ -75,18 +75,6 @@ const e=`0.58.0`,t={Option:{description:`Safe nullable handling - Some<T> or Non
|
|
|
75
75
|
* @returns Promise of the result of applying f to the contained value, or None if this Option is None
|
|
76
76
|
*/
|
|
77
77
|
flatMapAsync<U extends Type>(f: (value: T) => Promise<Option<U>>): Promise<Option<U>>
|
|
78
|
-
/**
|
|
79
|
-
* Applies a binary operator to a start value and the contained value
|
|
80
|
-
* @param f - The binary operator
|
|
81
|
-
* @returns The result of the reduction
|
|
82
|
-
*/
|
|
83
|
-
reduce<U>(f: (acc: U, value: T) => U): U
|
|
84
|
-
/**
|
|
85
|
-
* Applies a binary operator to the contained value and a start value
|
|
86
|
-
* @param f - The binary operator
|
|
87
|
-
* @returns The result of the reduction
|
|
88
|
-
*/
|
|
89
|
-
reduceRight<U>(f: (acc: U, value: T) => U): U
|
|
90
78
|
/**
|
|
91
79
|
* Pattern matches over the Option, applying onNone if None and onSome if Some
|
|
92
80
|
* @param onNone - Function to apply if the Option is None
|
|
@@ -117,6 +105,11 @@ const e=`0.58.0`,t={Option:{description:`Safe nullable handling - Some<T> or Non
|
|
|
117
105
|
* @returns true if this Option contains the value, false otherwise
|
|
118
106
|
*/
|
|
119
107
|
contains(value: T): boolean
|
|
108
|
+
/**
|
|
109
|
+
* Converts this Option to a List.
|
|
110
|
+
* @returns A List containing the value if Some, or empty List if None
|
|
111
|
+
*/
|
|
112
|
+
toList(): List<T>
|
|
120
113
|
/** The number of elements in this Option (0 or 1) */
|
|
121
114
|
size: number
|
|
122
115
|
/**
|
|
@@ -177,6 +170,7 @@ const RightConstructor = <L extends Type, R extends Type>(value: R): RightOf<L,
|
|
|
177
170
|
): Promise<Either<L | L2, U>> =>
|
|
178
171
|
f(value).catch((error: unknown) => Left<L | L2, U>(error as L | L2)) as Promise<Either<L | L2, U>>,
|
|
179
172
|
toOption: () => Some<R>(value),
|
|
173
|
+
toList: () => List<R>([value]),
|
|
180
174
|
toEither: <E extends Type>(_leftValue: E) => Right<E, R>(value),
|
|
181
175
|
toTry: () => Try(() => value),
|
|
182
176
|
toJSON() {
|
|
@@ -230,12 +224,7 @@ const RightConstructor = <L extends Type, R extends Type>(value: R): RightOf<L,
|
|
|
230
224
|
})
|
|
231
225
|
|
|
232
226
|
export interface EitherBase<out L extends Type, out R extends Type>
|
|
233
|
-
extends
|
|
234
|
-
FunctypeSum<R, "Left" | "Right">,
|
|
235
|
-
Promisable<R>,
|
|
236
|
-
Doable<R>,
|
|
237
|
-
Omit<Reshapeable<R>, "toList">,
|
|
238
|
-
Omit<Extractable<R>, "or" | "orElse"> {
|
|
227
|
+
extends FunctypeSum<R, "Left" | "Right">, Promisable<R>, Doable<R>, Reshapeable<R>, Extractable<R> {
|
|
239
228
|
isLeft(): this is LeftOf<L, R>
|
|
240
229
|
isRight(): this is RightOf<L, R>
|
|
241
230
|
orElse<R2 extends Type>(defaultValue: R2): R | R2
|
|
@@ -297,13 +286,7 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
297
286
|
readonly _tag: "Right"
|
|
298
287
|
readonly value: R
|
|
299
288
|
}`,Try:`export interface Try<out T>
|
|
300
|
-
extends
|
|
301
|
-
FunctypeSum<T, TypeNames>,
|
|
302
|
-
Omit<Extractable<T>, "or" | "orElse">,
|
|
303
|
-
Pipe<T>,
|
|
304
|
-
Promisable<T>,
|
|
305
|
-
Doable<T>,
|
|
306
|
-
Omit<Reshapeable<T>, "toList"> {
|
|
289
|
+
extends FunctypeSum<T, TypeNames>, Extractable<T>, Pipe<T>, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
307
290
|
readonly _tag: TypeNames
|
|
308
291
|
readonly error: Error | undefined
|
|
309
292
|
isSuccess(): this is Try<T> & { readonly _tag: "Success"; error: undefined }
|
|
@@ -354,7 +337,7 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
354
337
|
*/
|
|
355
338
|
recoverWith<U extends Type>(f: (error: Error) => Try<U>): Try<T | U>
|
|
356
339
|
toValue(): { _tag: TypeNames; value: T | Error }
|
|
357
|
-
}`,List:`export interface List<A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
|
|
340
|
+
}`,List:`export interface List<out A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
|
|
358
341
|
readonly length: number
|
|
359
342
|
readonly [Symbol.iterator]: () => Iterator<A>
|
|
360
343
|
// Override these to return List instead of FunctypeCollection
|
|
@@ -369,11 +352,14 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
369
352
|
// List-specific methods
|
|
370
353
|
/** @internal */
|
|
371
354
|
filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>
|
|
372
|
-
|
|
355
|
+
/** Remove a value. Accepts \`unknown\` so an unrelated-type arg is a safe no-op (Scala: \`-(elem: Any)\`). */
|
|
356
|
+
remove: (value: unknown) => List<A>
|
|
373
357
|
removeAt: (index: number) => List<A>
|
|
374
|
-
|
|
358
|
+
/** Add a value, possibly widening the element type (Scala: \`:+[B >: A]\`). */
|
|
359
|
+
add<B>(item: B): List<A | B>
|
|
375
360
|
get: (index: number) => Option<A>
|
|
376
|
-
|
|
361
|
+
/** Concatenate with another list, possibly widening (Scala: \`++[B >: A]\`). */
|
|
362
|
+
concat<B>(other: List<B>): List<A | B>
|
|
377
363
|
take: (n: number) => List<A>
|
|
378
364
|
takeWhile: (p: (a: A) => boolean) => List<A>
|
|
379
365
|
takeRight: (n: number) => List<A>
|
|
@@ -382,8 +368,10 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
382
368
|
get tail(): List<A>
|
|
383
369
|
get init(): List<A>
|
|
384
370
|
reverse: () => List<A>
|
|
385
|
-
|
|
386
|
-
|
|
371
|
+
/** Find the index of a value. Accepts \`unknown\` (Scala: \`indexOf(elem: Any)\`). */
|
|
372
|
+
indexOf: (value: unknown) => number
|
|
373
|
+
/** Prepend a value, possibly widening (Scala: \`+:[B >: A]\`). */
|
|
374
|
+
prepend<B>(item: B): List<A | B>
|
|
387
375
|
distinct: () => List<A>
|
|
388
376
|
sorted: (compareFn?: (a: A, b: A) => number) => List<A>
|
|
389
377
|
sortBy: <B>(f: (a: A) => B, compareFn?: (a: B, b: B) => number) => List<A>
|
|
@@ -399,11 +387,10 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
399
387
|
* @returns The result of applying the matching handler function
|
|
400
388
|
*/
|
|
401
389
|
match<R>(patterns: { Empty: () => R; NonEmpty: (values: A[]) => R }): R
|
|
402
|
-
}`,Set:`export interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
|
|
403
|
-
add
|
|
404
|
-
remove: (value:
|
|
405
|
-
|
|
406
|
-
has: (value: A) => boolean
|
|
390
|
+
}`,Set:`export interface Set<out A> extends FunctypeCollection<A, "Set">, Collection<A> {
|
|
391
|
+
add<B>(value: B): Set<A | B>
|
|
392
|
+
remove: (value: unknown) => Set<A>
|
|
393
|
+
has(value: unknown): boolean
|
|
407
394
|
map: <B>(f: (a: A) => B) => Set<B>
|
|
408
395
|
flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>
|
|
409
396
|
filter: (p: (a: A) => boolean) => Set<A>
|
|
@@ -449,11 +436,10 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
449
436
|
/** Whether the computation has been evaluated */
|
|
450
437
|
readonly isEvaluated: boolean
|
|
451
438
|
/**
|
|
452
|
-
* Returns the computed value or a default value if computation fails
|
|
453
|
-
*
|
|
454
|
-
* @returns The computed value or defaultValue
|
|
439
|
+
* Returns the computed value or a default value if computation fails.
|
|
440
|
+
* Result widens to \`T | T2\` (Scala: \`getOrElse[B >: A](default: B): B\`).
|
|
455
441
|
*/
|
|
456
|
-
orElse(defaultValue:
|
|
442
|
+
orElse<T2 extends Type>(defaultValue: T2): T | T2
|
|
457
443
|
/**
|
|
458
444
|
* Returns the computed value or null if computation fails
|
|
459
445
|
* @returns The computed value or null
|
|
@@ -467,11 +453,10 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
467
453
|
*/
|
|
468
454
|
orThrow(error?: Error): T
|
|
469
455
|
/**
|
|
470
|
-
* Returns this Lazy if computation succeeds, otherwise returns the alternative Lazy
|
|
471
|
-
*
|
|
472
|
-
* @returns This Lazy or the alternative
|
|
456
|
+
* Returns this Lazy if computation succeeds, otherwise returns the alternative Lazy.
|
|
457
|
+
* The alternative may carry a different type; result is \`Lazy<T | T2>\`.
|
|
473
458
|
*/
|
|
474
|
-
or(alternative: Lazy<
|
|
459
|
+
or<T2 extends Type>(alternative: Lazy<T2>): Lazy<T | T2>
|
|
475
460
|
/**
|
|
476
461
|
* Maps the value inside the Lazy using the provided function
|
|
477
462
|
* @param f - The mapping function
|