@shirudo/result 0.0.1

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.
@@ -0,0 +1,1033 @@
1
+ //#region src/pipeable.d.ts
2
+ type UnaryFunction<Input, Output> = (input: Input) => Output;
3
+ type Awaitable<T> = T | Promise<T>;
4
+ declare abstract class Pipeable {
5
+ pipe(): this;
6
+ pipe<B>(ab: UnaryFunction<this, B>): B;
7
+ pipe<B, C>(ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>): C;
8
+ pipe<B, C, D>(ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>): D;
9
+ pipe<A, B, C, D, E>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>): E;
10
+ pipe<A, B, C, D, E, F>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>): F;
11
+ pipe<A, B, C, D, E, F, G>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>): G;
12
+ pipe<A, B, C, D, E, F, G, H>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>): H;
13
+ pipe<A, B, C, D, E, F, G, H, I>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>): I;
14
+ pipe<A, B, C, D, E, F, G, H, I, J>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>): J;
15
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>): K$1;
16
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>): L;
17
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>): M;
18
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>): N;
19
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>): O;
20
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>, op: UnaryFunction<O, P>): P;
21
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>, op: UnaryFunction<O, P>, pq: UnaryFunction<P, Q>): Q;
22
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>, op: UnaryFunction<O, P>, pq: UnaryFunction<P, Q>, qr: UnaryFunction<Q, R$1>): R$1;
23
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1, S>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>, op: UnaryFunction<O, P>, pq: UnaryFunction<P, Q>, qr: UnaryFunction<Q, R$1>, rs: UnaryFunction<R$1, S>): S;
24
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1, S, T>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>, op: UnaryFunction<O, P>, pq: UnaryFunction<P, Q>, qr: UnaryFunction<Q, R$1>, rs: UnaryFunction<R$1, S>, st: UnaryFunction<S, T>): T;
25
+ pipe<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1, S, T, U>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<B, C>, cd: UnaryFunction<C, D>, de: UnaryFunction<D, E>, ef: UnaryFunction<E, F>, fg: UnaryFunction<F, G>, gh: UnaryFunction<G, H>, hi: UnaryFunction<H, I>, ij: UnaryFunction<I, J>, jk: UnaryFunction<J, K$1>, kl: UnaryFunction<K$1, L>, lm: UnaryFunction<L, M>, mn: UnaryFunction<M, N>, no: UnaryFunction<N, O>, op: UnaryFunction<O, P>, pq: UnaryFunction<P, Q>, qr: UnaryFunction<Q, R$1>, rs: UnaryFunction<R$1, S>, st: UnaryFunction<S, T>, tu: UnaryFunction<T, U>): U;
26
+ pipeAsync<A>(this: A): Promise<A>;
27
+ pipeAsync<A, B>(this: A, ab: UnaryFunction<this, B>): Promise<Awaited<B>>;
28
+ pipeAsync<A, B, C>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>): Promise<Awaited<C>>;
29
+ pipeAsync<A, B, C, D>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>): Promise<Awaited<D>>;
30
+ pipeAsync<A, B, C, D, E>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>): Promise<Awaited<E>>;
31
+ pipeAsync<A, B, C, D, E, F>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>): Promise<Awaited<F>>;
32
+ pipeAsync<A, B, C, D, E, F, G>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>): Promise<Awaited<G>>;
33
+ pipeAsync<A, B, C, D, E, F, G, H>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>): Promise<Awaited<H>>;
34
+ pipeAsync<A, B, C, D, E, F, G, H, I>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>): Promise<Awaited<I>>;
35
+ pipeAsync<A, B, C, D, E, F, G, H, I, J>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>): Promise<Awaited<J>>;
36
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>): Promise<Awaited<K$1>>;
37
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>): Promise<Awaited<L>>;
38
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>): Promise<Awaited<M>>;
39
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>): Promise<Awaited<N>>;
40
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>): Promise<Awaited<O>>;
41
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>, op: UnaryFunction<Awaited<O>, P>): Promise<Awaited<P>>;
42
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>, op: UnaryFunction<Awaited<O>, P>, pq: UnaryFunction<Awaited<P>, Q>): Promise<Awaited<Q>>;
43
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>, op: UnaryFunction<Awaited<O>, P>, pq: UnaryFunction<Awaited<P>, Q>, qr: UnaryFunction<Awaited<Q>, R$1>): Promise<Awaited<R$1>>;
44
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1, S>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>, op: UnaryFunction<Awaited<O>, P>, pq: UnaryFunction<Awaited<P>, Q>, qr: UnaryFunction<Awaited<Q>, R$1>, rs: UnaryFunction<Awaited<R$1>, S>): Promise<Awaited<S>>;
45
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1, S, T>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>, op: UnaryFunction<Awaited<O>, P>, pq: UnaryFunction<Awaited<P>, Q>, qr: UnaryFunction<Awaited<Q>, R$1>, rs: UnaryFunction<Awaited<R$1>, S>, st: UnaryFunction<Awaited<S>, T>): Promise<Awaited<T>>;
46
+ pipeAsync<A, B, C, D, E, F, G, H, I, J, K$1, L, M, N, O, P, Q, R$1, S, T, U>(this: A, ab: UnaryFunction<this, B>, bc: UnaryFunction<Awaited<B>, C>, cd: UnaryFunction<Awaited<C>, D>, de: UnaryFunction<Awaited<D>, E>, ef: UnaryFunction<Awaited<E>, F>, fg: UnaryFunction<Awaited<F>, G>, gh: UnaryFunction<Awaited<G>, H>, hi: UnaryFunction<Awaited<H>, I>, ij: UnaryFunction<Awaited<I>, J>, jk: UnaryFunction<Awaited<J>, K$1>, kl: UnaryFunction<Awaited<K$1>, L>, lm: UnaryFunction<Awaited<L>, M>, mn: UnaryFunction<Awaited<M>, N>, no: UnaryFunction<Awaited<N>, O>, op: UnaryFunction<Awaited<O>, P>, pq: UnaryFunction<Awaited<P>, Q>, qr: UnaryFunction<Awaited<Q>, R$1>, rs: UnaryFunction<Awaited<R$1>, S>, st: UnaryFunction<Awaited<S>, T>, tu: UnaryFunction<Awaited<T>, U>): Promise<Awaited<U>>;
47
+ }
48
+ //#endregion
49
+ //#region src/matcher.d.ts
50
+ type Ctor<T> = abstract new (...args: any[]) => T;
51
+ type TypeGuard<E, A extends E> = (error: E) => error is A;
52
+ /**
53
+ * Matcher for Err values (returns any return type, e.g. string messages).
54
+ *
55
+ * - `.when(Ctor, handler)` matched via `instanceof`
56
+ * - `.whenGuard(guard, handler)` matched via type guard
57
+ * - `.run()` is only allowed once all error cases are handled (`E` is reduced to `never`)
58
+ */
59
+ declare class ErrorMatchBuilder<E, R$1> {
60
+ #private;
61
+ constructor(error: unknown, matched?: boolean, value?: unknown);
62
+ when<C extends Ctor<any>, R1>(ctor: C, handler: (error: InstanceType<C>) => R1): ErrorMatchBuilder<Exclude<E, InstanceType<C>>, R$1 | R1>;
63
+ whenGuard<A extends E, R1>(guard: TypeGuard<E, A>, handler: (error: A) => R1): ErrorMatchBuilder<Exclude<E, A>, R$1 | R1>;
64
+ otherwise<R2>(handler: (error: any) => R2): R$1 | R2;
65
+ run(this: ErrorMatchBuilder<never, R$1>): R$1;
66
+ }
67
+ type OkOfReturn$1<R$1> = R$1 extends Result<infer T, any> ? T : never;
68
+ type ErrOfReturn$1<R$1> = R$1 extends Result<any, infer E> ? E : R$1;
69
+ type ErrFactory = <E>(error: E) => Result<never, E>;
70
+ /**
71
+ * Matcher for `Result` errors that always returns a `Result`.
72
+ *
73
+ * Handlers may:
74
+ * - return a `Result` (returned directly)
75
+ * - return an error value (automatically wrapped to `Err(error)`)
76
+ */
77
+ declare class ErrMatchBuilder<T, E, OutT, OutE> {
78
+ #private;
79
+ private constructor();
80
+ static fromResult<T, E>(result: Result<T, E>, makeErr: ErrFactory): ErrMatchBuilder<T, E, never, never>;
81
+ when<C extends Ctor<any>, R1>(ctor: C, handler: (error: InstanceType<C>) => R1): ErrMatchBuilder<T, Exclude<E, InstanceType<C>>, OutT | OkOfReturn$1<R1>, OutE | ErrOfReturn$1<R1>>;
82
+ whenGuard<A extends E, R1>(guard: TypeGuard<E, A>, handler: (error: A) => R1): ErrMatchBuilder<T, Exclude<E, A>, OutT | OkOfReturn$1<R1>, OutE | ErrOfReturn$1<R1>>;
83
+ otherwise<R2>(handler: (error: E) => R2): Result<T | OutT | OkOfReturn$1<R2>, OutE | ErrOfReturn$1<R2>>;
84
+ run(this: ErrMatchBuilder<T, never, OutT, OutE>): Result<T | OutT, OutE>;
85
+ }
86
+ type ErrCase = {
87
+ readonly kind: 'ctor';
88
+ readonly ctor: Ctor<any>;
89
+ readonly handler: (error: any) => unknown;
90
+ } | {
91
+ readonly kind: 'val';
92
+ readonly value: unknown;
93
+ readonly handler: (error: any) => unknown;
94
+ };
95
+ declare const HAS_OK: unique symbol;
96
+ type HasOk = {
97
+ readonly [HAS_OK]: true;
98
+ };
99
+ type WithOk<T, E, R$1> = ResultMatchBuilder<T, E, R$1> & HasOk;
100
+ type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : never;
101
+ type ExcludeIfLiteral<E, V> = IsUnion<V> extends true ? E : V extends string ? string extends V ? E : Exclude<E, V> : V extends number ? number extends V ? E : Exclude<E, V> : V extends boolean ? boolean extends V ? E : Exclude<E, V> : V extends bigint ? bigint extends V ? E : Exclude<E, V> : V extends symbol ? symbol extends V ? E : Exclude<E, V> : Exclude<E, V>;
102
+ /**
103
+ * Universal matcher for `Result` (Ok + Err in a single chain).
104
+ *
105
+ * - `.err(Ctor, handler)` matched via `instanceof`
106
+ * - `.errVal(value, handler)` matched via `Object.is`
107
+ * - `.ok(handler)` defines the success branch
108
+ * - `.run()` is only allowed after `.ok()` is set
109
+ *
110
+ * Lazy: if the Result is `Ok`, Err cases are not evaluated in `.run()`.
111
+ */
112
+ declare class ResultMatchBuilder<T, E, R$1> {
113
+ #private;
114
+ constructor(result: Result<T, E>, errCases?: readonly ErrCase[], okHandler?: (value: T) => unknown);
115
+ static fromResult<T, E>(result: Result<T, E>): ResultMatchBuilder<T, E, never>;
116
+ err<C extends Ctor<any>, R1>(this: ResultMatchBuilder<T, E, R$1>, ctor: C, handler: (error: InstanceType<C>) => R1): ResultMatchBuilder<T, Exclude<E, InstanceType<C>>, R$1 | R1>;
117
+ err<C extends Ctor<any>, R1>(this: WithOk<T, E, R$1>, ctor: C, handler: (error: InstanceType<C>) => R1): WithOk<T, Exclude<E, InstanceType<C>>, R$1 | R1>;
118
+ errVal<const V, R1>(this: ResultMatchBuilder<T, E, R$1>, value: V, handler: (error: V) => R1): ResultMatchBuilder<T, ExcludeIfLiteral<E, V>, R$1 | R1>;
119
+ errVal<const V, R1>(this: WithOk<T, E, R$1>, value: V, handler: (error: V) => R1): WithOk<T, ExcludeIfLiteral<E, V>, R$1 | R1>;
120
+ ok<R1>(handler: (value: T) => R1): WithOk<T, E, R$1 | R1>;
121
+ run(this: WithOk<T, E, R$1>): R$1;
122
+ }
123
+ //#endregion
124
+ //#region src/result.d.ts
125
+ type OperatorFunction<T, E, R$1> = (input: Result<T, E>) => R$1;
126
+ type AsyncOperatorFunction<T, E, R$1> = (input: Result<T, E>) => Promise<R$1>;
127
+ type Ok<T> = {
128
+ readonly _tag: 'Ok';
129
+ readonly value: T;
130
+ };
131
+ type Err<E> = {
132
+ readonly _tag: 'Err';
133
+ readonly error: E;
134
+ };
135
+ type ResultType<T, E> = Ok<T> | Err<E>;
136
+ declare class Result<T, E> extends Pipeable {
137
+ #private;
138
+ private constructor();
139
+ /**
140
+ * Creates an Ok Result with the given value.
141
+ *
142
+ * **Note**: `null` and `undefined` are allowed as values.
143
+ * If you want to convert `null`/`undefined` to an Err, use `fromNullable()`.
144
+ *
145
+ * @param value The value for the Ok Result
146
+ * @returns An Ok Result with the given value
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const result = Result.ok(42);
151
+ * const nullResult = Result.ok(null); // Allowed!
152
+ * ```
153
+ */
154
+ static ok<T, E = never>(value: T): Result<T, E>;
155
+ /**
156
+ * Creates an Err Result with the given error.
157
+ *
158
+ * **Note**: `null` and `undefined` are allowed as errors.
159
+ *
160
+ * @param error The error for the Err Result
161
+ * @returns An Err Result with the given error
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * const result = Result.err('error message');
166
+ * const nullError = Result.err(null); // Allowed!
167
+ * ```
168
+ */
169
+ static err<E, T = never>(error: E): Result<T, E>;
170
+ /**
171
+ * Converts `null | undefined` to `Err`, everything else to `Ok`.
172
+ *
173
+ * **Type Safety**: The type assertion `as NonNullable<T>` is safe,
174
+ * as the runtime check guarantees that the value is not null/undefined.
175
+ *
176
+ * @param value The value to check
177
+ * @param error The error to use if value is null/undefined
178
+ * @returns An Ok Result with the NonNullable value, or an Err Result with the error
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * Result.fromNullable(user, 'User not found')
183
+ * // Ok(user) or Err('User not found')
184
+ * ```
185
+ */
186
+ static fromNullable<T, E>(value: T, error: E): Result<NonNullable<T>, E>;
187
+ /**
188
+ * Converts a Promise to a Result-Promise.
189
+ * Exceptions are converted to Err.
190
+ *
191
+ * This static method delegates to the standalone `fromPromise()` function.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const result = await Result.fromPromise(fetch('/api/user'));
196
+ * // Ok(response) or Err(error)
197
+ *
198
+ * // With custom error mapper
199
+ * const result = await Result.fromPromise(
200
+ * fetch('/api/user'),
201
+ * (e) => `Network error: ${e}`
202
+ * );
203
+ * ```
204
+ */
205
+ static fromPromise<T>(promise: Promise<T>): Promise<Result<T, unknown>>;
206
+ static fromPromise<T, E>(promise: Promise<T>, errorMapper?: (error: unknown) => E): Promise<Result<T, E>>;
207
+ /**
208
+ * Executes a function and catches exceptions.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * const result = Result.try(() => JSON.parse(input));
213
+ * // Ok(parsed) or Err(SyntaxError)
214
+ * ```
215
+ */
216
+ static try<T>(fn: () => T): Result<T, unknown>;
217
+ /**
218
+ * Checks if the Result is Ok.
219
+ *
220
+ * @returns `true` if the Result is Ok (and narrows the type)
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * if (result.isOk()) {
225
+ * const value: T = result.value; // TypeScript knows that value is defined
226
+ * }
227
+ * ```
228
+ */
229
+ isOk(): this is Result<T, E> & {
230
+ readonly value: T;
231
+ readonly error: undefined;
232
+ };
233
+ /**
234
+ * Checks if the Result is Err.
235
+ *
236
+ * @returns `true` if the Result is Err (and narrows the type)
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * if (result.isErr()) {
241
+ * const error: E = result.error; // TypeScript knows that error is defined
242
+ * }
243
+ * ```
244
+ */
245
+ isErr(): this is Result<T, E> & {
246
+ readonly value: undefined;
247
+ readonly error: E;
248
+ };
249
+ get value(): T | undefined;
250
+ get error(): E | undefined;
251
+ /**
252
+ * Returns the value, guaranteed to be defined after `isOk()` check.
253
+ * This method provides better type narrowing than the `value` getter.
254
+ *
255
+ * ⚠️ **Warning**: This method throws an Error if called on an Err result.
256
+ * Use this method only after a type guard (`if (result.isOk())`).
257
+ * For a safer alternative with a custom message, use `expect()`.
258
+ *
259
+ * @throws {Error} If called on an Err result
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * if (result.isOk()) {
264
+ * const value = result.unwrap(); // Type is T, not T | undefined
265
+ * }
266
+ * ```
267
+ */
268
+ unwrap(): T;
269
+ /**
270
+ * Returns the error, guaranteed to be defined after `isErr()` check.
271
+ * This method provides better type narrowing than the `error` getter.
272
+ *
273
+ * ⚠️ **Warning**: This method throws an Error if called on an Ok result.
274
+ * Use this method only after a type guard (`if (result.isErr())`).
275
+ * For a safer alternative with a custom message, use `expectErr()`.
276
+ *
277
+ * @throws {Error} If called on an Ok result
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * if (result.isErr()) {
282
+ * const error = result.unwrapErr(); // Type is E, not E | undefined
283
+ * }
284
+ * ```
285
+ */
286
+ unwrapErr(): E;
287
+ /**
288
+ * Returns the value with a custom error message if the result is Err.
289
+ * Similar to `unwrap()`, but allows you to provide a custom error message.
290
+ *
291
+ * ⚠️ **Warning**: This method throws an Error if called on an Err result.
292
+ * Use this method only if you are sure the Result is Ok,
293
+ * or if you need a meaningful error message.
294
+ *
295
+ * @param message Custom error message to throw if result is Err
296
+ * @returns The value if result is Ok
297
+ * @throws {Error} If called on an Err result with the provided message
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const result = fetchUser(id);
302
+ * const user = result.expect('User should exist'); // Throws with custom message if Err
303
+ * ```
304
+ */
305
+ expect(message: string): T;
306
+ /**
307
+ * Returns the error with a custom error message if the result is Ok.
308
+ * Similar to `unwrapErr()`, but allows you to provide a custom error message.
309
+ *
310
+ * ⚠️ **Warning**: This method throws an Error if called on an Ok result.
311
+ * Use this method only if you are sure the Result is Err,
312
+ * or if you need a meaningful error message.
313
+ *
314
+ * @param message Custom error message to throw if result is Ok
315
+ * @returns The error if result is Err
316
+ * @throws {Error} If called on an Ok result with the provided message
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * const result = validateInput(input);
321
+ * if (result.isErr()) {
322
+ * const error = result.expectErr('Validation should have failed'); // Throws if Ok
323
+ * }
324
+ * ```
325
+ */
326
+ expectErr(message: string): E;
327
+ unwrapOr<D = T>(defaultValue: D): T | D;
328
+ /**
329
+ * Converts the Result to a Promise.
330
+ * Ok → resolves with the value, Err → rejects with the error
331
+ *
332
+ * This instance method delegates to the standalone `toPromise()` function.
333
+ *
334
+ * @returns A Promise that resolves with the value if Ok, or rejects with the error if Err
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * const result = ok(42);
339
+ * const promise = result.toPromise();
340
+ * const value = await promise; // 42
341
+ *
342
+ * const errResult = err('error');
343
+ * try {
344
+ * await errResult.toPromise();
345
+ * } catch (error) {
346
+ * console.log(error); // 'error'
347
+ * }
348
+ * ```
349
+ */
350
+ toPromise(): Promise<T>;
351
+ /**
352
+ * Converts the Result to `T | null`.
353
+ * Ok → returns the value, Err → returns null
354
+ *
355
+ * This instance method delegates to the standalone `toNullable()` function.
356
+ *
357
+ * @returns The value if Ok, or null if Err
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * const result = ok(42);
362
+ * const value = result.toNullable(); // 42
363
+ *
364
+ * const errResult = err('error');
365
+ * const nullValue = errResult.toNullable(); // null
366
+ * ```
367
+ */
368
+ toNullable(): T | null;
369
+ /**
370
+ * Enables `yield* result` in generators (Do-notation).
371
+ *
372
+ * The iterator yields the `Result` itself; the runner (see `task`) decides:
373
+ * - Ok → sends back the Ok value (`next(value)`), `yield*` yields `T`
374
+ * - Err → aborts and returns the Err Result
375
+ */
376
+ [Symbol.iterator](): Generator<Result<T, E>, T, unknown>;
377
+ /**
378
+ * Universal pattern matcher for Ok + Err cases.
379
+ *
380
+ * Use this to exhaustively match on both success and error cases with type-based
381
+ * and value-based pattern matching.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * const message = result
386
+ * .match()
387
+ * .err(NetworkError, e => `Network: ${e.message}`)
388
+ * .err(ValidationError, e => `Validation: ${e.message}`)
389
+ * .ok(val => `Success: ${val}`)
390
+ * .run();
391
+ * ```
392
+ */
393
+ match(): ResultMatchBuilder<T, E, never>;
394
+ /**
395
+ * Matches on the Err value via `.when(...)` chain.
396
+ *
397
+ * Note: For type safety reasons, `.matchErr()` can only be called on a Result that has already been narrowed to `Err`,
398
+ * e.g., inside `if (result.isErr()) { ... }`.
399
+ *
400
+ * @example
401
+ * ```ts
402
+ * if (result.isErr()) {
403
+ * const message = result
404
+ * .matchErr()
405
+ * .when(IOError, () => 'IO error')
406
+ * .when(ParseError, () => 'Parse error')
407
+ * .otherwise(e => `Other: ${e}`);
408
+ * }
409
+ * ```
410
+ */
411
+ matchErr(this: Result<T, E> & {
412
+ readonly error: E;
413
+ }): ErrorMatchBuilder<E, never>;
414
+ matchErr(this: Result<T, E>): never;
415
+ /**
416
+ * Matches on the Err value, but normalizes every branch to a `Result`:
417
+ * - Handlers may return a `Result` (returned directly)
418
+ * - or an error value (wrapped to `Err(error)`)
419
+ */
420
+ matchErrResult(): ErrMatchBuilder<T, E, never, never>;
421
+ /**
422
+ * @deprecated Use `.match()` instead. Will be removed in next major version.
423
+ */
424
+ pattern(): ResultMatchBuilder<T, E, never>;
425
+ /**
426
+ * @deprecated Use `.match()` instead. Will be removed in next major version.
427
+ */
428
+ switch(): ResultMatchBuilder<T, E, never>;
429
+ /**
430
+ * Folds the Result into a single value by applying one of two functions.
431
+ *
432
+ * This is a direct method equivalent to the `match` pipe operator.
433
+ * Use this when you want to handle both Ok and Err cases and return a single value.
434
+ *
435
+ * @param onOk Function to apply if the Result is Ok
436
+ * @param onErr Function to apply if the Result is Err
437
+ * @returns The result of applying the appropriate function
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * const result = ok(42);
442
+ * const message = result.fold(
443
+ * val => `Success: ${val}`,
444
+ * err => `Error: ${err}`
445
+ * );
446
+ * // message = "Success: 42"
447
+ * ```
448
+ *
449
+ * @example
450
+ * ```ts
451
+ * // Works with discriminated unions
452
+ * const result: Result<string, number> = err(404);
453
+ * const response = result.fold(
454
+ * data => ({ success: true as const, data }),
455
+ * code => ({ success: false as const, code })
456
+ * );
457
+ * // response: { success: true; data: string } | { success: false; code: number }
458
+ * ```
459
+ */
460
+ fold<R1, R2 = R1>(onOk: (value: T) => R1, onErr: (error: E) => R2): R1 | R2;
461
+ /**
462
+ * Returns the Result as a discriminated union (`{ _tag: 'Ok', value } | { _tag: 'Err', error }`).
463
+ * Useful for libraries like `ts-pattern` that match on plain object unions.
464
+ */
465
+ toUnion(): ResultType<T, E>;
466
+ /**
467
+ * Serializes the Result into a simple object format.
468
+ * Preserves the original types.
469
+ */
470
+ serialize(): {
471
+ isSuccess: boolean;
472
+ data?: T;
473
+ error?: E;
474
+ };
475
+ /**
476
+ * Serializes the Result into a user-friendly format.
477
+ * Converts errors to readable strings.
478
+ */
479
+ toUserFriendly(): {
480
+ isSuccess: boolean;
481
+ data?: T;
482
+ error?: string;
483
+ };
484
+ }
485
+ declare const ok: typeof Result.ok;
486
+ declare const err: typeof Result.err;
487
+ /**
488
+ * Helper for conditional Result creation.
489
+ * Avoids type inference issues with ternary operators.
490
+ *
491
+ * @example
492
+ * ```ts
493
+ * const result = okIf(value > 5, value, 'too small');
494
+ * // instead of: value > 5 ? ok(value) : err('too small')
495
+ * ```
496
+ */
497
+ declare function okIf<T, E>(condition: boolean, okValue: T, errValue: E): Result<T, E>;
498
+ /**
499
+ * Helper for conditional Result creation with lazy evaluation.
500
+ * Evaluates values only when they are needed.
501
+ *
502
+ * @example
503
+ * ```ts
504
+ * const result = okIfLazy(
505
+ * value > 5,
506
+ * () => expensiveComputation(value),
507
+ * () => 'too small'
508
+ * );
509
+ * ```
510
+ */
511
+ declare function okIfLazy<T, E>(condition: boolean, okFn: () => T, errFn: () => E): Result<T, E>;
512
+ //#endregion
513
+ //#region src/gen.d.ts
514
+ type AnyGenerator = Generator<any, any, unknown> | AsyncGenerator<any, any, unknown>;
515
+ type YieldOf<G> = G extends Generator<infer Y, any, any> ? Y : G extends AsyncGenerator<infer Y, any, any> ? Y : never;
516
+ type ReturnOf<G> = G extends Generator<any, infer R, any> ? R : G extends AsyncGenerator<any, infer R, any> ? R : never;
517
+ type ErrorOfYield<Y> = Y extends Result<any, infer E> ? E : never;
518
+ type ErrorOfGenerator<G> = ErrorOfYield<YieldOf<G>>;
519
+ type OnThrow<E> = (error: unknown) => E;
520
+ type AwaitedReturnOf<G> = Awaited<ReturnOf<G>>;
521
+ type OkOfReturn<G> = AwaitedReturnOf<G> extends Result<infer T, any> ? T : AwaitedReturnOf<G>;
522
+ type ErrOfReturn<G> = AwaitedReturnOf<G> extends Result<any, infer E> ? E : never;
523
+ /**
524
+ * Generator-based do-notation for `Result`.
525
+ *
526
+ * Usage:
527
+ * ```ts
528
+ * const out = await task(async function* () {
529
+ * const user = yield* await fromPromise(findUser(1));
530
+ * const email = yield* validate(user.email);
531
+ * return email;
532
+ * });
533
+ * ```
534
+ */
535
+ declare function task<const G extends AnyGenerator>(makeGenerator: () => G): Promise<Result<OkOfReturn<G>, ErrorOfGenerator<G> | ErrOfReturn<G>>>;
536
+ declare function task<const G extends AnyGenerator, EThrown>(makeGenerator: () => G, onThrow: OnThrow<EThrown>): Promise<Result<OkOfReturn<G>, ErrorOfGenerator<G> | ErrOfReturn<G> | EThrown>>;
537
+ declare const gen: typeof task;
538
+ //#endregion
539
+ //#region src/operators/map.d.ts
540
+ /**
541
+ * Transforms the value (Ok case).
542
+ * Equivalent to Rust `map`.
543
+ */
544
+ declare function map<T, E, U>(project: (value: T) => U): (source: Result<T, E>) => Result<U, E>;
545
+ //#endregion
546
+ //#region src/operators/mapErr.d.ts
547
+ /**
548
+ * Transforms the error (Err case).
549
+ * Equivalent to Rust `map_err`.
550
+ */
551
+ declare function mapErr<T, E, F>(project: (error: E) => F): (source: Result<T, E>) => Result<T, F>;
552
+ //#endregion
553
+ //#region src/operators/mapBoth.d.ts
554
+ /**
555
+ * Transforms both the Ok value and the Err error.
556
+ * Equivalent to FP `bimap` / `mapBoth`.
557
+ */
558
+ declare function mapBoth<T, E, U, F>(mapOk: (value: T) => U, mapErr: (error: E) => F): (source: Result<T, E>) => Result<U, F>;
559
+ /**
560
+ * Alias for `mapBoth`.
561
+ */
562
+ declare const bimap: typeof mapBoth;
563
+ //#endregion
564
+ //#region src/operators/flatMap.d.ts
565
+ /**
566
+ * Chains another operation that returns a Result.
567
+ * Equivalent to Rust `and_then` or JS `flatMap`.
568
+ */
569
+ declare function flatMap<T, E, U, E2 = E>(project: (value: T) => Result<U, E2>): (source: Result<T, E>) => Result<U, E | E2>;
570
+ //#endregion
571
+ //#region src/operators/tap.d.ts
572
+ /**
573
+ * Executes a side effect (logging, debugging) without changing the Result.
574
+ * Equivalent to Rust `inspect` / `inspect_err`.
575
+ */
576
+ declare function tap<T, E>(observer: {
577
+ ok?: (val: T) => void;
578
+ err?: (e: E) => void;
579
+ }): <SourceT extends T, SourceE extends E>(source: Result<SourceT, SourceE>) => Result<SourceT, SourceE>;
580
+ //#endregion
581
+ //#region src/operators/filter.d.ts
582
+ /**
583
+ * Checks a predicate. If false, the Result becomes Err.
584
+ * Partially equivalent to Rust `filter`.
585
+ */
586
+ declare function filter<T, E>(predicate: (val: T) => boolean, errorFn: () => E): (source: Result<T, E>) => Result<T, E>;
587
+ //#endregion
588
+ //#region src/operators/fold.d.ts
589
+ /**
590
+ * Folds the Result into a single value by applying one of two functions.
591
+ * The end of the pipe.
592
+ *
593
+ * This is the pipe operator equivalent of the `.fold()` instance method.
594
+ */
595
+ declare function fold<T, E, R$1>(handlers: {
596
+ ok: (val: T) => R$1;
597
+ err: (e: E) => R$1;
598
+ }): (source: Result<T, E>) => R$1;
599
+ /**
600
+ * @deprecated Use `fold` instead. Will be removed in next major version.
601
+ */
602
+ declare const match: typeof fold;
603
+ //#endregion
604
+ //#region src/operators/tryCatch.d.ts
605
+ /**
606
+ * Executes a function and catches exceptions.
607
+ * Converts exceptions into Result<E>.
608
+ * Equivalent to Rust `Result::from` for fallible operations.
609
+ */
610
+ declare function tryCatch<T, E = unknown>(fn: () => T, errorMapper?: (error: unknown) => E): <SourceT, SourceE>(source: Result<SourceT, SourceE>) => Result<T | SourceT, E | SourceE>;
611
+ //#endregion
612
+ //#region src/operators/tryMap.d.ts
613
+ /**
614
+ * Like `map`, but catches exceptions and turns them into Err.
615
+ */
616
+ declare function tryMap<T, E, U, F = unknown>(project: (value: T) => U, errorMapper?: (error: unknown) => F): (source: Result<T, E>) => Result<U, E | F>;
617
+ //#endregion
618
+ //#region src/operators/recover.d.ts
619
+ /**
620
+ * Recover: turns Err into Ok(defaultValue).
621
+ * Result is guaranteed Ok → error type becomes `never`.
622
+ */
623
+ declare function recover<T, E, D = T>(defaultValue: D): (source: Result<T, E>) => Result<T | D, never>;
624
+ /**
625
+ * Like `recover`, but computes the default value from the error.
626
+ */
627
+ declare function recoverWith<T, E, D = T>(fn: (error: E) => D): (source: Result<T, E>) => Result<T | D, never>;
628
+ //#endregion
629
+ //#region src/operators-async/mapAsync.d.ts
630
+ /**
631
+ * Async version of map.
632
+ */
633
+ declare function mapAsync<T, E, U>(project: (value: T) => Promise<U>): (source: Result<T, E>) => Promise<Result<Awaited<U>, E>>;
634
+ //#endregion
635
+ //#region src/operators-async/mapErrAsync.d.ts
636
+ /**
637
+ * Async version of mapErr.
638
+ */
639
+ declare function mapErrAsync<T, E, F>(project: (error: E) => Promise<F>): (source: Result<T, E>) => Promise<Result<T, F>>;
640
+ //#endregion
641
+ //#region src/operators-async/flatMapAsync.d.ts
642
+ /**
643
+ * Async version of flatMap.
644
+ * Allows different error types in the projected Result.
645
+ */
646
+ declare function flatMapAsync<T, E, U, E2 = E>(project: (value: T) => Promise<Result<U, E2>>): (source: Result<T, E>) => Promise<Result<U, E | E2>>;
647
+ //#endregion
648
+ //#region src/operators-async/tapAsync.d.ts
649
+ /**
650
+ * Async version of tap.
651
+ */
652
+ declare function tapAsync<T, E>(observer: {
653
+ ok?: (val: T) => Promise<void>;
654
+ err?: (e: E) => Promise<void>;
655
+ }): <SourceT extends T, SourceE extends E>(source: Result<SourceT, SourceE>) => Promise<Result<SourceT, SourceE>>;
656
+ //#endregion
657
+ //#region src/operators-async/filterAsync.d.ts
658
+ /**
659
+ * Async version of filter.
660
+ */
661
+ declare function filterAsync<T, E>(predicate: (val: T) => Promise<boolean>, errorFn: () => Promise<E>): (source: Result<T, E>) => Promise<Result<T, E>>;
662
+ //#endregion
663
+ //#region src/operators-async/foldAsync.d.ts
664
+ /**
665
+ * Async version of `fold`. Folds the Result into a single value asynchronously.
666
+ * The end of the pipe.
667
+ *
668
+ * This is the async pipe operator equivalent of the `.fold()` instance method.
669
+ */
670
+ declare function foldAsync<T, E, R$1>(handlers: {
671
+ ok: (val: T) => Promise<R$1>;
672
+ err: (e: E) => Promise<R$1>;
673
+ }): (source: Result<T, E>) => Promise<R$1>;
674
+ /**
675
+ * @deprecated Use `foldAsync` instead. Will be removed in next major version.
676
+ */
677
+ declare const matchAsync: typeof foldAsync;
678
+ //#endregion
679
+ //#region src/operators-async/tryCatchAsync.d.ts
680
+ /**
681
+ * Async version of tryCatch.
682
+ */
683
+ declare function tryCatchAsync<T, E = unknown>(fn: () => Promise<T>, errorMapper?: (error: unknown) => E): <SourceT, SourceE>(source: Result<SourceT, SourceE>) => Promise<Result<T, E | SourceE>>;
684
+ //#endregion
685
+ //#region src/operators-async/tryMapAsync.d.ts
686
+ /**
687
+ * Async version of tryMap.
688
+ */
689
+ declare function tryMapAsync<T, E, U, F = unknown>(project: (value: T) => Promise<U>, errorMapper?: (error: unknown) => F): (source: Result<T, E>) => Promise<Result<U, E | F>>;
690
+ //#endregion
691
+ //#region src/unwrap/unwrap.d.ts
692
+ /**
693
+ * Returns the value or throws an Error.
694
+ * Equivalent to Rust `unwrap`.
695
+ */
696
+ declare function unwrap<T, E>(result: Result<T, E>): T;
697
+ //#endregion
698
+ //#region src/unwrap/unwrapOr.d.ts
699
+ /**
700
+ * Returns the value or a default value.
701
+ * Pure function alternative to the instance method.
702
+ */
703
+ declare function unwrapOr<T, E, D = T>(result: Result<T, E>, defaultValue: D): T | D;
704
+ //#endregion
705
+ //#region src/unwrap/unwrapOrElse.d.ts
706
+ /**
707
+ * Returns the value or computes a default value with a function.
708
+ * Equivalent to Rust `unwrap_or_else`.
709
+ */
710
+ declare function unwrapOrElse<T, E, D = T>(result: Result<T, E>, fn: (error: E) => D): T | D;
711
+ //#endregion
712
+ //#region src/unwrap/unwrapOrDefault.d.ts
713
+ /**
714
+ * Alias for `unwrapOr`.
715
+ * Equivalent to Rust `unwrap_or_default` (with an explicit default value).
716
+ */
717
+ declare function unwrapOrDefault<T, E, D = T>(result: Result<T, E>, defaultValue: D): T | D;
718
+ //#endregion
719
+ //#region src/unwrap/unwrapOrThrow.d.ts
720
+ /**
721
+ * Returns the value or throws the original Err value (not wrapped).
722
+ * Useful to keep `Error` instances with stack traces.
723
+ */
724
+ declare function unwrapOrThrow<T, E>(result: Result<T, E>): T;
725
+ //#endregion
726
+ //#region src/unwrap/unwrapErr.d.ts
727
+ /**
728
+ * Returns the error or throws an Error.
729
+ * Equivalent to Rust `unwrap_err`.
730
+ */
731
+ declare function unwrapErr<T, E>(result: Result<T, E>): E;
732
+ //#endregion
733
+ //#region src/unwrap/expectResult.d.ts
734
+ /**
735
+ * Returns the value or throws an Error with a custom message.
736
+ * Equivalent to Rust `expect`.
737
+ */
738
+ declare function expectResult<T, E>(result: Result<T, E>, message: string): T;
739
+ //#endregion
740
+ //#region src/unwrap/expectErr.d.ts
741
+ /**
742
+ * Returns the error or throws an Error with a custom message.
743
+ * Equivalent to Rust `expect_err`.
744
+ */
745
+ declare function expectErr<T, E>(result: Result<T, E>, message: string): E;
746
+ //#endregion
747
+ //#region src/combinators/and.d.ts
748
+ /**
749
+ * Combines two Results. Returns the second only if the first is Ok.
750
+ * Equivalent to Rust `and`.
751
+ */
752
+ declare function and<T, E, U>(result: Result<T, E>, other: Result<U, E>): Result<U, E>;
753
+ //#endregion
754
+ //#region src/combinators/or.d.ts
755
+ /**
756
+ * Fallback to another Result when the first is Err.
757
+ * Equivalent to Rust `or`.
758
+ */
759
+ declare function or<T, E, T2 = T, E2 = E>(result: Result<T, E>, other: Result<T2, E2>): Result<T | T2, E2>;
760
+ //#endregion
761
+ //#region src/combinators/orElse.d.ts
762
+ /**
763
+ * Fallback using a function that returns a Result.
764
+ * Equivalent to Rust `or_else`.
765
+ */
766
+ declare function orElse<T, E, T2 = T, E2 = E>(result: Result<T, E>, fn: (error: E) => Result<T2, E2>): Result<T | T2, E2>;
767
+ //#endregion
768
+ //#region src/combinators/mapOr.d.ts
769
+ /**
770
+ * Transforms the value or returns a default value.
771
+ * Equivalent to Rust `map_or`.
772
+ */
773
+ declare function mapOr<T, E, U>(result: Result<T, E>, defaultValue: U, fn: (value: T) => U): U;
774
+ //#endregion
775
+ //#region src/combinators/mapOrElse.d.ts
776
+ /**
777
+ * Transforms the value or computes a default value with a function.
778
+ * Equivalent to Rust `map_or_else`.
779
+ */
780
+ declare function mapOrElse<T, E, U>(result: Result<T, E>, defaultFn: (error: E) => U, fn: (value: T) => U): U;
781
+ //#endregion
782
+ //#region src/combinators/zip.d.ts
783
+ /**
784
+ * Combines two Results into a Result of a tuple.
785
+ * Short-circuits on the first Err (left before right).
786
+ */
787
+ declare function zip<A, AE, B, BE>(left: Result<A, AE>, right: Result<B, BE>): Result<[A, B], AE | BE>;
788
+ declare function zip<A, AE, B, BE>(right: Result<B, BE>): (left: Result<A, AE>) => Result<[A, B], AE | BE>;
789
+ /**
790
+ * Combines two Results and collects errors.
791
+ * - Ok only if both are Ok
792
+ * - Err([errors]) if at least one is Err (left before right)
793
+ */
794
+ declare function combine<A, AE, B, BE>(left: Result<A, AE>, right: Result<B, BE>): Result<[A, B], Array<AE | BE>>;
795
+ declare function combine<A, AE, B, BE>(right: Result<B, BE>): (left: Result<A, AE>) => Result<[A, B], Array<AE | BE>>;
796
+ //#endregion
797
+ //#region src/combinators/swap.d.ts
798
+ /**
799
+ * Swaps Ok and Err.
800
+ * Result<T, E> → Result<E, T>
801
+ */
802
+ declare function swap<T, E>(result: Result<T, E>): Result<E, T>;
803
+ //#endregion
804
+ //#region src/collections/sequence.d.ts
805
+ type ResultLike$1<T, E> = {
806
+ isOk(): boolean;
807
+ isErr(): boolean;
808
+ readonly value: T | undefined;
809
+ readonly error: E | undefined;
810
+ };
811
+ type OkValueOf$3<R$1> = R$1 extends ResultLike$1<infer T, any> ? T : never;
812
+ type ErrValueOf$3<R$1> = R$1 extends ResultLike$1<any, infer E> ? E : never;
813
+ /**
814
+ * Combines a list of Results into a Result of a list.
815
+ * Short-circuits on the first Err.
816
+ * Analogous to Rust `collect::<Result<Vec<_>, _>>()`.
817
+ */
818
+ declare function sequence<const Results extends readonly ResultLike$1<any, any>[]>(results: Results): Result<Array<OkValueOf$3<Results[number]>>, ErrValueOf$3<Results[number]>>;
819
+ /**
820
+ * Alias for `sequence`.
821
+ */
822
+ declare function all<const Results extends readonly ResultLike$1<any, any>[]>(results: Results): Result<Array<OkValueOf$3<Results[number]>>, ErrValueOf$3<Results[number]>>;
823
+ //#endregion
824
+ //#region src/collections/sequenceRecord.d.ts
825
+ type ResultLike<T, E> = {
826
+ isOk(): boolean;
827
+ isErr(): boolean;
828
+ readonly value: T | undefined;
829
+ readonly error: E | undefined;
830
+ };
831
+ type OkValueOf$2<R$1> = R$1 extends ResultLike<infer T, any> ? T : never;
832
+ type ErrValueOf$2<R$1> = R$1 extends ResultLike<any, infer E> ? E : never;
833
+ /**
834
+ * Like `sequence`, but for records/objects.
835
+ * Short-circuits on the first Err.
836
+ */
837
+ declare function sequenceRecord<const R$1 extends Record<string, ResultLike<any, any>>>(record: R$1): Result<{ [K in keyof R$1]: OkValueOf$2<R$1[K]> }, ErrValueOf$2<R$1[keyof R$1]>>;
838
+ //#endregion
839
+ //#region src/collections/collectFirstOk.d.ts
840
+ /**
841
+ * Parse a set of `Result`s, short-circuits when an input value is `Ok`.
842
+ * If no `Ok` is found, returns an `Err` containing the collected error values.
843
+ * Useful for "try multiple approaches until one works" patterns.
844
+ */
845
+ declare function collectFirstOk<T, E>(results: readonly (Result<T, E> | Result<T, never> | Result<never, E>)[]): Result<T, E[]>;
846
+ //#endregion
847
+ //#region src/collections/collectFirstOkAsync.d.ts
848
+ type CollectFirstOkAsyncInput$1 = Promise<Result<any, any>> | (() => Awaitable<Result<any, any>>);
849
+ type ResolvedResult$1<I> = I extends (() => infer R) ? Awaited<R> : I extends Promise<infer R> ? R : never;
850
+ type OkValueOfInput$1<I> = ResolvedResult$1<I> extends Result<infer T, any> ? T : never;
851
+ type ErrValueOfInput$1<I> = ResolvedResult$1<I> extends Result<any, infer E> ? E : never;
852
+ /**
853
+ * Async version of collectFirstOk.
854
+ *
855
+ * - Accepts already-started promises or "thunks" (`() => Awaitable<Result<...>>`).
856
+ * - Processes inputs strictly sequentially (like `for ... of` + `await`).
857
+ * - Returns the first `Ok` and collects all errors when no `Ok` is found.
858
+ */
859
+ declare function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput$1[]>(inputs: Inputs): Promise<Result<OkValueOfInput$1<Inputs[number]>, ErrValueOfInput$1<Inputs[number]>[]>>;
860
+ //#endregion
861
+ //#region src/collections/collectFirstOkRaceAsync.d.ts
862
+ type CollectFirstOkAsyncInput = Promise<Result<any, any>> | (() => Awaitable<Result<any, any>>);
863
+ type ResolvedResult<I> = I extends (() => infer R) ? Awaited<R> : I extends Promise<infer R> ? R : never;
864
+ type OkValueOfInput<I> = ResolvedResult<I> extends Result<infer T, any> ? T : never;
865
+ type ErrValueOfInput<I> = ResolvedResult<I> extends Result<any, infer E> ? E : never;
866
+ /**
867
+ * Parallel/race variant of `collectFirstOkAsync`.
868
+ *
869
+ * - Starts all inputs immediately (promises or thunks).
870
+ * - Returns the first `Ok` as soon as it is available.
871
+ * - If no `Ok` is found, returns an `Err` with all error values (in input order).
872
+ * - **Note**: There is no cancellation logic. All inputs keep running even after the first `Ok` is found.
873
+ */
874
+ declare function collectFirstOkRaceAsync<const Inputs extends readonly CollectFirstOkAsyncInput[]>(inputs: Inputs): Promise<Result<OkValueOfInput<Inputs[number]>, ErrValueOfInput<Inputs[number]>[]>>;
875
+ //#endregion
876
+ //#region src/collections/collectAllErrors.d.ts
877
+ type OkValueOf$1<R$1> = R$1 extends Result<infer T, any> ? T : never;
878
+ type ErrValueOf$1<R$1> = R$1 extends Result<any, infer E> ? E : never;
879
+ /**
880
+ * Combines a list of Results.
881
+ * Returns Ok(values) only if all are Ok, otherwise Err([errors]).
882
+ */
883
+ declare function collectAllErrors<const Results extends readonly Result<any, any>[]>(results: Results): Result<Array<OkValueOf$1<Results[number]>>, Array<ErrValueOf$1<Results[number]>>>;
884
+ //#endregion
885
+ //#region src/collections/partition.d.ts
886
+ type OkValueOf<R$1> = R$1 extends Result<infer T, any> ? T : never;
887
+ type ErrValueOf<R$1> = R$1 extends Result<any, infer E> ? E : never;
888
+ /**
889
+ * Partitions Results into Ok values and Err errors.
890
+ */
891
+ declare function partition<const Results extends readonly Result<any, any>[]>(results: Results): [oks: Array<OkValueOf<Results[number]>>, errs: Array<ErrValueOf<Results[number]>>];
892
+ //#endregion
893
+ //#region src/collections/flatten.d.ts
894
+ /**
895
+ * Flacht ein nested Result ab.
896
+ * Result<Result<T, E>, E> → Result<T, E>
897
+ * Entspricht Rust `flatten`.
898
+ */
899
+ declare function flatten<T, E>(result: Result<Result<T, E>, E>): Result<T, E>;
900
+ //#endregion
901
+ //#region src/conversions/fromPromise.d.ts
902
+ /**
903
+ * Converts a Promise to a Result-Promise.
904
+ * Exceptions are converted to Err.
905
+ *
906
+ * @param promise The Promise to convert
907
+ * @param errorMapper Optional function to map errors to a specific type
908
+ * @returns A Promise that resolves to an Ok Result with the value, or an Err Result with the error
909
+ *
910
+ * @example
911
+ * ```ts
912
+ * const result = await fromPromise(fetch('/api/user'));
913
+ * // Ok(response) or Err(error)
914
+ *
915
+ * // With custom error mapper
916
+ * const result = await fromPromise(
917
+ * fetch('/api/user'),
918
+ * (e) => `Network error: ${e}`
919
+ * );
920
+ * ```
921
+ */
922
+ declare function fromPromise<T>(promise: Promise<T>): Promise<Result<T, unknown>>;
923
+ declare function fromPromise<T, E>(promise: Promise<T>, errorMapper?: (error: unknown) => E): Promise<Result<T, E>>;
924
+ //#endregion
925
+ //#region src/conversions/fromNullable.d.ts
926
+ /**
927
+ * Converts `null | undefined` to `Err`, everything else to `Ok`.
928
+ *
929
+ * **Type Safety**: The type assertion `as NonNullable<T>` is safe,
930
+ * as the runtime check guarantees that the value is not null/undefined.
931
+ *
932
+ * @param value The value to check
933
+ * @param error The error to use if value is null/undefined
934
+ * @returns An Ok Result with the NonNullable value, or an Err Result with the error
935
+ *
936
+ * @example
937
+ * ```ts
938
+ * fromNullable(user, 'User not found')
939
+ * // Ok(user) or Err('User not found')
940
+ * ```
941
+ */
942
+ declare function fromNullable<T, E>(value: T, error: E): Result<NonNullable<T>, E>;
943
+ //#endregion
944
+ //#region src/conversions/try.d.ts
945
+ /**
946
+ * Executes a function and catches exceptions.
947
+ *
948
+ * @param fn The function to execute
949
+ * @returns An Ok Result with the return value, or an Err Result with the caught exception
950
+ *
951
+ * @example
952
+ * ```ts
953
+ * const result = tryFn(() => JSON.parse(input));
954
+ * // Ok(parsed) or Err(SyntaxError)
955
+ * ```
956
+ */
957
+ declare function tryFn<T>(fn: () => T): Result<T, unknown>;
958
+ //#endregion
959
+ //#region src/conversions/toPromise.d.ts
960
+ /**
961
+ * Converts a Result to a Promise.
962
+ * Ok → resolves with the value, Err → rejects with the error
963
+ *
964
+ * @param result The Result to convert
965
+ * @returns A Promise that resolves with the value if Ok, or rejects with the error if Err
966
+ *
967
+ * @example
968
+ * ```ts
969
+ * const result = ok(42);
970
+ * const promise = toPromise(result);
971
+ * const value = await promise; // 42
972
+ * ```
973
+ */
974
+ declare function toPromise<T, E>(result: Result<T, E>): Promise<T>;
975
+ //#endregion
976
+ //#region src/conversions/toNullable.d.ts
977
+ /**
978
+ * Converts a Result to `T | null`.
979
+ * Ok → returns the value, Err → returns null
980
+ *
981
+ * @param result The Result to convert
982
+ * @returns The value if Ok, or null if Err
983
+ *
984
+ * @example
985
+ * ```ts
986
+ * const result = ok(42);
987
+ * const value = toNullable(result); // 42
988
+ *
989
+ * const errResult = err('error');
990
+ * const nullValue = toNullable(errResult); // null
991
+ * ```
992
+ */
993
+ declare function toNullable<T, E>(result: Result<T, E>): T | null;
994
+ //#endregion
995
+ //#region src/utils/isOk.d.ts
996
+ /**
997
+ * Checks whether a Result is Ok.
998
+ * Pure function alternative to the instance method.
999
+ */
1000
+ declare function isOk<T, E>(result: Result<T, E>): result is Result<T, E> & {
1001
+ readonly value: T;
1002
+ readonly error: undefined;
1003
+ };
1004
+ //#endregion
1005
+ //#region src/utils/isErr.d.ts
1006
+ /**
1007
+ * Checks whether a Result is Err.
1008
+ * Pure function alternative to the instance method.
1009
+ */
1010
+ declare function isErr<T, E>(result: Result<T, E>): result is Result<T, E> & {
1011
+ readonly value: undefined;
1012
+ readonly error: E;
1013
+ };
1014
+ //#endregion
1015
+ //#region src/utils/contains.d.ts
1016
+ /**
1017
+ * Checks whether the Result contains a specific value.
1018
+ * Equivalent to Rust `contains`.
1019
+ */
1020
+ declare function contains<T, E>(result: Result<any, E>, value: T): boolean;
1021
+ //#endregion
1022
+ //#region src/utils/containsErr.d.ts
1023
+ /**
1024
+ * Checks whether the Result contains a specific error.
1025
+ * Analogous to `contains` for the Err case.
1026
+ */
1027
+ declare function containsErr<T, E>(result: Result<T, E>, error: E): boolean;
1028
+ //#endregion
1029
+ //#region src/utils/isResult.d.ts
1030
+ declare function isResult(value: unknown): value is Result<any, any>;
1031
+ //#endregion
1032
+ export { AsyncOperatorFunction, type Awaitable, Err, Ok, OperatorFunction, Result, ResultType, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkRaceAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
1033
+ //# sourceMappingURL=index.d.cts.map