lite-fp 0.4.1 → 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 +91 -55
- package/dist/index.d.ts +91 -55
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +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
|
+
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 lft: <A>(e: Left<A>) => A;
|
|
14
|
+
declare const rgt: <B>(e: Right<B>) => B;
|
|
11
15
|
type Either<A, B> = Left<A> | Right<B>;
|
|
12
16
|
declare const Either: {
|
|
17
|
+
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
13
18
|
left: <A>(value: A) => Left<A>;
|
|
14
19
|
right: <B>(value: B) => Right<B>;
|
|
15
|
-
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
16
20
|
isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
17
21
|
isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
18
22
|
fromNullable: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
@@ -22,6 +26,7 @@ declare const Either: {
|
|
|
22
26
|
mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
23
27
|
bimap: <A, B, C, D>(e: Either<A, B>, fl: (l: A) => C, fr: (r: B) => D) => Either<C, D>;
|
|
24
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>;
|
|
25
30
|
chain: <A, B, C>(e: Either<A, B>, fn: (r: B) => Either<A, C>) => Either<A, C>;
|
|
26
31
|
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
27
32
|
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
@@ -29,9 +34,15 @@ declare const Either: {
|
|
|
29
34
|
left: (value: A) => C;
|
|
30
35
|
}) => C;
|
|
31
36
|
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
37
|
+
lft: <A>(e: Left<A>) => A;
|
|
38
|
+
rgt: <B>(e: Right<B>) => B;
|
|
32
39
|
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
40
|
+
getOrNull: <A, B>(e: Either<A, B>) => B | null;
|
|
41
|
+
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
42
|
+
getOrThrow: <A, B>(e: Either<A, B>) => B;
|
|
33
43
|
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
34
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>;
|
|
35
46
|
tap: <A, B>(e: Either<A, B>, f: (r: B) => void) => Either<A, B>;
|
|
36
47
|
tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
37
48
|
};
|
|
@@ -41,25 +52,26 @@ declare global {
|
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
type Nothing = NothingNull | NothingUndefined;
|
|
47
|
-
declare const just: <T>(value: T) => Maybe<T>;
|
|
55
|
+
type Nothing = null | undefined;
|
|
56
|
+
declare const just: <T>(value: T) => T;
|
|
48
57
|
declare const nothing: () => Nothing;
|
|
58
|
+
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
59
|
+
declare const isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
49
60
|
type Maybe<T> = T | Nothing;
|
|
50
61
|
declare const Maybe: {
|
|
51
|
-
|
|
62
|
+
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
63
|
+
just: <T>(value: T) => T;
|
|
52
64
|
nothing: () => Nothing;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
isSome: <T>(m: Maybe<T>) => m is T;
|
|
65
|
+
nothingNull: () => null;
|
|
66
|
+
nothingUndefined: () => undefined;
|
|
67
|
+
isJust: <T>(m: Maybe<T>) => m is T;
|
|
57
68
|
isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
fromNullable: <T>(
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
isNull: <T>(m: Maybe<T>) => m is null;
|
|
70
|
+
isUndefined: <T>(m: Maybe<T>) => m is undefined;
|
|
71
|
+
fromNullable: <T>(m: T | null | undefined) => Maybe<T>;
|
|
72
|
+
fromThrowable: <T>(fn: () => T) => Maybe<T>;
|
|
73
|
+
fromPredicate: <T>(value: T, predicate: (value: T) => boolean) => Maybe<T>;
|
|
74
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Maybe<T>>;
|
|
63
75
|
map: <T, U>(m: Maybe<T>, fn: (v: T) => U) => Maybe<U>;
|
|
64
76
|
flatMap: <T, U>(m: Maybe<T>, fn: (v: T) => Maybe<U>) => Maybe<U>;
|
|
65
77
|
filter: <T>(m: Maybe<T>, predicate: (value: T) => boolean) => Maybe<T>;
|
|
@@ -67,30 +79,34 @@ declare const Maybe: {
|
|
|
67
79
|
some: (v: T) => U;
|
|
68
80
|
nothing: () => U;
|
|
69
81
|
}) => U;
|
|
70
|
-
|
|
82
|
+
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
83
|
+
getOrElse: <T>(m: Maybe<T>, defaultValue: T) => T;
|
|
71
84
|
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
fromPromise: <T>(promise: Promise<T>) => Promise<Maybe<T>>;
|
|
85
|
+
getOrNull: <T>(m: Maybe<T>) => T | null;
|
|
86
|
+
getOrThrow: <T>(m: Maybe<T>) => T;
|
|
75
87
|
zip: <T, U>(a: Maybe<T>, b: Maybe<U>) => Maybe<[T, U]>;
|
|
76
88
|
apply: <T, U>(fn: Maybe<(value: T) => U>, opt: Maybe<T>) => Maybe<U>;
|
|
77
89
|
orElse: <T>(opt: Maybe<T>, other: Maybe<T>) => Maybe<T>;
|
|
90
|
+
tap: <T>(m: Maybe<T>, fn: (v: T) => void) => Maybe<T>;
|
|
78
91
|
};
|
|
79
92
|
|
|
80
|
-
|
|
93
|
+
interface None {
|
|
81
94
|
readonly $: "None";
|
|
82
|
-
}
|
|
83
|
-
|
|
95
|
+
}
|
|
96
|
+
interface Some<T> {
|
|
84
97
|
readonly $: "Some";
|
|
85
98
|
readonly value: T;
|
|
86
|
-
}
|
|
99
|
+
}
|
|
87
100
|
declare const none: <T>() => Option<T>;
|
|
88
101
|
declare const some: <T>(value: T) => Option<T>;
|
|
102
|
+
declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
103
|
+
declare const isNone: <T>(option: Option<T>) => option is None;
|
|
104
|
+
declare const unwrap: <T>(option: Some<T>) => T;
|
|
89
105
|
type Option<T> = None | Some<T>;
|
|
90
106
|
declare const Option: {
|
|
107
|
+
new: <T>(value: T | null | undefined) => Option<T>;
|
|
91
108
|
none: <T>() => Option<T>;
|
|
92
109
|
some: <T>(value: T) => Option<T>;
|
|
93
|
-
new: <T>(value: T | null | undefined) => Option<T>;
|
|
94
110
|
isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
95
111
|
isNone: <T>(option: Option<T>) => option is None;
|
|
96
112
|
fromNullable: <T>(value: T | null | undefined) => Option<T>;
|
|
@@ -100,16 +116,20 @@ declare const Option: {
|
|
|
100
116
|
map: <T, U>(option: Option<T>, fn: (value: T) => U) => Option<U>;
|
|
101
117
|
flatMap: <T, U>(option: Option<T>, fn: (value: T) => Option<U>) => Option<U>;
|
|
102
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;
|
|
103
120
|
match: <T, U>(option: Option<T>, matcher: {
|
|
104
121
|
some: (value: T) => U;
|
|
105
122
|
none: () => U;
|
|
106
123
|
}) => U;
|
|
124
|
+
unwrap: <T>(option: Some<T>) => T;
|
|
107
125
|
getOrElse: <T>(option: Option<T>, defaultValue: T) => T;
|
|
108
126
|
getOrUndefined: <T>(option: Option<T>) => T | undefined;
|
|
109
|
-
|
|
127
|
+
getOrNull: <T>(option: Option<T>) => T | null;
|
|
128
|
+
getOrThrow: <T>(option: Option<T>) => T;
|
|
110
129
|
zip: <T, U>(a: Option<T>, b: Option<U>) => Option<[T, U]>;
|
|
111
130
|
apply: <T, U>(fn: Option<(value: T) => U>, opt: Option<T>) => Option<U>;
|
|
112
131
|
orElse: <T>(opt: Option<T>, other: Option<T>) => Option<T>;
|
|
132
|
+
tap: <T>(option: Option<T>, f: (value: T) => void) => Option<T>;
|
|
113
133
|
};
|
|
114
134
|
declare global {
|
|
115
135
|
interface Array<T> {
|
|
@@ -120,50 +140,61 @@ declare global {
|
|
|
120
140
|
}
|
|
121
141
|
}
|
|
122
142
|
|
|
143
|
+
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
144
|
+
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
145
|
+
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
123
146
|
type Pair<A, B> = readonly [A, B];
|
|
124
147
|
declare const Pair: {
|
|
125
|
-
fst: <A, B>(p: Pair<A, B>) => A;
|
|
126
|
-
snd: <A, B>(p: Pair<A, B>) => B;
|
|
127
148
|
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
149
|
+
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
128
150
|
fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
129
151
|
fromObject: <A, B>(obj: {
|
|
130
152
|
fst: A;
|
|
131
153
|
snd: B;
|
|
132
154
|
}) => Pair<A, B>;
|
|
133
|
-
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
134
|
-
mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
135
|
-
mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
136
|
-
map: <A, B, C, D>(p: Pair<A, B>, fnA: (a: A) => C, fnB: (b: B) => D) => Pair<C, D>;
|
|
137
|
-
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
138
|
-
apply: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
139
|
-
apply2: <A, B, C>(fnPair: Pair<(a: A) => B, (b: B) => C>, vPair: Pair<A, B>) => Pair<A, C>;
|
|
140
|
-
reduce: <A, B, C>(p: Pair<A, B>, fn: (a: A, b: B) => C) => C;
|
|
141
155
|
toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
142
156
|
toObject: <A, B>(p: Pair<A, B>) => {
|
|
143
157
|
fst: A;
|
|
144
158
|
snd: B;
|
|
145
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;
|
|
146
168
|
eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
147
|
-
|
|
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>;
|
|
148
174
|
zip: <A, B, C, D>(p1: Pair<A, B>, p2: Pair<C, D>) => Pair<Pair<A, C>, Pair<B, D>>;
|
|
149
175
|
};
|
|
150
|
-
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
151
176
|
|
|
152
|
-
|
|
177
|
+
interface Done<T> {
|
|
153
178
|
readonly v: T;
|
|
154
|
-
}
|
|
155
|
-
|
|
179
|
+
}
|
|
180
|
+
interface Fail<E> {
|
|
156
181
|
readonly e: E;
|
|
157
|
-
}
|
|
158
|
-
declare const done: <T>(
|
|
159
|
-
declare const fail: <E>(
|
|
182
|
+
}
|
|
183
|
+
declare const done: <T>(v: T) => Done<T>;
|
|
184
|
+
declare const fail: <E>(e: E) => Fail<E>;
|
|
185
|
+
declare const Ok: <T>(v: T) => Done<T>;
|
|
186
|
+
declare const Err: <E>(e: E) => Fail<E>;
|
|
187
|
+
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
188
|
+
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
189
|
+
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
190
|
+
declare const isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
191
|
+
declare const val: <T>(r: Done<T>) => T;
|
|
192
|
+
declare const err: <E>(r: Fail<E>) => E;
|
|
160
193
|
type Result<T, E> = Done<T> | Fail<E>;
|
|
161
194
|
declare const Result: {
|
|
162
|
-
done: <T>(value: T) => Done<T>;
|
|
163
|
-
fail: <E>(error: E) => Fail<E>;
|
|
164
|
-
OK: <T>(value: T) => Done<T>;
|
|
165
|
-
Err: <E>(error: E) => Fail<E>;
|
|
166
195
|
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
196
|
+
done: <T>(v: T) => Done<T>;
|
|
197
|
+
fail: <E>(e: E) => Fail<E>;
|
|
167
198
|
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
168
199
|
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
169
200
|
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
@@ -175,18 +206,23 @@ declare const Result: {
|
|
|
175
206
|
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
176
207
|
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
177
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>;
|
|
178
210
|
match: <T, E, U>(r: Result<T, E>, matcher: {
|
|
179
211
|
done: (a: T) => U;
|
|
180
212
|
fail: (b: E) => U;
|
|
181
213
|
}) => U;
|
|
182
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>;
|
|
183
216
|
recover: <T, E>(r: Result<T, E>, fn: (error: E) => T) => Result<T, E>;
|
|
184
|
-
|
|
185
|
-
|
|
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;
|
|
220
|
+
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
221
|
+
getOrNull: <T, E>(r: Result<T, E>) => T | null;
|
|
222
|
+
getOrThrow: <T, E>(r: Result<T, E>) => T;
|
|
186
223
|
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
187
224
|
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
188
225
|
orElse: <T, E>(a: Result<T, E>, b: Result<T, E>) => Result<T, E>;
|
|
189
|
-
filter: <T, E>(r: Result<T, E>, predicate: (a: T) => boolean, onFalse: E) => Result<T, E>;
|
|
190
226
|
tap: <T, E>(r: Result<T, E>, f: (a: T) => void) => Result<T, E>;
|
|
191
227
|
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
192
228
|
};
|
|
@@ -196,4 +232,4 @@ declare global {
|
|
|
196
232
|
}
|
|
197
233
|
}
|
|
198
234
|
|
|
199
|
-
export { type Done, Either, 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,18 +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
|
+
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 lft: <A>(e: Left<A>) => A;
|
|
14
|
+
declare const rgt: <B>(e: Right<B>) => B;
|
|
11
15
|
type Either<A, B> = Left<A> | Right<B>;
|
|
12
16
|
declare const Either: {
|
|
17
|
+
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
13
18
|
left: <A>(value: A) => Left<A>;
|
|
14
19
|
right: <B>(value: B) => Right<B>;
|
|
15
|
-
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
16
20
|
isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
17
21
|
isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
18
22
|
fromNullable: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
@@ -22,6 +26,7 @@ declare const Either: {
|
|
|
22
26
|
mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
23
27
|
bimap: <A, B, C, D>(e: Either<A, B>, fl: (l: A) => C, fr: (r: B) => D) => Either<C, D>;
|
|
24
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>;
|
|
25
30
|
chain: <A, B, C>(e: Either<A, B>, fn: (r: B) => Either<A, C>) => Either<A, C>;
|
|
26
31
|
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
27
32
|
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
@@ -29,9 +34,15 @@ declare const Either: {
|
|
|
29
34
|
left: (value: A) => C;
|
|
30
35
|
}) => C;
|
|
31
36
|
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
37
|
+
lft: <A>(e: Left<A>) => A;
|
|
38
|
+
rgt: <B>(e: Right<B>) => B;
|
|
32
39
|
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
40
|
+
getOrNull: <A, B>(e: Either<A, B>) => B | null;
|
|
41
|
+
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
42
|
+
getOrThrow: <A, B>(e: Either<A, B>) => B;
|
|
33
43
|
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
34
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>;
|
|
35
46
|
tap: <A, B>(e: Either<A, B>, f: (r: B) => void) => Either<A, B>;
|
|
36
47
|
tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
37
48
|
};
|
|
@@ -41,25 +52,26 @@ declare global {
|
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
type Nothing = NothingNull | NothingUndefined;
|
|
47
|
-
declare const just: <T>(value: T) => Maybe<T>;
|
|
55
|
+
type Nothing = null | undefined;
|
|
56
|
+
declare const just: <T>(value: T) => T;
|
|
48
57
|
declare const nothing: () => Nothing;
|
|
58
|
+
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
59
|
+
declare const isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
49
60
|
type Maybe<T> = T | Nothing;
|
|
50
61
|
declare const Maybe: {
|
|
51
|
-
|
|
62
|
+
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
63
|
+
just: <T>(value: T) => T;
|
|
52
64
|
nothing: () => Nothing;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
isSome: <T>(m: Maybe<T>) => m is T;
|
|
65
|
+
nothingNull: () => null;
|
|
66
|
+
nothingUndefined: () => undefined;
|
|
67
|
+
isJust: <T>(m: Maybe<T>) => m is T;
|
|
57
68
|
isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
fromNullable: <T>(
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
isNull: <T>(m: Maybe<T>) => m is null;
|
|
70
|
+
isUndefined: <T>(m: Maybe<T>) => m is undefined;
|
|
71
|
+
fromNullable: <T>(m: T | null | undefined) => Maybe<T>;
|
|
72
|
+
fromThrowable: <T>(fn: () => T) => Maybe<T>;
|
|
73
|
+
fromPredicate: <T>(value: T, predicate: (value: T) => boolean) => Maybe<T>;
|
|
74
|
+
fromPromise: <T>(promise: Promise<T>) => Promise<Maybe<T>>;
|
|
63
75
|
map: <T, U>(m: Maybe<T>, fn: (v: T) => U) => Maybe<U>;
|
|
64
76
|
flatMap: <T, U>(m: Maybe<T>, fn: (v: T) => Maybe<U>) => Maybe<U>;
|
|
65
77
|
filter: <T>(m: Maybe<T>, predicate: (value: T) => boolean) => Maybe<T>;
|
|
@@ -67,30 +79,34 @@ declare const Maybe: {
|
|
|
67
79
|
some: (v: T) => U;
|
|
68
80
|
nothing: () => U;
|
|
69
81
|
}) => U;
|
|
70
|
-
|
|
82
|
+
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
83
|
+
getOrElse: <T>(m: Maybe<T>, defaultValue: T) => T;
|
|
71
84
|
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
fromPromise: <T>(promise: Promise<T>) => Promise<Maybe<T>>;
|
|
85
|
+
getOrNull: <T>(m: Maybe<T>) => T | null;
|
|
86
|
+
getOrThrow: <T>(m: Maybe<T>) => T;
|
|
75
87
|
zip: <T, U>(a: Maybe<T>, b: Maybe<U>) => Maybe<[T, U]>;
|
|
76
88
|
apply: <T, U>(fn: Maybe<(value: T) => U>, opt: Maybe<T>) => Maybe<U>;
|
|
77
89
|
orElse: <T>(opt: Maybe<T>, other: Maybe<T>) => Maybe<T>;
|
|
90
|
+
tap: <T>(m: Maybe<T>, fn: (v: T) => void) => Maybe<T>;
|
|
78
91
|
};
|
|
79
92
|
|
|
80
|
-
|
|
93
|
+
interface None {
|
|
81
94
|
readonly $: "None";
|
|
82
|
-
}
|
|
83
|
-
|
|
95
|
+
}
|
|
96
|
+
interface Some<T> {
|
|
84
97
|
readonly $: "Some";
|
|
85
98
|
readonly value: T;
|
|
86
|
-
}
|
|
99
|
+
}
|
|
87
100
|
declare const none: <T>() => Option<T>;
|
|
88
101
|
declare const some: <T>(value: T) => Option<T>;
|
|
102
|
+
declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
103
|
+
declare const isNone: <T>(option: Option<T>) => option is None;
|
|
104
|
+
declare const unwrap: <T>(option: Some<T>) => T;
|
|
89
105
|
type Option<T> = None | Some<T>;
|
|
90
106
|
declare const Option: {
|
|
107
|
+
new: <T>(value: T | null | undefined) => Option<T>;
|
|
91
108
|
none: <T>() => Option<T>;
|
|
92
109
|
some: <T>(value: T) => Option<T>;
|
|
93
|
-
new: <T>(value: T | null | undefined) => Option<T>;
|
|
94
110
|
isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
95
111
|
isNone: <T>(option: Option<T>) => option is None;
|
|
96
112
|
fromNullable: <T>(value: T | null | undefined) => Option<T>;
|
|
@@ -100,16 +116,20 @@ declare const Option: {
|
|
|
100
116
|
map: <T, U>(option: Option<T>, fn: (value: T) => U) => Option<U>;
|
|
101
117
|
flatMap: <T, U>(option: Option<T>, fn: (value: T) => Option<U>) => Option<U>;
|
|
102
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;
|
|
103
120
|
match: <T, U>(option: Option<T>, matcher: {
|
|
104
121
|
some: (value: T) => U;
|
|
105
122
|
none: () => U;
|
|
106
123
|
}) => U;
|
|
124
|
+
unwrap: <T>(option: Some<T>) => T;
|
|
107
125
|
getOrElse: <T>(option: Option<T>, defaultValue: T) => T;
|
|
108
126
|
getOrUndefined: <T>(option: Option<T>) => T | undefined;
|
|
109
|
-
|
|
127
|
+
getOrNull: <T>(option: Option<T>) => T | null;
|
|
128
|
+
getOrThrow: <T>(option: Option<T>) => T;
|
|
110
129
|
zip: <T, U>(a: Option<T>, b: Option<U>) => Option<[T, U]>;
|
|
111
130
|
apply: <T, U>(fn: Option<(value: T) => U>, opt: Option<T>) => Option<U>;
|
|
112
131
|
orElse: <T>(opt: Option<T>, other: Option<T>) => Option<T>;
|
|
132
|
+
tap: <T>(option: Option<T>, f: (value: T) => void) => Option<T>;
|
|
113
133
|
};
|
|
114
134
|
declare global {
|
|
115
135
|
interface Array<T> {
|
|
@@ -120,50 +140,61 @@ declare global {
|
|
|
120
140
|
}
|
|
121
141
|
}
|
|
122
142
|
|
|
143
|
+
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
144
|
+
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
145
|
+
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
123
146
|
type Pair<A, B> = readonly [A, B];
|
|
124
147
|
declare const Pair: {
|
|
125
|
-
fst: <A, B>(p: Pair<A, B>) => A;
|
|
126
|
-
snd: <A, B>(p: Pair<A, B>) => B;
|
|
127
148
|
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
149
|
+
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
128
150
|
fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
129
151
|
fromObject: <A, B>(obj: {
|
|
130
152
|
fst: A;
|
|
131
153
|
snd: B;
|
|
132
154
|
}) => Pair<A, B>;
|
|
133
|
-
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
134
|
-
mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
135
|
-
mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
136
|
-
map: <A, B, C, D>(p: Pair<A, B>, fnA: (a: A) => C, fnB: (b: B) => D) => Pair<C, D>;
|
|
137
|
-
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
138
|
-
apply: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
139
|
-
apply2: <A, B, C>(fnPair: Pair<(a: A) => B, (b: B) => C>, vPair: Pair<A, B>) => Pair<A, C>;
|
|
140
|
-
reduce: <A, B, C>(p: Pair<A, B>, fn: (a: A, b: B) => C) => C;
|
|
141
155
|
toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
142
156
|
toObject: <A, B>(p: Pair<A, B>) => {
|
|
143
157
|
fst: A;
|
|
144
158
|
snd: B;
|
|
145
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;
|
|
146
168
|
eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
147
|
-
|
|
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>;
|
|
148
174
|
zip: <A, B, C, D>(p1: Pair<A, B>, p2: Pair<C, D>) => Pair<Pair<A, C>, Pair<B, D>>;
|
|
149
175
|
};
|
|
150
|
-
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
151
176
|
|
|
152
|
-
|
|
177
|
+
interface Done<T> {
|
|
153
178
|
readonly v: T;
|
|
154
|
-
}
|
|
155
|
-
|
|
179
|
+
}
|
|
180
|
+
interface Fail<E> {
|
|
156
181
|
readonly e: E;
|
|
157
|
-
}
|
|
158
|
-
declare const done: <T>(
|
|
159
|
-
declare const fail: <E>(
|
|
182
|
+
}
|
|
183
|
+
declare const done: <T>(v: T) => Done<T>;
|
|
184
|
+
declare const fail: <E>(e: E) => Fail<E>;
|
|
185
|
+
declare const Ok: <T>(v: T) => Done<T>;
|
|
186
|
+
declare const Err: <E>(e: E) => Fail<E>;
|
|
187
|
+
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
188
|
+
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
189
|
+
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
190
|
+
declare const isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
191
|
+
declare const val: <T>(r: Done<T>) => T;
|
|
192
|
+
declare const err: <E>(r: Fail<E>) => E;
|
|
160
193
|
type Result<T, E> = Done<T> | Fail<E>;
|
|
161
194
|
declare const Result: {
|
|
162
|
-
done: <T>(value: T) => Done<T>;
|
|
163
|
-
fail: <E>(error: E) => Fail<E>;
|
|
164
|
-
OK: <T>(value: T) => Done<T>;
|
|
165
|
-
Err: <E>(error: E) => Fail<E>;
|
|
166
195
|
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
196
|
+
done: <T>(v: T) => Done<T>;
|
|
197
|
+
fail: <E>(e: E) => Fail<E>;
|
|
167
198
|
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
168
199
|
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
169
200
|
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
@@ -175,18 +206,23 @@ declare const Result: {
|
|
|
175
206
|
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
176
207
|
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
177
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>;
|
|
178
210
|
match: <T, E, U>(r: Result<T, E>, matcher: {
|
|
179
211
|
done: (a: T) => U;
|
|
180
212
|
fail: (b: E) => U;
|
|
181
213
|
}) => U;
|
|
182
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>;
|
|
183
216
|
recover: <T, E>(r: Result<T, E>, fn: (error: E) => T) => Result<T, E>;
|
|
184
|
-
|
|
185
|
-
|
|
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;
|
|
220
|
+
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
221
|
+
getOrNull: <T, E>(r: Result<T, E>) => T | null;
|
|
222
|
+
getOrThrow: <T, E>(r: Result<T, E>) => T;
|
|
186
223
|
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
187
224
|
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
188
225
|
orElse: <T, E>(a: Result<T, E>, b: Result<T, E>) => Result<T, E>;
|
|
189
|
-
filter: <T, E>(r: Result<T, E>, predicate: (a: T) => boolean, onFalse: E) => Result<T, E>;
|
|
190
226
|
tap: <T, E>(r: Result<T, E>, f: (a: T) => void) => Result<T, E>;
|
|
191
227
|
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
192
228
|
};
|
|
@@ -196,4 +232,4 @@ declare global {
|
|
|
196
232
|
}
|
|
197
233
|
}
|
|
198
234
|
|
|
199
|
-
export { type Done, Either, 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};
|