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