lite-fp 0.4.0 → 0.5.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/index.d.mts +227 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
type Left<A> = {
|
|
2
|
+
readonly $: "Left";
|
|
3
|
+
readonly value: A;
|
|
4
|
+
};
|
|
5
|
+
type Right<B> = {
|
|
6
|
+
readonly $: "Right";
|
|
7
|
+
readonly value: B;
|
|
8
|
+
};
|
|
9
|
+
declare const left: <A>(value: A) => Left<A>;
|
|
10
|
+
declare const right: <B>(value: B) => Right<B>;
|
|
11
|
+
declare const isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
12
|
+
declare const isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
13
|
+
declare const getLeft: <A>(e: Left<A>) => A;
|
|
14
|
+
declare const getRight: <B>(e: Right<B>) => B;
|
|
15
|
+
type Either<A, B> = Left<A> | Right<B>;
|
|
16
|
+
declare const Either: {
|
|
17
|
+
left: <A>(value: A) => Left<A>;
|
|
18
|
+
right: <B>(value: B) => Right<B>;
|
|
19
|
+
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
20
|
+
isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
21
|
+
isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
22
|
+
fromNullable: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
23
|
+
fromThrowable: <A, B>(fn: () => B, onError: (e: unknown) => A) => Either<A, B>;
|
|
24
|
+
fromPromise: <A, B>(promise: Promise<B>, onError: (e: unknown) => A) => Promise<Either<A, B>>;
|
|
25
|
+
map: <A, B, C>(e: Either<A, B>, fn: (r: B) => C) => Either<A, C>;
|
|
26
|
+
mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
27
|
+
bimap: <A, B, C, D>(e: Either<A, B>, fl: (l: A) => C, fr: (r: B) => D) => Either<C, D>;
|
|
28
|
+
flatMap: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
29
|
+
chain: <A, B, C>(e: Either<A, B>, fn: (r: B) => Either<A, C>) => Either<A, C>;
|
|
30
|
+
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
31
|
+
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
32
|
+
right: (value: B) => C;
|
|
33
|
+
left: (value: A) => C;
|
|
34
|
+
}) => C;
|
|
35
|
+
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
36
|
+
getLeft: <A>(e: Left<A>) => A;
|
|
37
|
+
getRight: <B>(e: Right<B>) => B;
|
|
38
|
+
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
39
|
+
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
40
|
+
getOrThrow: <A, B>(e: Either<A, B>) => B;
|
|
41
|
+
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
42
|
+
apply: <E, A, B>(fn: Either<E, (value: A) => B>, arg: Either<E, A>) => Either<E, B>;
|
|
43
|
+
tap: <A, B>(e: Either<A, B>, f: (r: B) => void) => Either<A, B>;
|
|
44
|
+
tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
45
|
+
};
|
|
46
|
+
declare global {
|
|
47
|
+
interface Promise<T> {
|
|
48
|
+
toEither<A>(onError: (e: unknown) => A): Promise<Either<A, T>>;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type NothingNull = null;
|
|
53
|
+
type NothingUndefined = undefined;
|
|
54
|
+
type Nothing = NothingNull | NothingUndefined;
|
|
55
|
+
declare const just: <T>(value: T) => Maybe<T>;
|
|
56
|
+
declare const nothing: () => Nothing;
|
|
57
|
+
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
58
|
+
declare const isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
59
|
+
type Maybe<T> = T | Nothing;
|
|
60
|
+
declare const Maybe: {
|
|
61
|
+
just: <T>(value: T) => Maybe<T>;
|
|
62
|
+
nothing: () => Nothing;
|
|
63
|
+
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
64
|
+
nothingNull: () => NothingNull;
|
|
65
|
+
nothingUndefined: () => NothingUndefined;
|
|
66
|
+
isJust: <T>(m: Maybe<T>) => m is T;
|
|
67
|
+
isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
68
|
+
isNothingNull: <T>(m: Maybe<T>) => m is NothingNull;
|
|
69
|
+
isNothingUndefined: <T>(m: Maybe<T>) => m is NothingUndefined;
|
|
70
|
+
fromNullable: <T>(m: T | null | undefined) => Maybe<T>;
|
|
71
|
+
fromThrowable: <T>(fn: () => T) => Maybe<T>;
|
|
72
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Maybe<T>>;
|
|
73
|
+
toNullable: <T>(m: Maybe<T>) => T | null;
|
|
74
|
+
toUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
75
|
+
map: <T, U>(m: Maybe<T>, fn: (v: T) => U) => Maybe<U>;
|
|
76
|
+
flatMap: <T, U>(m: Maybe<T>, fn: (v: T) => Maybe<U>) => Maybe<U>;
|
|
77
|
+
filter: <T>(m: Maybe<T>, predicate: (value: T) => boolean) => Maybe<T>;
|
|
78
|
+
match: <T, U>(m: Maybe<T>, matcher: {
|
|
79
|
+
some: (v: T) => U;
|
|
80
|
+
nothing: () => U;
|
|
81
|
+
}) => U;
|
|
82
|
+
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
83
|
+
getOrElse: <T>(m: Maybe<T>, d: T) => T;
|
|
84
|
+
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
85
|
+
getOrThrow: <T>(m: Maybe<T>) => T;
|
|
86
|
+
zip: <T, U>(a: Maybe<T>, b: Maybe<U>) => Maybe<[T, U]>;
|
|
87
|
+
apply: <T, U>(fn: Maybe<(value: T) => U>, opt: Maybe<T>) => Maybe<U>;
|
|
88
|
+
orElse: <T>(opt: Maybe<T>, other: Maybe<T>) => Maybe<T>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type None = {
|
|
92
|
+
readonly $: "None";
|
|
93
|
+
};
|
|
94
|
+
type Some<T> = {
|
|
95
|
+
readonly $: "Some";
|
|
96
|
+
readonly value: T;
|
|
97
|
+
};
|
|
98
|
+
declare const none: <T>() => Option<T>;
|
|
99
|
+
declare const some: <T>(value: T) => Option<T>;
|
|
100
|
+
declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
101
|
+
declare const isNone: <T>(option: Option<T>) => option is None;
|
|
102
|
+
declare const unwrap: <T>(option: Some<T>) => T;
|
|
103
|
+
type Option<T> = None | Some<T>;
|
|
104
|
+
declare const Option: {
|
|
105
|
+
none: <T>() => Option<T>;
|
|
106
|
+
some: <T>(value: T) => Option<T>;
|
|
107
|
+
new: <T>(value: T | null | undefined) => Option<T>;
|
|
108
|
+
isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
109
|
+
isNone: <T>(option: Option<T>) => option is None;
|
|
110
|
+
fromNullable: <T>(value: T | null | undefined) => Option<T>;
|
|
111
|
+
fromPredicate: <T>(value: T, predicate: (value: T) => boolean) => Option<T>;
|
|
112
|
+
fromThrowable: <T>(fn: () => T) => Option<T>;
|
|
113
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Option<T>>;
|
|
114
|
+
map: <T, U>(option: Option<T>, fn: (value: T) => U) => Option<U>;
|
|
115
|
+
flatMap: <T, U>(option: Option<T>, fn: (value: T) => Option<U>) => Option<U>;
|
|
116
|
+
filter: <T>(option: Option<T>, predicate: (value: T) => boolean) => Option<T>;
|
|
117
|
+
match: <T, U>(option: Option<T>, matcher: {
|
|
118
|
+
some: (value: T) => U;
|
|
119
|
+
none: () => U;
|
|
120
|
+
}) => U;
|
|
121
|
+
unwrap: <T>(option: Some<T>) => T;
|
|
122
|
+
getOrElse: <T>(option: Option<T>, defaultValue: T) => T;
|
|
123
|
+
getOrUndefined: <T>(option: Option<T>) => T | undefined;
|
|
124
|
+
getOrThrow: <T>(option: Option<T>) => T;
|
|
125
|
+
zip: <T, U>(a: Option<T>, b: Option<U>) => Option<[T, U]>;
|
|
126
|
+
apply: <T, U>(fn: Option<(value: T) => U>, opt: Option<T>) => Option<U>;
|
|
127
|
+
orElse: <T>(opt: Option<T>, other: Option<T>) => Option<T>;
|
|
128
|
+
};
|
|
129
|
+
declare global {
|
|
130
|
+
interface Array<T> {
|
|
131
|
+
firstOption(): Option<T>;
|
|
132
|
+
}
|
|
133
|
+
interface Promise<T> {
|
|
134
|
+
toOption(): Promise<Option<T>>;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
139
|
+
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
140
|
+
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
141
|
+
type Pair<A, B> = readonly [A, B];
|
|
142
|
+
declare const Pair: {
|
|
143
|
+
fst: <A, B>(p: Pair<A, B>) => A;
|
|
144
|
+
snd: <A, B>(p: Pair<A, B>) => B;
|
|
145
|
+
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
146
|
+
fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
147
|
+
fromObject: <A, B>(obj: {
|
|
148
|
+
fst: A;
|
|
149
|
+
snd: B;
|
|
150
|
+
}) => Pair<A, B>;
|
|
151
|
+
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
152
|
+
mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
153
|
+
mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
154
|
+
map: <A, B, C, D>(p: Pair<A, B>, fnA: (a: A) => C, fnB: (b: B) => D) => Pair<C, D>;
|
|
155
|
+
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
156
|
+
apply: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
157
|
+
apply2: <A, B, C>(fnPair: Pair<(a: A) => B, (b: B) => C>, vPair: Pair<A, B>) => Pair<A, C>;
|
|
158
|
+
reduce: <A, B, C>(p: Pair<A, B>, fn: (a: A, b: B) => C) => C;
|
|
159
|
+
toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
160
|
+
toObject: <A, B>(p: Pair<A, B>) => {
|
|
161
|
+
fst: A;
|
|
162
|
+
snd: B;
|
|
163
|
+
};
|
|
164
|
+
eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
165
|
+
equals: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>, eqA: (a1: A, a2: A) => boolean, eqB: (b1: B, b2: B) => boolean) => boolean;
|
|
166
|
+
zip: <A, B, C, D>(p1: Pair<A, B>, p2: Pair<C, D>) => Pair<Pair<A, C>, Pair<B, D>>;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type Done<T> = {
|
|
170
|
+
readonly v: T;
|
|
171
|
+
};
|
|
172
|
+
type Fail<E> = {
|
|
173
|
+
readonly e: E;
|
|
174
|
+
};
|
|
175
|
+
declare const done: <T>(v: T) => Done<T>;
|
|
176
|
+
declare const fail: <E>(e: E) => Fail<E>;
|
|
177
|
+
declare const Ok: <T>(v: T) => Done<T>;
|
|
178
|
+
declare const Err: <E>(e: E) => Fail<E>;
|
|
179
|
+
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
180
|
+
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
181
|
+
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
182
|
+
declare const isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
183
|
+
declare const val: <T>(r: Done<T>) => T;
|
|
184
|
+
declare const err: <E>(r: Fail<E>) => E;
|
|
185
|
+
type Result<T, E> = Done<T> | Fail<E>;
|
|
186
|
+
declare const Result: {
|
|
187
|
+
done: <T>(v: T) => Done<T>;
|
|
188
|
+
fail: <E>(e: E) => Fail<E>;
|
|
189
|
+
Ok: <T>(v: T) => Done<T>;
|
|
190
|
+
Err: <E>(e: E) => Fail<E>;
|
|
191
|
+
val: <T>(r: Done<T>) => T;
|
|
192
|
+
err: <E>(r: Fail<E>) => E;
|
|
193
|
+
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
194
|
+
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
195
|
+
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
196
|
+
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
197
|
+
isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
198
|
+
fromNullable: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
199
|
+
fromThrowable: <T, E>(fn: () => T, onError: (e: unknown) => E) => Result<T, E>;
|
|
200
|
+
fromPromise: <T, E>(promise: Promise<T>, onError: (e: unknown) => E) => Promise<Result<T, E>>;
|
|
201
|
+
map: <T, E, U>(r: Result<T, E>, fn: (a: T) => U) => Result<U, E>;
|
|
202
|
+
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
203
|
+
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
204
|
+
flatMap: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
205
|
+
match: <T, E, U>(r: Result<T, E>, matcher: {
|
|
206
|
+
done: (a: T) => U;
|
|
207
|
+
fail: (b: E) => U;
|
|
208
|
+
}) => U;
|
|
209
|
+
fold: <T, E, U>(r: Result<T, E>, onFail: (error: E) => U, onDone: (value: T) => U) => U;
|
|
210
|
+
recover: <T, E>(r: Result<T, E>, fn: (error: E) => T) => Result<T, E>;
|
|
211
|
+
getOrElse: <T, E>(r: Result<T, E>, d: T) => T;
|
|
212
|
+
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
213
|
+
getOrThrow: <T, E>(r: Result<T, E>) => T;
|
|
214
|
+
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
215
|
+
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
216
|
+
orElse: <T, E>(a: Result<T, E>, b: Result<T, E>) => Result<T, E>;
|
|
217
|
+
filter: <T, E>(r: Result<T, E>, predicate: (a: T) => boolean, onFalse: E) => Result<T, E>;
|
|
218
|
+
tap: <T, E>(r: Result<T, E>, f: (a: T) => void) => Result<T, E>;
|
|
219
|
+
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
220
|
+
};
|
|
221
|
+
declare global {
|
|
222
|
+
interface Promise<T> {
|
|
223
|
+
toResult<E = unknown>(onError: (e: unknown) => E): Promise<Result<T, E>>;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { type Done, Either, Err, type Fail, type Left, Maybe, type None, type Nothing, type NothingNull, type NothingUndefined, Ok, Option, Pair, Result, type Right, type Some, done, err, fail, fst, getLeft, getRight, isDone, isErr, isFail, isJust, isLeft, isNone, isNothing, isOk, isRight, isSome, just, left, none, nothing, pair, right, snd, some, unwrap, val };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
type Left<A> = {
|
|
2
|
+
readonly $: "Left";
|
|
3
|
+
readonly value: A;
|
|
4
|
+
};
|
|
5
|
+
type Right<B> = {
|
|
6
|
+
readonly $: "Right";
|
|
7
|
+
readonly value: B;
|
|
8
|
+
};
|
|
9
|
+
declare const left: <A>(value: A) => Left<A>;
|
|
10
|
+
declare const right: <B>(value: B) => Right<B>;
|
|
11
|
+
declare const isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
12
|
+
declare const isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
13
|
+
declare const getLeft: <A>(e: Left<A>) => A;
|
|
14
|
+
declare const getRight: <B>(e: Right<B>) => B;
|
|
15
|
+
type Either<A, B> = Left<A> | Right<B>;
|
|
16
|
+
declare const Either: {
|
|
17
|
+
left: <A>(value: A) => Left<A>;
|
|
18
|
+
right: <B>(value: B) => Right<B>;
|
|
19
|
+
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
20
|
+
isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
21
|
+
isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
22
|
+
fromNullable: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
23
|
+
fromThrowable: <A, B>(fn: () => B, onError: (e: unknown) => A) => Either<A, B>;
|
|
24
|
+
fromPromise: <A, B>(promise: Promise<B>, onError: (e: unknown) => A) => Promise<Either<A, B>>;
|
|
25
|
+
map: <A, B, C>(e: Either<A, B>, fn: (r: B) => C) => Either<A, C>;
|
|
26
|
+
mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
27
|
+
bimap: <A, B, C, D>(e: Either<A, B>, fl: (l: A) => C, fr: (r: B) => D) => Either<C, D>;
|
|
28
|
+
flatMap: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
29
|
+
chain: <A, B, C>(e: Either<A, B>, fn: (r: B) => Either<A, C>) => Either<A, C>;
|
|
30
|
+
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
31
|
+
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
32
|
+
right: (value: B) => C;
|
|
33
|
+
left: (value: A) => C;
|
|
34
|
+
}) => C;
|
|
35
|
+
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
36
|
+
getLeft: <A>(e: Left<A>) => A;
|
|
37
|
+
getRight: <B>(e: Right<B>) => B;
|
|
38
|
+
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
39
|
+
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
40
|
+
getOrThrow: <A, B>(e: Either<A, B>) => B;
|
|
41
|
+
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
42
|
+
apply: <E, A, B>(fn: Either<E, (value: A) => B>, arg: Either<E, A>) => Either<E, B>;
|
|
43
|
+
tap: <A, B>(e: Either<A, B>, f: (r: B) => void) => Either<A, B>;
|
|
44
|
+
tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
45
|
+
};
|
|
46
|
+
declare global {
|
|
47
|
+
interface Promise<T> {
|
|
48
|
+
toEither<A>(onError: (e: unknown) => A): Promise<Either<A, T>>;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type NothingNull = null;
|
|
53
|
+
type NothingUndefined = undefined;
|
|
54
|
+
type Nothing = NothingNull | NothingUndefined;
|
|
55
|
+
declare const just: <T>(value: T) => Maybe<T>;
|
|
56
|
+
declare const nothing: () => Nothing;
|
|
57
|
+
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
58
|
+
declare const isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
59
|
+
type Maybe<T> = T | Nothing;
|
|
60
|
+
declare const Maybe: {
|
|
61
|
+
just: <T>(value: T) => Maybe<T>;
|
|
62
|
+
nothing: () => Nothing;
|
|
63
|
+
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
64
|
+
nothingNull: () => NothingNull;
|
|
65
|
+
nothingUndefined: () => NothingUndefined;
|
|
66
|
+
isJust: <T>(m: Maybe<T>) => m is T;
|
|
67
|
+
isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
68
|
+
isNothingNull: <T>(m: Maybe<T>) => m is NothingNull;
|
|
69
|
+
isNothingUndefined: <T>(m: Maybe<T>) => m is NothingUndefined;
|
|
70
|
+
fromNullable: <T>(m: T | null | undefined) => Maybe<T>;
|
|
71
|
+
fromThrowable: <T>(fn: () => T) => Maybe<T>;
|
|
72
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Maybe<T>>;
|
|
73
|
+
toNullable: <T>(m: Maybe<T>) => T | null;
|
|
74
|
+
toUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
75
|
+
map: <T, U>(m: Maybe<T>, fn: (v: T) => U) => Maybe<U>;
|
|
76
|
+
flatMap: <T, U>(m: Maybe<T>, fn: (v: T) => Maybe<U>) => Maybe<U>;
|
|
77
|
+
filter: <T>(m: Maybe<T>, predicate: (value: T) => boolean) => Maybe<T>;
|
|
78
|
+
match: <T, U>(m: Maybe<T>, matcher: {
|
|
79
|
+
some: (v: T) => U;
|
|
80
|
+
nothing: () => U;
|
|
81
|
+
}) => U;
|
|
82
|
+
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
83
|
+
getOrElse: <T>(m: Maybe<T>, d: T) => T;
|
|
84
|
+
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
85
|
+
getOrThrow: <T>(m: Maybe<T>) => T;
|
|
86
|
+
zip: <T, U>(a: Maybe<T>, b: Maybe<U>) => Maybe<[T, U]>;
|
|
87
|
+
apply: <T, U>(fn: Maybe<(value: T) => U>, opt: Maybe<T>) => Maybe<U>;
|
|
88
|
+
orElse: <T>(opt: Maybe<T>, other: Maybe<T>) => Maybe<T>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type None = {
|
|
92
|
+
readonly $: "None";
|
|
93
|
+
};
|
|
94
|
+
type Some<T> = {
|
|
95
|
+
readonly $: "Some";
|
|
96
|
+
readonly value: T;
|
|
97
|
+
};
|
|
98
|
+
declare const none: <T>() => Option<T>;
|
|
99
|
+
declare const some: <T>(value: T) => Option<T>;
|
|
100
|
+
declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
101
|
+
declare const isNone: <T>(option: Option<T>) => option is None;
|
|
102
|
+
declare const unwrap: <T>(option: Some<T>) => T;
|
|
103
|
+
type Option<T> = None | Some<T>;
|
|
104
|
+
declare const Option: {
|
|
105
|
+
none: <T>() => Option<T>;
|
|
106
|
+
some: <T>(value: T) => Option<T>;
|
|
107
|
+
new: <T>(value: T | null | undefined) => Option<T>;
|
|
108
|
+
isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
109
|
+
isNone: <T>(option: Option<T>) => option is None;
|
|
110
|
+
fromNullable: <T>(value: T | null | undefined) => Option<T>;
|
|
111
|
+
fromPredicate: <T>(value: T, predicate: (value: T) => boolean) => Option<T>;
|
|
112
|
+
fromThrowable: <T>(fn: () => T) => Option<T>;
|
|
113
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Option<T>>;
|
|
114
|
+
map: <T, U>(option: Option<T>, fn: (value: T) => U) => Option<U>;
|
|
115
|
+
flatMap: <T, U>(option: Option<T>, fn: (value: T) => Option<U>) => Option<U>;
|
|
116
|
+
filter: <T>(option: Option<T>, predicate: (value: T) => boolean) => Option<T>;
|
|
117
|
+
match: <T, U>(option: Option<T>, matcher: {
|
|
118
|
+
some: (value: T) => U;
|
|
119
|
+
none: () => U;
|
|
120
|
+
}) => U;
|
|
121
|
+
unwrap: <T>(option: Some<T>) => T;
|
|
122
|
+
getOrElse: <T>(option: Option<T>, defaultValue: T) => T;
|
|
123
|
+
getOrUndefined: <T>(option: Option<T>) => T | undefined;
|
|
124
|
+
getOrThrow: <T>(option: Option<T>) => T;
|
|
125
|
+
zip: <T, U>(a: Option<T>, b: Option<U>) => Option<[T, U]>;
|
|
126
|
+
apply: <T, U>(fn: Option<(value: T) => U>, opt: Option<T>) => Option<U>;
|
|
127
|
+
orElse: <T>(opt: Option<T>, other: Option<T>) => Option<T>;
|
|
128
|
+
};
|
|
129
|
+
declare global {
|
|
130
|
+
interface Array<T> {
|
|
131
|
+
firstOption(): Option<T>;
|
|
132
|
+
}
|
|
133
|
+
interface Promise<T> {
|
|
134
|
+
toOption(): Promise<Option<T>>;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
139
|
+
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
140
|
+
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
141
|
+
type Pair<A, B> = readonly [A, B];
|
|
142
|
+
declare const Pair: {
|
|
143
|
+
fst: <A, B>(p: Pair<A, B>) => A;
|
|
144
|
+
snd: <A, B>(p: Pair<A, B>) => B;
|
|
145
|
+
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
146
|
+
fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
147
|
+
fromObject: <A, B>(obj: {
|
|
148
|
+
fst: A;
|
|
149
|
+
snd: B;
|
|
150
|
+
}) => Pair<A, B>;
|
|
151
|
+
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
152
|
+
mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
153
|
+
mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
154
|
+
map: <A, B, C, D>(p: Pair<A, B>, fnA: (a: A) => C, fnB: (b: B) => D) => Pair<C, D>;
|
|
155
|
+
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
156
|
+
apply: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
157
|
+
apply2: <A, B, C>(fnPair: Pair<(a: A) => B, (b: B) => C>, vPair: Pair<A, B>) => Pair<A, C>;
|
|
158
|
+
reduce: <A, B, C>(p: Pair<A, B>, fn: (a: A, b: B) => C) => C;
|
|
159
|
+
toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
160
|
+
toObject: <A, B>(p: Pair<A, B>) => {
|
|
161
|
+
fst: A;
|
|
162
|
+
snd: B;
|
|
163
|
+
};
|
|
164
|
+
eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
165
|
+
equals: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>, eqA: (a1: A, a2: A) => boolean, eqB: (b1: B, b2: B) => boolean) => boolean;
|
|
166
|
+
zip: <A, B, C, D>(p1: Pair<A, B>, p2: Pair<C, D>) => Pair<Pair<A, C>, Pair<B, D>>;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type Done<T> = {
|
|
170
|
+
readonly v: T;
|
|
171
|
+
};
|
|
172
|
+
type Fail<E> = {
|
|
173
|
+
readonly e: E;
|
|
174
|
+
};
|
|
175
|
+
declare const done: <T>(v: T) => Done<T>;
|
|
176
|
+
declare const fail: <E>(e: E) => Fail<E>;
|
|
177
|
+
declare const Ok: <T>(v: T) => Done<T>;
|
|
178
|
+
declare const Err: <E>(e: E) => Fail<E>;
|
|
179
|
+
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
180
|
+
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
181
|
+
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
182
|
+
declare const isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
183
|
+
declare const val: <T>(r: Done<T>) => T;
|
|
184
|
+
declare const err: <E>(r: Fail<E>) => E;
|
|
185
|
+
type Result<T, E> = Done<T> | Fail<E>;
|
|
186
|
+
declare const Result: {
|
|
187
|
+
done: <T>(v: T) => Done<T>;
|
|
188
|
+
fail: <E>(e: E) => Fail<E>;
|
|
189
|
+
Ok: <T>(v: T) => Done<T>;
|
|
190
|
+
Err: <E>(e: E) => Fail<E>;
|
|
191
|
+
val: <T>(r: Done<T>) => T;
|
|
192
|
+
err: <E>(r: Fail<E>) => E;
|
|
193
|
+
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
194
|
+
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
195
|
+
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
196
|
+
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
197
|
+
isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
198
|
+
fromNullable: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
199
|
+
fromThrowable: <T, E>(fn: () => T, onError: (e: unknown) => E) => Result<T, E>;
|
|
200
|
+
fromPromise: <T, E>(promise: Promise<T>, onError: (e: unknown) => E) => Promise<Result<T, E>>;
|
|
201
|
+
map: <T, E, U>(r: Result<T, E>, fn: (a: T) => U) => Result<U, E>;
|
|
202
|
+
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
203
|
+
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
204
|
+
flatMap: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
205
|
+
match: <T, E, U>(r: Result<T, E>, matcher: {
|
|
206
|
+
done: (a: T) => U;
|
|
207
|
+
fail: (b: E) => U;
|
|
208
|
+
}) => U;
|
|
209
|
+
fold: <T, E, U>(r: Result<T, E>, onFail: (error: E) => U, onDone: (value: T) => U) => U;
|
|
210
|
+
recover: <T, E>(r: Result<T, E>, fn: (error: E) => T) => Result<T, E>;
|
|
211
|
+
getOrElse: <T, E>(r: Result<T, E>, d: T) => T;
|
|
212
|
+
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
213
|
+
getOrThrow: <T, E>(r: Result<T, E>) => T;
|
|
214
|
+
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
215
|
+
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
216
|
+
orElse: <T, E>(a: Result<T, E>, b: Result<T, E>) => Result<T, E>;
|
|
217
|
+
filter: <T, E>(r: Result<T, E>, predicate: (a: T) => boolean, onFalse: E) => Result<T, E>;
|
|
218
|
+
tap: <T, E>(r: Result<T, E>, f: (a: T) => void) => Result<T, E>;
|
|
219
|
+
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
220
|
+
};
|
|
221
|
+
declare global {
|
|
222
|
+
interface Promise<T> {
|
|
223
|
+
toResult<E = unknown>(onError: (e: unknown) => E): Promise<Result<T, E>>;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { type Done, Either, Err, type Fail, type Left, Maybe, type None, type Nothing, type NothingNull, type NothingUndefined, Ok, Option, Pair, Result, type Right, type Some, done, err, fail, fst, getLeft, getRight, isDone, isErr, isFail, isJust, isLeft, isNone, isNothing, isOk, isRight, isSome, just, left, none, nothing, pair, right, snd, some, unwrap, val };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var R=(t,e,o)=>new Promise((P,C)=>{var G=U=>{try{O(o.next(U))}catch(g){C(g)}},H=U=>{try{O(o.throw(U))}catch(g){C(g)}},O=U=>U.done?P(U.value):Promise.resolve(U.value).then(G,H);O((o=o.apply(t,e)).next())});var B=t=>({$:"Left",value:t}),l= exports.right =t=>({$:"Right",value:t}),E= exports.isLeft =t=>t.$==="Left",u= exports.isRight =t=>t.$==="Right",M=(t,e)=>t==null?B(e):l(t),I=(t,e)=>{try{return l(t())}catch(o){return B(e(o))}},K=(t,e)=>R(null,null,function*(){try{let o=yield t;return l(o)}catch(o){return B(e(o))}}),Q=(t,e)=>u(t)?l(e(r(t))):t,V=(t,e)=>E(t)?B(e(h(t))):t,W=(t,e,o)=>E(t)?B(e(h(t))):l(o(r(t))),X=(t,e)=>u(t)?e(r(t)):t,Y=(t,e)=>u(t)?e(r(t)):t,Z=(t,e,o)=>E(t)?e(h(t)):o(r(t)),tt=(t,e)=>u(t)?e.right(r(t)):e.left(h(t)),et=t=>u(t)?B(r(t)):l(h(t)),h= exports.getLeft =t=>t.value,r= exports.getRight =t=>t.value,ot=(t,e)=>u(t)?r(t):e,rt=t=>u(t)?r(t):void 0,nt=t=>{if(u(t))return r(t);throw h(t)},it=(t,e)=>E(t)?t:E(e)?e:l([r(t),r(e)]),st=(t,e)=>E(t)?t:E(e)?e:l(r(t)(r(e))),Tt=(t,e)=>(u(t)&&e(r(t)),t),pt=(t,e)=>(E(t)&&e(h(t)),t),at= exports.Either ={left:B,right:l,new:M,isLeft:E,isRight:u,fromNullable:M,fromThrowable:I,fromPromise:K,map:Q,mapLeft:V,bimap:W,flatMap:X,chain:Y,fold:Z,match:tt,swap:et,getLeft:h,getRight:r,getOrElse:ot,getOrUndefined:rt,getOrThrow:nt,zip:it,apply:st,tap:Tt,tapLeft:pt};Promise.prototype.toEither=function(t){return R(this,null,function*(){try{let e=yield this;return l(e)}catch(e){return B(t(e))}})};var w=t=>t,f= exports.nothing =()=>{},lt=()=>null,v=()=>{},b= exports.isJust =t=>t!=null,p= exports.isNothing =t=>t==null,ut=t=>t===null,ct=t=>t===void 0,N=t=>t,Et=t=>p(t)?null:t,xt=t=>p(t)?void 0:t,At=t=>{try{return t()}catch(e){return f()}},Bt=t=>t.then(e=>e,()=>f());var ht=(t,e)=>p(t)?f():e(t),ft=(t,e)=>p(t)?f():e(t),dt=(t,e)=>b(t)&&e(t)?t:f(),yt=(t,e)=>p(t)?e.nothing():e.some(t),mt=(t,e,o)=>p(t)?e():o(t),Ut=(t,e)=>p(t)?e:t,bt=t=>p(t)?v():t,Pt=t=>{if(p(t))throw new Error("Maybe is nothing");return t},Ot=(t,e)=>b(t)&&b(e)?[t,e]:f(),gt=(t,e)=>b(t)&&b(e)?t(e):f(),Rt=(t,e)=>p(t)?e:t,Ct= exports.Maybe ={just:w,nothing:f,new:N,nothingNull:lt,nothingUndefined:v,isJust:b,isNothing:p,isNothingNull:ut,isNothingUndefined:ct,fromNullable:N,fromThrowable:At,fromPromise:Bt,toNullable:Et,toUndefined:xt,map:ht,flatMap:ft,filter:dt,match:yt,fold:mt,getOrElse:Ut,getOrUndefined:bt,getOrThrow:Pt,zip:Ot,apply:gt,orElse:Rt};var a=()=>({$:"None"}),x= exports.some =t=>({$:"Some",value:t}),i= exports.isSome =t=>t.$==="Some",D= exports.isNone =t=>t.$==="None",L=t=>t==null?a():x(t),Mt=(t,e)=>e(t)?x(t):a(),Nt=t=>{try{return x(t())}catch(e){return a()}},k=t=>t.then(x,()=>a()),wt=(t,e)=>i(t)?x(e(T(t))):a(),vt=(t,e)=>i(t)?e(T(t)):a(),Lt=(t,e)=>i(t)&&e(T(t))?t:a(),Dt=(t,e)=>i(t)?e.some(T(t)):e.none(),T= exports.unwrap =t=>t.value,kt=(t,e)=>i(t)?T(t):e,Ft=t=>i(t)?T(t):void 0,$t=t=>{if(i(t))return T(t);throw new Error("Option is none")},St=(t,e)=>i(t)&&i(e)?x([T(t),T(e)]):a(),zt=(t,e)=>i(t)&&i(e)?x(T(t)(T(e))):a(),jt=(t,e)=>i(t)?t:e,qt= exports.Option ={none:a,some:x,new:L,isSome:i,isNone:D,fromNullable:L,fromPredicate:Mt,fromThrowable:Nt,fromPromise:k,map:wt,flatMap:vt,filter:Lt,match:Dt,unwrap:T,getOrElse:kt,getOrUndefined:Ft,getOrThrow:$t,zip:St,apply:zt,orElse:jt};Array.prototype.firstOption=function(){return this[0]?x(this[0]):a()};Promise.prototype.toOption=function(){return k(this)};var F=t=>t[0],$= exports.snd =t=>t[1],d=(t,e)=>[t,e],Jt= exports.pair =d,_t=([t,e])=>[t,e],Gt=t=>[t.fst,t.snd],Ht=t=>e=>[t,e],It=(t,e)=>d(e(t[0]),t[1]),Kt=(t,e)=>d(t[0],e(t[1])),Qt=(t,e,o)=>d(e(t[0]),o(t[1])),Vt=t=>d(t[1],t[0]),Wt=(t,e)=>d(t[0](e),t[1]),Xt=(t,e)=>d(e[0],t[1](e[1])),Yt=(t,e)=>e(t[0],t[1]),Zt=t=>[t[0],t[1]],te=t=>({fst:t[0],snd:t[1]}),ee=(t,e)=>t[0]===e[0]&&t[1]===e[1],oe=(t,e,o,P)=>o(t[0],e[0])&&P(t[1],e[1]),re=(t,e)=>d([t[0],e[0]],[t[1],e[1]]),ne= exports.Pair ={fst:F,snd:$,new:d,fromArray:_t,fromObject:Gt,curry:Ht,mapFirst:It,mapSecond:Kt,map:Qt,swap:Vt,apply:Wt,apply2:Xt,reduce:Yt,toArray:Zt,toObject:te,eq:ee,equals:oe,zip:re};var c=t=>({v:t}),y= exports.fail =t=>({e:t}),z= exports.Ok =c,j= exports.Err =y,s= exports.isDone =t=>"v"in t,A= exports.isFail =t=>"e"in t,q= exports.isOk =s,J= exports.isErr =A,S=(t,e)=>t==null?y(e):c(t),ie=(t,e)=>{try{return c(t())}catch(o){return y(e(o))}},_=(t,e)=>t.then(c,o=>y(e(o))),se=(t,e)=>s(t)?c(e(n(t))):t,Te=(t,e)=>A(t)?y(e(m(t))):t,pe=(t,e,o)=>s(t)?c(e(n(t))):y(o(m(t))),ae=(t,e)=>s(t)?e(n(t)):t,le=(t,e)=>s(t)?e.done(n(t)):e.fail(m(t)),ue=(t,e,o)=>s(t)?o(n(t)):e(m(t)),ce=(t,e)=>A(t)?c(e(m(t))):t,n= exports.val =t=>t.v,m= exports.err =t=>t.e,Ee=(t,e)=>s(t)?n(t):e,xe=t=>s(t)?n(t):void 0,Ae=t=>{if(s(t))return n(t);throw m(t)},Be=(t,e)=>A(t)?t:A(e)?e:c([n(t),n(e)]),he=(t,e)=>A(t)?t:A(e)?e:c(n(t)(n(e))),fe=(t,e)=>s(t)?t:e,de=(t,e,o)=>s(t)?e(n(t))?t:y(o):t,ye=(t,e)=>(s(t)&&e(n(t)),t),me=(t,e)=>(A(t)&&e(m(t)),t),Ue= exports.Result ={done:c,fail:y,Ok:z,Err:j,val:n,err:m,new:S,isDone:s,isFail:A,isOk:q,isErr:J,fromNullable:S,fromThrowable:ie,fromPromise:_,map:se,mapErr:Te,bimap:pe,flatMap:ae,match:le,fold:ue,recover:ce,getOrElse:Ee,getOrUndefined:xe,getOrThrow:Ae,zip:Be,apply:he,orElse:fe,filter:de,tap:ye,tapErr:me};Promise.prototype.toResult=function(t){return _(this,t)};exports.Either = at; exports.Err = j; exports.Maybe = Ct; exports.Ok = z; exports.Option = qt; exports.Pair = ne; exports.Result = Ue; exports.done = c; exports.err = m; exports.fail = y; exports.fst = F; exports.getLeft = h; exports.getRight = r; exports.isDone = s; exports.isErr = J; exports.isFail = A; exports.isJust = b; exports.isLeft = E; exports.isNone = D; exports.isNothing = p; exports.isOk = q; exports.isRight = u; exports.isSome = i; exports.just = w; exports.left = B; exports.none = a; exports.nothing = f; exports.pair = Jt; exports.right = l; exports.snd = $; exports.some = x; exports.unwrap = T; exports.val = n;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var R=(t,e,o)=>new Promise((P,C)=>{var G=U=>{try{O(o.next(U))}catch(g){C(g)}},H=U=>{try{O(o.throw(U))}catch(g){C(g)}},O=U=>U.done?P(U.value):Promise.resolve(U.value).then(G,H);O((o=o.apply(t,e)).next())});var B=t=>({$:"Left",value:t}),l=t=>({$:"Right",value:t}),E=t=>t.$==="Left",u=t=>t.$==="Right",M=(t,e)=>t==null?B(e):l(t),I=(t,e)=>{try{return l(t())}catch(o){return B(e(o))}},K=(t,e)=>R(null,null,function*(){try{let o=yield t;return l(o)}catch(o){return B(e(o))}}),Q=(t,e)=>u(t)?l(e(r(t))):t,V=(t,e)=>E(t)?B(e(h(t))):t,W=(t,e,o)=>E(t)?B(e(h(t))):l(o(r(t))),X=(t,e)=>u(t)?e(r(t)):t,Y=(t,e)=>u(t)?e(r(t)):t,Z=(t,e,o)=>E(t)?e(h(t)):o(r(t)),tt=(t,e)=>u(t)?e.right(r(t)):e.left(h(t)),et=t=>u(t)?B(r(t)):l(h(t)),h=t=>t.value,r=t=>t.value,ot=(t,e)=>u(t)?r(t):e,rt=t=>u(t)?r(t):void 0,nt=t=>{if(u(t))return r(t);throw h(t)},it=(t,e)=>E(t)?t:E(e)?e:l([r(t),r(e)]),st=(t,e)=>E(t)?t:E(e)?e:l(r(t)(r(e))),Tt=(t,e)=>(u(t)&&e(r(t)),t),pt=(t,e)=>(E(t)&&e(h(t)),t),at={left:B,right:l,new:M,isLeft:E,isRight:u,fromNullable:M,fromThrowable:I,fromPromise:K,map:Q,mapLeft:V,bimap:W,flatMap:X,chain:Y,fold:Z,match:tt,swap:et,getLeft:h,getRight:r,getOrElse:ot,getOrUndefined:rt,getOrThrow:nt,zip:it,apply:st,tap:Tt,tapLeft:pt};Promise.prototype.toEither=function(t){return R(this,null,function*(){try{let e=yield this;return l(e)}catch(e){return B(t(e))}})};var w=t=>t,f=()=>{},lt=()=>null,v=()=>{},b=t=>t!=null,p=t=>t==null,ut=t=>t===null,ct=t=>t===void 0,N=t=>t,Et=t=>p(t)?null:t,xt=t=>p(t)?void 0:t,At=t=>{try{return t()}catch(e){return f()}},Bt=t=>t.then(e=>e,()=>f());var ht=(t,e)=>p(t)?f():e(t),ft=(t,e)=>p(t)?f():e(t),dt=(t,e)=>b(t)&&e(t)?t:f(),yt=(t,e)=>p(t)?e.nothing():e.some(t),mt=(t,e,o)=>p(t)?e():o(t),Ut=(t,e)=>p(t)?e:t,bt=t=>p(t)?v():t,Pt=t=>{if(p(t))throw new Error("Maybe is nothing");return t},Ot=(t,e)=>b(t)&&b(e)?[t,e]:f(),gt=(t,e)=>b(t)&&b(e)?t(e):f(),Rt=(t,e)=>p(t)?e:t,Ct={just:w,nothing:f,new:N,nothingNull:lt,nothingUndefined:v,isJust:b,isNothing:p,isNothingNull:ut,isNothingUndefined:ct,fromNullable:N,fromThrowable:At,fromPromise:Bt,toNullable:Et,toUndefined:xt,map:ht,flatMap:ft,filter:dt,match:yt,fold:mt,getOrElse:Ut,getOrUndefined:bt,getOrThrow:Pt,zip:Ot,apply:gt,orElse:Rt};var a=()=>({$:"None"}),x=t=>({$:"Some",value:t}),i=t=>t.$==="Some",D=t=>t.$==="None",L=t=>t==null?a():x(t),Mt=(t,e)=>e(t)?x(t):a(),Nt=t=>{try{return x(t())}catch(e){return a()}},k=t=>t.then(x,()=>a()),wt=(t,e)=>i(t)?x(e(T(t))):a(),vt=(t,e)=>i(t)?e(T(t)):a(),Lt=(t,e)=>i(t)&&e(T(t))?t:a(),Dt=(t,e)=>i(t)?e.some(T(t)):e.none(),T=t=>t.value,kt=(t,e)=>i(t)?T(t):e,Ft=t=>i(t)?T(t):void 0,$t=t=>{if(i(t))return T(t);throw new Error("Option is none")},St=(t,e)=>i(t)&&i(e)?x([T(t),T(e)]):a(),zt=(t,e)=>i(t)&&i(e)?x(T(t)(T(e))):a(),jt=(t,e)=>i(t)?t:e,qt={none:a,some:x,new:L,isSome:i,isNone:D,fromNullable:L,fromPredicate:Mt,fromThrowable:Nt,fromPromise:k,map:wt,flatMap:vt,filter:Lt,match:Dt,unwrap:T,getOrElse:kt,getOrUndefined:Ft,getOrThrow:$t,zip:St,apply:zt,orElse:jt};Array.prototype.firstOption=function(){return this[0]?x(this[0]):a()};Promise.prototype.toOption=function(){return k(this)};var F=t=>t[0],$=t=>t[1],d=(t,e)=>[t,e],Jt=d,_t=([t,e])=>[t,e],Gt=t=>[t.fst,t.snd],Ht=t=>e=>[t,e],It=(t,e)=>d(e(t[0]),t[1]),Kt=(t,e)=>d(t[0],e(t[1])),Qt=(t,e,o)=>d(e(t[0]),o(t[1])),Vt=t=>d(t[1],t[0]),Wt=(t,e)=>d(t[0](e),t[1]),Xt=(t,e)=>d(e[0],t[1](e[1])),Yt=(t,e)=>e(t[0],t[1]),Zt=t=>[t[0],t[1]],te=t=>({fst:t[0],snd:t[1]}),ee=(t,e)=>t[0]===e[0]&&t[1]===e[1],oe=(t,e,o,P)=>o(t[0],e[0])&&P(t[1],e[1]),re=(t,e)=>d([t[0],e[0]],[t[1],e[1]]),ne={fst:F,snd:$,new:d,fromArray:_t,fromObject:Gt,curry:Ht,mapFirst:It,mapSecond:Kt,map:Qt,swap:Vt,apply:Wt,apply2:Xt,reduce:Yt,toArray:Zt,toObject:te,eq:ee,equals:oe,zip:re};var c=t=>({v:t}),y=t=>({e:t}),z=c,j=y,s=t=>"v"in t,A=t=>"e"in t,q=s,J=A,S=(t,e)=>t==null?y(e):c(t),ie=(t,e)=>{try{return c(t())}catch(o){return y(e(o))}},_=(t,e)=>t.then(c,o=>y(e(o))),se=(t,e)=>s(t)?c(e(n(t))):t,Te=(t,e)=>A(t)?y(e(m(t))):t,pe=(t,e,o)=>s(t)?c(e(n(t))):y(o(m(t))),ae=(t,e)=>s(t)?e(n(t)):t,le=(t,e)=>s(t)?e.done(n(t)):e.fail(m(t)),ue=(t,e,o)=>s(t)?o(n(t)):e(m(t)),ce=(t,e)=>A(t)?c(e(m(t))):t,n=t=>t.v,m=t=>t.e,Ee=(t,e)=>s(t)?n(t):e,xe=t=>s(t)?n(t):void 0,Ae=t=>{if(s(t))return n(t);throw m(t)},Be=(t,e)=>A(t)?t:A(e)?e:c([n(t),n(e)]),he=(t,e)=>A(t)?t:A(e)?e:c(n(t)(n(e))),fe=(t,e)=>s(t)?t:e,de=(t,e,o)=>s(t)?e(n(t))?t:y(o):t,ye=(t,e)=>(s(t)&&e(n(t)),t),me=(t,e)=>(A(t)&&e(m(t)),t),Ue={done:c,fail:y,Ok:z,Err:j,val:n,err:m,new:S,isDone:s,isFail:A,isOk:q,isErr:J,fromNullable:S,fromThrowable:ie,fromPromise:_,map:se,mapErr:Te,bimap:pe,flatMap:ae,match:le,fold:ue,recover:ce,getOrElse:Ee,getOrUndefined:xe,getOrThrow:Ae,zip:Be,apply:he,orElse:fe,filter:de,tap:ye,tapErr:me};Promise.prototype.toResult=function(t){return _(this,t)};export{at as Either,j as Err,Ct as Maybe,z as Ok,qt as Option,ne as Pair,Ue as Result,c as done,m as err,y as fail,F as fst,h as getLeft,r as getRight,s as isDone,J as isErr,A as isFail,b as isJust,E as isLeft,D as isNone,p as isNothing,q as isOk,u as isRight,i as isSome,w as just,B as left,a as none,f as nothing,Jt as pair,l as right,$ as snd,x as some,T as unwrap,n as val};
|