lite-fp 0.6.0 → 0.7.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/README.md +65 -6
- package/dist/index.d.mts +59 -13
- package/dist/index.d.ts +59 -13
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,7 +121,57 @@ const r2 = await Result.fromPromise(
|
|
|
121
121
|
const safe = Result.recover(r2, () => "default"); // Done("default")
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
### Callback-based conversions
|
|
125
|
+
|
|
126
|
+
For callback-driven code — `fromPromiseCallback` fires **once** and is gone (like `setTimeout`,
|
|
127
|
+
not `setInterval` or `EventEmitter.on`). After the Promise settles, the callback executes and
|
|
128
|
+
becomes eligible for garbage collection — no cleanup, no leak.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { Either, fromPromiseCallback, flatMapCallback, match } from "lite-fp";
|
|
132
|
+
|
|
133
|
+
// Promise → Either delivered via callback (fires exactly once)
|
|
134
|
+
fromPromiseCallback(
|
|
135
|
+
fetch("/api/user").then(r => r.json()),
|
|
136
|
+
e => new Error(String(e)),
|
|
137
|
+
result => {
|
|
138
|
+
// result is Either<Error, User> — callback is done after this tick
|
|
139
|
+
flatMapCallback(result, user => fetchPosts(user.id), postsResult => {
|
|
140
|
+
match(postsResult, {
|
|
141
|
+
right: posts => render(posts),
|
|
142
|
+
left: err => showError(err),
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Contrast with persistent subscriptions (`setInterval`, `emitter.on`, `addEventListener`,
|
|
150
|
+
`subscribe`) where the callback stays registered until explicitly removed.
|
|
151
|
+
|
|
152
|
+
### Collection operations
|
|
153
|
+
|
|
154
|
+
`all`/`collect`, `flatten`, and `partition` work on arrays of `Result` or `Either`:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { Result, Either } from "lite-fp";
|
|
158
|
+
|
|
159
|
+
// all — fail-fast: returns the first Fail/Left, or Done/Right with all values
|
|
160
|
+
const ok = Result.all([Result.done(1), Result.done(2)]); // Done([1, 2])
|
|
161
|
+
const err = Result.all([Result.done(1), Result.fail("nope")]); // Fail("nope")
|
|
162
|
+
|
|
163
|
+
// partition — split into done/fail (or right/left) arrays
|
|
164
|
+
const { done, fail } = Result.partition([
|
|
165
|
+
Result.done(1), Result.fail("a"), Result.done(2), Result.fail("b"),
|
|
166
|
+
]); // done = [1, 2], fail = ["a", "b"]
|
|
167
|
+
|
|
168
|
+
// flatten — unwrap nested Result/Either
|
|
169
|
+
const nested = Result.done(Result.done(42));
|
|
170
|
+
Result.flatten(nested); // Done(42)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Also available: `Either.all`, `Either.collect`, `Either.flatten`, `Either.partition`.
|
|
174
|
+
|
|
125
175
|
### Pair
|
|
126
176
|
|
|
127
177
|
```ts
|
|
@@ -145,14 +195,23 @@ const p2 = Pair.map(
|
|
|
145
195
|
- Combine: `zip`, `apply`, `orElse`
|
|
146
196
|
|
|
147
197
|
- Either
|
|
148
|
-
- Constructors: `left`, `right`, `new`, `fromNullable`, `fromThrowable`, `fromPromise`
|
|
198
|
+
- Constructors: `left`, `right`, `new`, `fromNullable`, `fromThrowable`, `fromPromise`, `fromPromiseSettled`, `fromPromiseCallback`
|
|
149
199
|
- Type guards: `isLeft`, `isRight`
|
|
150
|
-
- Ops: `map`, `mapLeft`, `bimap`, `flatMap`, `chain`, `fold`, `match`, `swap`, `
|
|
200
|
+
- Ops: `map`, `mapLeft`, `bimap`, `flatMap`, `chain`, `fold`, `match`, `swap`, `recover`, `getOrElse`, `getOrNull`, `getOrUndefined`, `getOrThrow`
|
|
201
|
+
- Combine: `zip`, `apply`, `orElse`, `tap`, `tapLeft`
|
|
202
|
+
- Collection: `all`, `collect`, `flatten`, `partition`
|
|
203
|
+
- Callback: `flatMapCallback`
|
|
204
|
+
- Conversions: `toPromise`
|
|
151
205
|
|
|
152
206
|
- Result
|
|
153
|
-
- Constructors: `done`, `fail`, `new`, `fromNullable`, `fromThrowable`, `fromPromise`
|
|
154
|
-
- Type guards: `isDone`, `isFail`
|
|
155
|
-
- Ops: `map`, `
|
|
207
|
+
- Constructors: `done`, `fail`, `Ok`, `Err`, `new`, `fromNullable`, `fromThrowable`, `fromPromise`, `fromPromiseSettled`, `fromPromiseCallback`
|
|
208
|
+
- Type guards: `isDone`, `isFail`, `isOk`, `isErr`
|
|
209
|
+
- Ops: `map`, `mapFail`, `mapErr`, `bimap`, `flatMap`, `chain`, `fold`, `match`, `filter`, `recover`, `swap`
|
|
210
|
+
- Extract: `val`, `err`, `getOrElse`, `getOrUndefined`, `getOrNull`, `getOrThrow`
|
|
211
|
+
- Combine: `zip`, `apply`, `orElse`, `tap`, `tapFail`, `tapErr`
|
|
212
|
+
- Collection: `all`, `collect`, `flatten`, `partition`
|
|
213
|
+
- Callback: `flatMapCallback`
|
|
214
|
+
- Conversions: `toPromise`
|
|
156
215
|
|
|
157
216
|
- Maybe (T | null | undefined)
|
|
158
217
|
- Constructors: `new`, `just`, `nothing`/`nothingNull`/`nothingUndefined`, `fromNullable`, `fromPredicate`, `fromThrowable`, `fromPromise`
|
package/dist/index.d.mts
CHANGED
|
@@ -10,8 +10,10 @@ 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 mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
13
14
|
declare const lft: <A>(e: Left<A>) => A;
|
|
14
15
|
declare const rgt: <B>(e: Right<B>) => B;
|
|
16
|
+
declare const tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
15
17
|
type Either<A, B> = Left<A> | Right<B>;
|
|
16
18
|
declare const Either: {
|
|
17
19
|
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
@@ -22,24 +24,34 @@ declare const Either: {
|
|
|
22
24
|
fromNullable: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
23
25
|
fromThrowable: <A, B>(fn: () => B, onError: (e: unknown) => A) => Either<A, B>;
|
|
24
26
|
fromPromise: <A, B>(promise: Promise<B>, onError: (e: unknown) => A) => Promise<Either<A, B>>;
|
|
27
|
+
fromPromiseCallback: <A, B>(promise: Promise<B>, onError: (e: unknown) => A, callback: (result: Either<A, B>) => void) => void;
|
|
28
|
+
toPromise: <A, B>(e: Either<A, B>) => Promise<B>;
|
|
25
29
|
map: <A, B, C>(e: Either<A, B>, fn: (r: B) => C) => Either<A, C>;
|
|
26
30
|
mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
27
31
|
bimap: <A, B, C, D>(e: Either<A, B>, fl: (l: A) => C, fr: (r: B) => D) => Either<C, D>;
|
|
28
32
|
flatMap: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
29
33
|
filter: <A, B>(e: Either<A, B>, predicate: (value: B) => boolean, onFalse: A) => Either<A, B>;
|
|
30
|
-
chain: <A, B, C>(e: Either<A, B>, fn: (
|
|
34
|
+
chain: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
31
35
|
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
32
36
|
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
33
37
|
right: (value: B) => C;
|
|
34
38
|
left: (value: A) => C;
|
|
35
39
|
}) => C;
|
|
36
40
|
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
41
|
+
flatMapCallback: <A, B, C>(e: Either<A, B>, fn: (value: B) => Promise<Either<A, C>>, callback: (result: Either<A, C>) => void) => void;
|
|
37
42
|
lft: <A>(e: Left<A>) => A;
|
|
38
43
|
rgt: <B>(e: Right<B>) => B;
|
|
39
44
|
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
40
45
|
getOrNull: <A, B>(e: Either<A, B>) => B | null;
|
|
41
46
|
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
42
47
|
getOrThrow: <A, B>(e: Either<A, B>) => B;
|
|
48
|
+
all: <A, B>(eithers: Either<A, B>[]) => Either<A, B[]>;
|
|
49
|
+
collect: <A, B>(eithers: Either<A, B>[]) => Either<A, B[]>;
|
|
50
|
+
flatten: <A, B>(e: Either<A, Either<A, B>>) => Either<A, B>;
|
|
51
|
+
partition: <A, B>(eithers: Either<A, B>[]) => {
|
|
52
|
+
right: B[];
|
|
53
|
+
left: A[];
|
|
54
|
+
};
|
|
43
55
|
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
44
56
|
apply: <E, A, B>(fn: Either<E, (value: A) => B>, arg: Either<E, A>) => Either<E, B>;
|
|
45
57
|
orElse: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, A | B>;
|
|
@@ -53,14 +65,18 @@ declare global {
|
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
type Nothing = null | undefined;
|
|
56
|
-
declare const just: <T>(value: T) => T
|
|
68
|
+
declare const just: <T>(value: T) => NonNullable<T>;
|
|
57
69
|
declare const nothing: () => Nothing;
|
|
70
|
+
declare const nothingNull: () => null;
|
|
71
|
+
declare const nothingUndefined: () => undefined;
|
|
58
72
|
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
59
73
|
declare const isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
74
|
+
declare const isNull: <T>(m: Maybe<T>) => m is null;
|
|
75
|
+
declare const isUndefined: <T>(m: Maybe<T>) => m is undefined;
|
|
60
76
|
type Maybe<T> = T | Nothing;
|
|
61
77
|
declare const Maybe: {
|
|
62
78
|
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
63
|
-
just: <T>(value: T) => T
|
|
79
|
+
just: <T>(value: T) => NonNullable<T>;
|
|
64
80
|
nothing: () => Nothing;
|
|
65
81
|
nothingNull: () => null;
|
|
66
82
|
nothingUndefined: () => undefined;
|
|
@@ -75,11 +91,11 @@ declare const Maybe: {
|
|
|
75
91
|
map: <T, U>(m: Maybe<T>, fn: (v: T) => U) => Maybe<U>;
|
|
76
92
|
flatMap: <T, U>(m: Maybe<T>, fn: (v: T) => Maybe<U>) => Maybe<U>;
|
|
77
93
|
filter: <T>(m: Maybe<T>, predicate: (value: T) => boolean) => Maybe<T>;
|
|
94
|
+
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
78
95
|
match: <T, U>(m: Maybe<T>, matcher: {
|
|
79
96
|
some: (v: T) => U;
|
|
80
97
|
nothing: () => U;
|
|
81
98
|
}) => U;
|
|
82
|
-
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
83
99
|
getOrElse: <T>(m: Maybe<T>, defaultValue: T) => T;
|
|
84
100
|
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
85
101
|
getOrNull: <T>(m: Maybe<T>) => T | null;
|
|
@@ -141,8 +157,24 @@ declare global {
|
|
|
141
157
|
}
|
|
142
158
|
|
|
143
159
|
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
160
|
+
declare const curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
161
|
+
declare const fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
162
|
+
declare const fromObject: <A, B>(obj: {
|
|
163
|
+
fst: A;
|
|
164
|
+
snd: B;
|
|
165
|
+
}) => Pair<A, B>;
|
|
166
|
+
declare const toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
167
|
+
declare const toObject: <A, B>(p: Pair<A, B>) => {
|
|
168
|
+
fst: A;
|
|
169
|
+
snd: B;
|
|
170
|
+
};
|
|
171
|
+
declare const mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
172
|
+
declare const mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
173
|
+
declare const eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
174
|
+
declare const eql: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>, eqA: (a1: A, a2: A) => boolean, eqB: (b1: B, b2: B) => boolean) => boolean;
|
|
144
175
|
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
145
176
|
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
177
|
+
declare const app: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
146
178
|
type Pair<A, B> = readonly [A, B];
|
|
147
179
|
declare const Pair: {
|
|
148
180
|
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
@@ -180,21 +212,23 @@ interface Done<T> {
|
|
|
180
212
|
interface Fail<E> {
|
|
181
213
|
readonly e: E;
|
|
182
214
|
}
|
|
183
|
-
declare const done: <T>(
|
|
184
|
-
declare const fail: <E>(
|
|
185
|
-
declare const Ok: <T>(
|
|
186
|
-
declare const Err: <E>(
|
|
215
|
+
declare const done: <T>(value: T) => Done<T>;
|
|
216
|
+
declare const fail: <E>(value: E) => Fail<E>;
|
|
217
|
+
declare const Ok: <T>(value: T) => Done<T>;
|
|
218
|
+
declare const Err: <E>(value: E) => Fail<E>;
|
|
187
219
|
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
188
220
|
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
189
221
|
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
190
222
|
declare const isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
223
|
+
declare const mapFail: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
191
224
|
declare const val: <T>(r: Done<T>) => T;
|
|
192
225
|
declare const err: <E>(r: Fail<E>) => E;
|
|
226
|
+
declare const tapFail: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
193
227
|
type Result<T, E> = Done<T> | Fail<E>;
|
|
194
228
|
declare const Result: {
|
|
195
229
|
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
196
|
-
done: <T>(
|
|
197
|
-
fail: <E>(
|
|
230
|
+
done: <T>(value: T) => Done<T>;
|
|
231
|
+
fail: <E>(value: E) => Fail<E>;
|
|
198
232
|
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
199
233
|
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
200
234
|
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
@@ -202,7 +236,10 @@ declare const Result: {
|
|
|
202
236
|
fromNullable: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
203
237
|
fromThrowable: <T, E>(fn: () => T, onError: (e: unknown) => E) => Result<T, E>;
|
|
204
238
|
fromPromise: <T, E>(promise: Promise<T>, onError: (e: unknown) => E) => Promise<Result<T, E>>;
|
|
239
|
+
fromPromiseCallback: <T, E>(promise: Promise<T>, onError: (e: unknown) => E, callback: (result: Result<T, E>) => void) => void;
|
|
240
|
+
toPromise: <T, E>(r: Result<T, E>) => Promise<T>;
|
|
205
241
|
map: <T, E, U>(r: Result<T, E>, fn: (a: T) => U) => Result<U, E>;
|
|
242
|
+
mapFail: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
206
243
|
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
207
244
|
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
208
245
|
flatMap: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
@@ -211,19 +248,28 @@ declare const Result: {
|
|
|
211
248
|
done: (a: T) => U;
|
|
212
249
|
fail: (b: E) => U;
|
|
213
250
|
}) => U;
|
|
214
|
-
fold: <T, E, U>(r: Result<T, E>, onFail: (
|
|
251
|
+
fold: <T, E, U>(r: Result<T, E>, onFail: (e: E) => U, onDone: (v: T) => U) => U;
|
|
215
252
|
chain: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
216
|
-
recover: <T, E>(r: Result<T, E>, fn: (
|
|
253
|
+
recover: <T, E>(r: Result<T, E>, fn: (value: E) => T) => Result<T, E>;
|
|
254
|
+
flatMapCallback: <T, E, C>(r: Result<T, E>, fn: (a: T) => Promise<Result<C, E>>, callback: (result: Result<C, E>) => void) => void;
|
|
217
255
|
val: <T>(r: Done<T>) => T;
|
|
218
256
|
err: <E>(r: Fail<E>) => E;
|
|
219
257
|
getOrElse: <T, E>(r: Result<T, E>, defaultValue: T) => T;
|
|
220
258
|
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
221
259
|
getOrNull: <T, E>(r: Result<T, E>) => T | null;
|
|
222
260
|
getOrThrow: <T, E>(r: Result<T, E>) => T;
|
|
261
|
+
all: <T, E>(results: Result<T, E>[]) => Result<T[], E>;
|
|
262
|
+
collect: <T, E>(results: Result<T, E>[]) => Result<T[], E>;
|
|
263
|
+
flatten: <T, E>(r: Result<Result<T, E>, E>) => Result<T, E>;
|
|
264
|
+
partition: <T, E>(results: Result<T, E>[]) => {
|
|
265
|
+
done: T[];
|
|
266
|
+
fail: E[];
|
|
267
|
+
};
|
|
223
268
|
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
224
269
|
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
225
270
|
orElse: <T, E>(a: Result<T, E>, b: Result<T, E>) => Result<T, E>;
|
|
226
271
|
tap: <T, E>(r: Result<T, E>, f: (a: T) => void) => Result<T, E>;
|
|
272
|
+
tapFail: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
227
273
|
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
228
274
|
};
|
|
229
275
|
declare global {
|
|
@@ -232,4 +278,4 @@ declare global {
|
|
|
232
278
|
}
|
|
233
279
|
}
|
|
234
280
|
|
|
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 };
|
|
281
|
+
export { type Done, Either, Err, type Fail, type Left, Maybe, type None, type Nothing, Ok, Option, Pair, Result, type Right, type Some, app, curry, done, eq, eql, err, fail, fromArray, fromObject, fst, isDone, isErr, isFail, isJust, isLeft, isNone, isNothing, isNull, isOk, isRight, isSome, isUndefined, just, left, lft, mapFail, mapFirst, mapLeft, mapSecond, none, nothing, nothingNull, nothingUndefined, pair, rgt, right, snd, some, tapFail, tapLeft, toArray, toObject, unwrap, val };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ 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 mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
13
14
|
declare const lft: <A>(e: Left<A>) => A;
|
|
14
15
|
declare const rgt: <B>(e: Right<B>) => B;
|
|
16
|
+
declare const tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
15
17
|
type Either<A, B> = Left<A> | Right<B>;
|
|
16
18
|
declare const Either: {
|
|
17
19
|
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
@@ -22,24 +24,34 @@ declare const Either: {
|
|
|
22
24
|
fromNullable: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
23
25
|
fromThrowable: <A, B>(fn: () => B, onError: (e: unknown) => A) => Either<A, B>;
|
|
24
26
|
fromPromise: <A, B>(promise: Promise<B>, onError: (e: unknown) => A) => Promise<Either<A, B>>;
|
|
27
|
+
fromPromiseCallback: <A, B>(promise: Promise<B>, onError: (e: unknown) => A, callback: (result: Either<A, B>) => void) => void;
|
|
28
|
+
toPromise: <A, B>(e: Either<A, B>) => Promise<B>;
|
|
25
29
|
map: <A, B, C>(e: Either<A, B>, fn: (r: B) => C) => Either<A, C>;
|
|
26
30
|
mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
27
31
|
bimap: <A, B, C, D>(e: Either<A, B>, fl: (l: A) => C, fr: (r: B) => D) => Either<C, D>;
|
|
28
32
|
flatMap: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
29
33
|
filter: <A, B>(e: Either<A, B>, predicate: (value: B) => boolean, onFalse: A) => Either<A, B>;
|
|
30
|
-
chain: <A, B, C>(e: Either<A, B>, fn: (
|
|
34
|
+
chain: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
31
35
|
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
32
36
|
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
33
37
|
right: (value: B) => C;
|
|
34
38
|
left: (value: A) => C;
|
|
35
39
|
}) => C;
|
|
36
40
|
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
41
|
+
flatMapCallback: <A, B, C>(e: Either<A, B>, fn: (value: B) => Promise<Either<A, C>>, callback: (result: Either<A, C>) => void) => void;
|
|
37
42
|
lft: <A>(e: Left<A>) => A;
|
|
38
43
|
rgt: <B>(e: Right<B>) => B;
|
|
39
44
|
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
40
45
|
getOrNull: <A, B>(e: Either<A, B>) => B | null;
|
|
41
46
|
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
42
47
|
getOrThrow: <A, B>(e: Either<A, B>) => B;
|
|
48
|
+
all: <A, B>(eithers: Either<A, B>[]) => Either<A, B[]>;
|
|
49
|
+
collect: <A, B>(eithers: Either<A, B>[]) => Either<A, B[]>;
|
|
50
|
+
flatten: <A, B>(e: Either<A, Either<A, B>>) => Either<A, B>;
|
|
51
|
+
partition: <A, B>(eithers: Either<A, B>[]) => {
|
|
52
|
+
right: B[];
|
|
53
|
+
left: A[];
|
|
54
|
+
};
|
|
43
55
|
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
44
56
|
apply: <E, A, B>(fn: Either<E, (value: A) => B>, arg: Either<E, A>) => Either<E, B>;
|
|
45
57
|
orElse: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, A | B>;
|
|
@@ -53,14 +65,18 @@ declare global {
|
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
type Nothing = null | undefined;
|
|
56
|
-
declare const just: <T>(value: T) => T
|
|
68
|
+
declare const just: <T>(value: T) => NonNullable<T>;
|
|
57
69
|
declare const nothing: () => Nothing;
|
|
70
|
+
declare const nothingNull: () => null;
|
|
71
|
+
declare const nothingUndefined: () => undefined;
|
|
58
72
|
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
59
73
|
declare const isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
74
|
+
declare const isNull: <T>(m: Maybe<T>) => m is null;
|
|
75
|
+
declare const isUndefined: <T>(m: Maybe<T>) => m is undefined;
|
|
60
76
|
type Maybe<T> = T | Nothing;
|
|
61
77
|
declare const Maybe: {
|
|
62
78
|
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
63
|
-
just: <T>(value: T) => T
|
|
79
|
+
just: <T>(value: T) => NonNullable<T>;
|
|
64
80
|
nothing: () => Nothing;
|
|
65
81
|
nothingNull: () => null;
|
|
66
82
|
nothingUndefined: () => undefined;
|
|
@@ -75,11 +91,11 @@ declare const Maybe: {
|
|
|
75
91
|
map: <T, U>(m: Maybe<T>, fn: (v: T) => U) => Maybe<U>;
|
|
76
92
|
flatMap: <T, U>(m: Maybe<T>, fn: (v: T) => Maybe<U>) => Maybe<U>;
|
|
77
93
|
filter: <T>(m: Maybe<T>, predicate: (value: T) => boolean) => Maybe<T>;
|
|
94
|
+
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
78
95
|
match: <T, U>(m: Maybe<T>, matcher: {
|
|
79
96
|
some: (v: T) => U;
|
|
80
97
|
nothing: () => U;
|
|
81
98
|
}) => U;
|
|
82
|
-
fold: <T, U>(m: Maybe<T>, onNothing: () => U, onJust: (v: T) => U) => U;
|
|
83
99
|
getOrElse: <T>(m: Maybe<T>, defaultValue: T) => T;
|
|
84
100
|
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
85
101
|
getOrNull: <T>(m: Maybe<T>) => T | null;
|
|
@@ -141,8 +157,24 @@ declare global {
|
|
|
141
157
|
}
|
|
142
158
|
|
|
143
159
|
declare const pair: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
160
|
+
declare const curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
161
|
+
declare const fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
162
|
+
declare const fromObject: <A, B>(obj: {
|
|
163
|
+
fst: A;
|
|
164
|
+
snd: B;
|
|
165
|
+
}) => Pair<A, B>;
|
|
166
|
+
declare const toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
167
|
+
declare const toObject: <A, B>(p: Pair<A, B>) => {
|
|
168
|
+
fst: A;
|
|
169
|
+
snd: B;
|
|
170
|
+
};
|
|
171
|
+
declare const mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
172
|
+
declare const mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
173
|
+
declare const eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
174
|
+
declare const eql: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>, eqA: (a1: A, a2: A) => boolean, eqB: (b1: B, b2: B) => boolean) => boolean;
|
|
144
175
|
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
145
176
|
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
177
|
+
declare const app: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
146
178
|
type Pair<A, B> = readonly [A, B];
|
|
147
179
|
declare const Pair: {
|
|
148
180
|
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
@@ -180,21 +212,23 @@ interface Done<T> {
|
|
|
180
212
|
interface Fail<E> {
|
|
181
213
|
readonly e: E;
|
|
182
214
|
}
|
|
183
|
-
declare const done: <T>(
|
|
184
|
-
declare const fail: <E>(
|
|
185
|
-
declare const Ok: <T>(
|
|
186
|
-
declare const Err: <E>(
|
|
215
|
+
declare const done: <T>(value: T) => Done<T>;
|
|
216
|
+
declare const fail: <E>(value: E) => Fail<E>;
|
|
217
|
+
declare const Ok: <T>(value: T) => Done<T>;
|
|
218
|
+
declare const Err: <E>(value: E) => Fail<E>;
|
|
187
219
|
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
188
220
|
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
189
221
|
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
190
222
|
declare const isErr: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
223
|
+
declare const mapFail: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
191
224
|
declare const val: <T>(r: Done<T>) => T;
|
|
192
225
|
declare const err: <E>(r: Fail<E>) => E;
|
|
226
|
+
declare const tapFail: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
193
227
|
type Result<T, E> = Done<T> | Fail<E>;
|
|
194
228
|
declare const Result: {
|
|
195
229
|
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
196
|
-
done: <T>(
|
|
197
|
-
fail: <E>(
|
|
230
|
+
done: <T>(value: T) => Done<T>;
|
|
231
|
+
fail: <E>(value: E) => Fail<E>;
|
|
198
232
|
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
199
233
|
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
200
234
|
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
@@ -202,7 +236,10 @@ declare const Result: {
|
|
|
202
236
|
fromNullable: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
203
237
|
fromThrowable: <T, E>(fn: () => T, onError: (e: unknown) => E) => Result<T, E>;
|
|
204
238
|
fromPromise: <T, E>(promise: Promise<T>, onError: (e: unknown) => E) => Promise<Result<T, E>>;
|
|
239
|
+
fromPromiseCallback: <T, E>(promise: Promise<T>, onError: (e: unknown) => E, callback: (result: Result<T, E>) => void) => void;
|
|
240
|
+
toPromise: <T, E>(r: Result<T, E>) => Promise<T>;
|
|
205
241
|
map: <T, E, U>(r: Result<T, E>, fn: (a: T) => U) => Result<U, E>;
|
|
242
|
+
mapFail: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
206
243
|
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
207
244
|
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
208
245
|
flatMap: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
@@ -211,19 +248,28 @@ declare const Result: {
|
|
|
211
248
|
done: (a: T) => U;
|
|
212
249
|
fail: (b: E) => U;
|
|
213
250
|
}) => U;
|
|
214
|
-
fold: <T, E, U>(r: Result<T, E>, onFail: (
|
|
251
|
+
fold: <T, E, U>(r: Result<T, E>, onFail: (e: E) => U, onDone: (v: T) => U) => U;
|
|
215
252
|
chain: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
216
|
-
recover: <T, E>(r: Result<T, E>, fn: (
|
|
253
|
+
recover: <T, E>(r: Result<T, E>, fn: (value: E) => T) => Result<T, E>;
|
|
254
|
+
flatMapCallback: <T, E, C>(r: Result<T, E>, fn: (a: T) => Promise<Result<C, E>>, callback: (result: Result<C, E>) => void) => void;
|
|
217
255
|
val: <T>(r: Done<T>) => T;
|
|
218
256
|
err: <E>(r: Fail<E>) => E;
|
|
219
257
|
getOrElse: <T, E>(r: Result<T, E>, defaultValue: T) => T;
|
|
220
258
|
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
221
259
|
getOrNull: <T, E>(r: Result<T, E>) => T | null;
|
|
222
260
|
getOrThrow: <T, E>(r: Result<T, E>) => T;
|
|
261
|
+
all: <T, E>(results: Result<T, E>[]) => Result<T[], E>;
|
|
262
|
+
collect: <T, E>(results: Result<T, E>[]) => Result<T[], E>;
|
|
263
|
+
flatten: <T, E>(r: Result<Result<T, E>, E>) => Result<T, E>;
|
|
264
|
+
partition: <T, E>(results: Result<T, E>[]) => {
|
|
265
|
+
done: T[];
|
|
266
|
+
fail: E[];
|
|
267
|
+
};
|
|
223
268
|
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
224
269
|
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
225
270
|
orElse: <T, E>(a: Result<T, E>, b: Result<T, E>) => Result<T, E>;
|
|
226
271
|
tap: <T, E>(r: Result<T, E>, f: (a: T) => void) => Result<T, E>;
|
|
272
|
+
tapFail: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
227
273
|
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
228
274
|
};
|
|
229
275
|
declare global {
|
|
@@ -232,4 +278,4 @@ declare global {
|
|
|
232
278
|
}
|
|
233
279
|
}
|
|
234
280
|
|
|
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 };
|
|
281
|
+
export { type Done, Either, Err, type Fail, type Left, Maybe, type None, type Nothing, Ok, Option, Pair, Result, type Right, type Some, app, curry, done, eq, eql, err, fail, fromArray, fromObject, fst, isDone, isErr, isFail, isJust, isLeft, isNone, isNothing, isNull, isOk, isRight, isSome, isUndefined, just, left, lft, mapFail, mapFirst, mapLeft, mapSecond, none, nothing, nothingNull, nothingUndefined, pair, rgt, right, snd, some, tapFail, tapLeft, toArray, toObject, unwrap, val };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var b=t=>({$:"Left",value:t}),A=t=>({$:"Right",value:t}),P=t=>t.$==="Left",s=t=>t.$==="Right",C=(t,e)=>t==null?b(e):A(t),it=(t,e)=>{try{return A(t())}catch(o){return b(e(o))}},M=(t,e)=>t.then(A,o=>b(e(o))),st=(t,e,o)=>{t.then(T=>o(A(T)),T=>o(b(e(T))));},lt=(t,e,o)=>{P(t)?o(t):e(r(t)).then(o);},pt=t=>s(t)?Promise.resolve(r(t)):Promise.reject(h(t)),Tt=(t,e)=>s(t)?A(e(r(t))):t,N=(t,e)=>P(t)?b(e(h(t))):t,at=(t,e,o)=>s(t)?A(o(r(t))):b(e(h(t))),w=(t,e)=>s(t)?e(r(t)):t,ut=(t,e,o)=>s(t)?e(r(t))?t:b(o):t,ct=(t,e,o)=>s(t)?o(r(t)):e(h(t)),Et=(t,e)=>s(t)?e.right(r(t)):e.left(h(t));var At=t=>s(t)?b(r(t)):A(h(t)),h=t=>t.value,r=t=>t.value,ft=(t,e)=>s(t)?r(t):e,xt=t=>s(t)?r(t):null,Bt=t=>s(t)?r(t):void 0,ht=t=>{if(s(t))return r(t);let e=h(t);throw e instanceof Error?e:new Error(String(e))},dt=(t,e)=>P(t)?t:P(e)?e:A([r(t),r(e)]),mt=(t,e)=>P(t)?t:P(e)?e:A(r(t)(r(e))),yt=(t,e)=>s(t)?t:e,Pt=(t,e)=>(s(t)&&e(r(t)),t),F=(t,e)=>(P(t)&&e(h(t)),t),k=t=>{let e=[];for(let o of t){if(P(o))return o;e.push(r(o));}return A(e)},bt=k,Ot=t=>s(t)?r(t):t,Rt=t=>{let e=[],o=[];for(let T of t)s(T)?e.push(r(T)):o.push(h(T));return {right:e,left:o}},Ut={new:C,left:b,right:A,isLeft:P,isRight:s,fromNullable:C,fromThrowable:it,fromPromise:M,fromPromiseCallback:st,toPromise:pt,map:Tt,mapLeft:N,bimap:at,flatMap:w,filter:ut,chain:w,fold:ct,match:Et,swap:At,flatMapCallback:lt,lft:h,rgt:r,getOrElse:ft,getOrNull:xt,getOrUndefined:Bt,getOrThrow:ht,all:k,collect:bt,flatten:Ot,partition:Rt,zip:dt,apply:mt,orElse:yt,tap:Pt,tapLeft:F};"toEither"in Promise.prototype||Object.defineProperty(Promise.prototype,"toEither",{value:function(t){return M(this,t)},writable:true,configurable:true});var c=t=>t,d=()=>{},D=()=>null,S=()=>{},U=t=>t!=null,f=t=>t==null,$=t=>t===null,j=t=>t===void 0,L=t=>f(t)?d():c(t),gt=(t,e)=>e(t)?t:d(),vt=t=>{try{return t()}catch(e){return d()}},Ct=t=>t.then(c,()=>d()),wt=(t,e)=>f(t)?d():c(e(t)),Mt=(t,e)=>f(t)?d():c(e(t)),Nt=(t,e)=>U(t)&&e(t)?c(t):d(),Ft=(t,e,o)=>f(t)?e():o(t),kt=(t,e)=>f(t)?e.nothing():e.some(t),Lt=(t,e)=>f(t)?e:c(t),Dt=t=>f(t)?void 0:c(t),St=t=>f(t)?null:c(t),$t=t=>{if(f(t))throw new Error("Maybe is nothing");return c(t)},jt=(t,e)=>U(t)&&U(e)?c([t,e]):d(),zt=(t,e)=>U(t)&&U(e)?c(t(e)):d(),qt=(t,e)=>f(t)?e:t,Jt=(t,e)=>(U(t)&&c(e(t)),c(t)),Gt={new:L,just:c,nothing:d,nothingNull:D,nothingUndefined:S,isJust:U,isNothing:f,isNull:$,isUndefined:j,fromNullable:L,fromThrowable:vt,fromPredicate:gt,fromPromise:Ct,map:wt,flatMap:Mt,filter:Nt,fold:Ft,match:kt,getOrElse:Lt,getOrUndefined:Dt,getOrNull:St,getOrThrow:$t,zip:jt,apply:zt,orElse:qt,tap:Jt};var x=()=>({$:"None"}),O=t=>({$:"Some",value:t}),a=t=>t.$==="Some",q=t=>t.$==="None",z=t=>t==null?x():O(t),Ht=(t,e)=>e(t)?O(t):x(),It=t=>{try{return O(t())}catch(e){return x()}},J=t=>t.then(O,()=>x()),Kt=(t,e)=>a(t)?O(e(u(t))):x(),Qt=(t,e)=>a(t)?e(u(t)):x(),Vt=(t,e)=>a(t)&&e(u(t))?t:x(),Wt=(t,e,o)=>a(t)?o(u(t)):e(),Xt=(t,e)=>a(t)?e.some(u(t)):e.none(),u=t=>t.value,Yt=(t,e)=>a(t)?u(t):e,Zt=t=>a(t)?u(t):void 0,_t=t=>a(t)?u(t):null,te=t=>{if(a(t))return u(t);throw new Error("Option is none")},ee=(t,e)=>a(t)&&a(e)?O([u(t),u(e)]):x(),oe=(t,e)=>a(t)&&a(e)?O(u(t)(u(e))):x(),re=(t,e)=>a(t)?t:e,ne=(t,e)=>(a(t)&&e(u(t)),t),ie={new:z,none:x,some:O,isSome:a,isNone:q,fromNullable:z,fromPredicate:Ht,fromThrowable:It,fromPromise:J,map:Kt,flatMap:Qt,filter:Vt,fold:Wt,match:Xt,unwrap:u,getOrElse:Yt,getOrUndefined:Zt,getOrNull:_t,getOrThrow:te,zip:ee,apply:oe,orElse:re,tap:ne};"firstOption"in Array.prototype||Object.defineProperty(Array.prototype,"firstOption",{value:function(){return this[0]?O(this[0]):x()},writable:true,configurable:true});"toOption"in Promise.prototype||Object.defineProperty(Promise.prototype,"toOption",{value:function(){return J(this)},writable:true,configurable:true});var m=(t,e)=>[t,e],se=m,G=t=>e=>[t,e],H=([t,e])=>m(t,e),I=t=>m(t.fst,t.snd),K=t=>[l(t),i(t)],Q=t=>({fst:l(t),snd:i(t)}),V=(t,e)=>m(e(l(t)),i(t)),W=(t,e)=>m(l(t),e(i(t))),le=(t,e,o)=>m(e(l(t)),o(i(t))),pe=t=>m(i(t),l(t)),Te=(t,e)=>e(l(t),i(t)),ae=(t,e)=>e.new(l(t),i(t)),X=(t,e)=>l(t)===l(e)&&i(t)===i(e),Y=(t,e,o,T)=>o(l(t),l(e))&&T(i(t),i(e)),l=t=>t[0],i=t=>t[1],Z=(t,e)=>m(l(t)(e),i(t)),ue=(t,e)=>m(l(e),i(t)(i(e))),ce=(t,e)=>m([l(t),l(e)],[i(t),i(e)]),Ee={new:m,curry:G,fromArray:H,fromObject:I,toArray:K,toObject:Q,mapFirst:V,mapSecond:W,map:le,swap:pe,fold:Te,match:ae,eq:X,eql:Y,fst:l,snd:i,app:Z,apply:ue,zip:ce};var E=t=>({v:t}),R=t=>({e:t}),Ae=E,fe=R,p=t=>"v"in t,B=t=>"e"in t,et=p,ot=B,_=(t,e)=>t==null?R(e):E(t),xe=(t,e)=>{try{return E(t())}catch(o){return R(e(o))}},rt=(t,e)=>t.then(E,o=>R(e(o))),Be=(t,e,o)=>{t.then(T=>o(E(T)),T=>o(R(e(T))));},he=(t,e,o)=>{B(t)?o(t):e(n(t)).then(o);},de=t=>p(t)?Promise.resolve(n(t)):Promise.reject(y(t)),me=(t,e)=>p(t)?E(e(n(t))):t,g=(t,e)=>B(t)?R(e(y(t))):t,ye=(t,e,o)=>p(t)?E(e(n(t))):R(o(y(t))),tt=(t,e)=>p(t)?e(n(t)):t,Pe=(t,e,o)=>p(t)?e(n(t))?t:R(o):t,be=(t,e,o)=>p(t)?o(n(t)):e(y(t)),Oe=(t,e)=>p(t)?e.done(n(t)):e.fail(y(t)),Re=(t,e)=>B(t)?E(e(y(t))):t;var n=t=>t.v,y=t=>t.e,Ue=(t,e)=>p(t)?n(t):e,ge=t=>p(t)?n(t):void 0,ve=t=>p(t)?n(t):null,Ce=t=>{if(p(t))return n(t);let e=y(t);throw e instanceof Error?e:new Error(String(e))},we=(t,e)=>B(t)?t:B(e)?e:E([n(t),n(e)]),Me=(t,e)=>B(t)?t:B(e)?e:E(n(t)(n(e))),Ne=(t,e)=>p(t)?t:e,Fe=(t,e)=>(p(t)&&e(n(t)),t),v=(t,e)=>(B(t)&&e(y(t)),t),nt=t=>{let e=[];for(let o of t){if(B(o))return o;e.push(n(o));}return E(e)},ke=nt,Le=t=>p(t)?n(t):t,De=t=>{let e=[],o=[];for(let T of t)p(T)?e.push(n(T)):o.push(y(T));return {done:e,fail:o}},Se={new:_,done:E,fail:R,isDone:p,isFail:B,isOk:et,isErr:ot,fromNullable:_,fromThrowable:xe,fromPromise:rt,fromPromiseCallback:Be,toPromise:de,map:me,mapFail:g,mapErr:g,bimap:ye,flatMap:tt,filter:Pe,match:Oe,fold:be,chain:tt,recover:Re,flatMapCallback:he,val:n,err:y,getOrElse:Ue,getOrUndefined:ge,getOrNull:ve,getOrThrow:Ce,all:nt,collect:ke,flatten:Le,partition:De,zip:we,apply:Me,orElse:Ne,tap:Fe,tapFail:v,tapErr:v};"toResult"in Promise.prototype||Object.defineProperty(Promise.prototype,"toResult",{value:function(t){return rt(this,t)},writable:true,configurable:true});exports.Either=Ut;exports.Err=fe;exports.Maybe=Gt;exports.Ok=Ae;exports.Option=ie;exports.Pair=Ee;exports.Result=Se;exports.app=Z;exports.curry=G;exports.done=E;exports.eq=X;exports.eql=Y;exports.err=y;exports.fail=R;exports.fromArray=H;exports.fromObject=I;exports.fst=l;exports.isDone=p;exports.isErr=ot;exports.isFail=B;exports.isJust=U;exports.isLeft=P;exports.isNone=q;exports.isNothing=f;exports.isNull=$;exports.isOk=et;exports.isRight=s;exports.isSome=a;exports.isUndefined=j;exports.just=c;exports.left=b;exports.lft=h;exports.mapFail=g;exports.mapFirst=V;exports.mapLeft=N;exports.mapSecond=W;exports.none=x;exports.nothing=d;exports.nothingNull=D;exports.nothingUndefined=S;exports.pair=se;exports.rgt=r;exports.right=A;exports.snd=i;exports.some=O;exports.tapFail=v;exports.tapLeft=F;exports.toArray=K;exports.toObject=Q;exports.unwrap=u;exports.val=n;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var b=t=>({$:"Left",value:t}),A=t=>({$:"Right",value:t}),P=t=>t.$==="Left",s=t=>t.$==="Right",C=(t,e)=>t==null?b(e):A(t),it=(t,e)=>{try{return A(t())}catch(o){return b(e(o))}},M=(t,e)=>t.then(A,o=>b(e(o))),st=(t,e,o)=>{t.then(T=>o(A(T)),T=>o(b(e(T))));},lt=(t,e,o)=>{P(t)?o(t):e(r(t)).then(o);},pt=t=>s(t)?Promise.resolve(r(t)):Promise.reject(h(t)),Tt=(t,e)=>s(t)?A(e(r(t))):t,N=(t,e)=>P(t)?b(e(h(t))):t,at=(t,e,o)=>s(t)?A(o(r(t))):b(e(h(t))),w=(t,e)=>s(t)?e(r(t)):t,ut=(t,e,o)=>s(t)?e(r(t))?t:b(o):t,ct=(t,e,o)=>s(t)?o(r(t)):e(h(t)),Et=(t,e)=>s(t)?e.right(r(t)):e.left(h(t));var At=t=>s(t)?b(r(t)):A(h(t)),h=t=>t.value,r=t=>t.value,ft=(t,e)=>s(t)?r(t):e,xt=t=>s(t)?r(t):null,Bt=t=>s(t)?r(t):void 0,ht=t=>{if(s(t))return r(t);let e=h(t);throw e instanceof Error?e:new Error(String(e))},dt=(t,e)=>P(t)?t:P(e)?e:A([r(t),r(e)]),mt=(t,e)=>P(t)?t:P(e)?e:A(r(t)(r(e))),yt=(t,e)=>s(t)?t:e,Pt=(t,e)=>(s(t)&&e(r(t)),t),F=(t,e)=>(P(t)&&e(h(t)),t),k=t=>{let e=[];for(let o of t){if(P(o))return o;e.push(r(o));}return A(e)},bt=k,Ot=t=>s(t)?r(t):t,Rt=t=>{let e=[],o=[];for(let T of t)s(T)?e.push(r(T)):o.push(h(T));return {right:e,left:o}},Ut={new:C,left:b,right:A,isLeft:P,isRight:s,fromNullable:C,fromThrowable:it,fromPromise:M,fromPromiseCallback:st,toPromise:pt,map:Tt,mapLeft:N,bimap:at,flatMap:w,filter:ut,chain:w,fold:ct,match:Et,swap:At,flatMapCallback:lt,lft:h,rgt:r,getOrElse:ft,getOrNull:xt,getOrUndefined:Bt,getOrThrow:ht,all:k,collect:bt,flatten:Ot,partition:Rt,zip:dt,apply:mt,orElse:yt,tap:Pt,tapLeft:F};"toEither"in Promise.prototype||Object.defineProperty(Promise.prototype,"toEither",{value:function(t){return M(this,t)},writable:true,configurable:true});var c=t=>t,d=()=>{},D=()=>null,S=()=>{},U=t=>t!=null,f=t=>t==null,$=t=>t===null,j=t=>t===void 0,L=t=>f(t)?d():c(t),gt=(t,e)=>e(t)?t:d(),vt=t=>{try{return t()}catch(e){return d()}},Ct=t=>t.then(c,()=>d()),wt=(t,e)=>f(t)?d():c(e(t)),Mt=(t,e)=>f(t)?d():c(e(t)),Nt=(t,e)=>U(t)&&e(t)?c(t):d(),Ft=(t,e,o)=>f(t)?e():o(t),kt=(t,e)=>f(t)?e.nothing():e.some(t),Lt=(t,e)=>f(t)?e:c(t),Dt=t=>f(t)?void 0:c(t),St=t=>f(t)?null:c(t),$t=t=>{if(f(t))throw new Error("Maybe is nothing");return c(t)},jt=(t,e)=>U(t)&&U(e)?c([t,e]):d(),zt=(t,e)=>U(t)&&U(e)?c(t(e)):d(),qt=(t,e)=>f(t)?e:t,Jt=(t,e)=>(U(t)&&c(e(t)),c(t)),Gt={new:L,just:c,nothing:d,nothingNull:D,nothingUndefined:S,isJust:U,isNothing:f,isNull:$,isUndefined:j,fromNullable:L,fromThrowable:vt,fromPredicate:gt,fromPromise:Ct,map:wt,flatMap:Mt,filter:Nt,fold:Ft,match:kt,getOrElse:Lt,getOrUndefined:Dt,getOrNull:St,getOrThrow:$t,zip:jt,apply:zt,orElse:qt,tap:Jt};var x=()=>({$:"None"}),O=t=>({$:"Some",value:t}),a=t=>t.$==="Some",q=t=>t.$==="None",z=t=>t==null?x():O(t),Ht=(t,e)=>e(t)?O(t):x(),It=t=>{try{return O(t())}catch(e){return x()}},J=t=>t.then(O,()=>x()),Kt=(t,e)=>a(t)?O(e(u(t))):x(),Qt=(t,e)=>a(t)?e(u(t)):x(),Vt=(t,e)=>a(t)&&e(u(t))?t:x(),Wt=(t,e,o)=>a(t)?o(u(t)):e(),Xt=(t,e)=>a(t)?e.some(u(t)):e.none(),u=t=>t.value,Yt=(t,e)=>a(t)?u(t):e,Zt=t=>a(t)?u(t):void 0,_t=t=>a(t)?u(t):null,te=t=>{if(a(t))return u(t);throw new Error("Option is none")},ee=(t,e)=>a(t)&&a(e)?O([u(t),u(e)]):x(),oe=(t,e)=>a(t)&&a(e)?O(u(t)(u(e))):x(),re=(t,e)=>a(t)?t:e,ne=(t,e)=>(a(t)&&e(u(t)),t),ie={new:z,none:x,some:O,isSome:a,isNone:q,fromNullable:z,fromPredicate:Ht,fromThrowable:It,fromPromise:J,map:Kt,flatMap:Qt,filter:Vt,fold:Wt,match:Xt,unwrap:u,getOrElse:Yt,getOrUndefined:Zt,getOrNull:_t,getOrThrow:te,zip:ee,apply:oe,orElse:re,tap:ne};"firstOption"in Array.prototype||Object.defineProperty(Array.prototype,"firstOption",{value:function(){return this[0]?O(this[0]):x()},writable:true,configurable:true});"toOption"in Promise.prototype||Object.defineProperty(Promise.prototype,"toOption",{value:function(){return J(this)},writable:true,configurable:true});var m=(t,e)=>[t,e],se=m,G=t=>e=>[t,e],H=([t,e])=>m(t,e),I=t=>m(t.fst,t.snd),K=t=>[l(t),i(t)],Q=t=>({fst:l(t),snd:i(t)}),V=(t,e)=>m(e(l(t)),i(t)),W=(t,e)=>m(l(t),e(i(t))),le=(t,e,o)=>m(e(l(t)),o(i(t))),pe=t=>m(i(t),l(t)),Te=(t,e)=>e(l(t),i(t)),ae=(t,e)=>e.new(l(t),i(t)),X=(t,e)=>l(t)===l(e)&&i(t)===i(e),Y=(t,e,o,T)=>o(l(t),l(e))&&T(i(t),i(e)),l=t=>t[0],i=t=>t[1],Z=(t,e)=>m(l(t)(e),i(t)),ue=(t,e)=>m(l(e),i(t)(i(e))),ce=(t,e)=>m([l(t),l(e)],[i(t),i(e)]),Ee={new:m,curry:G,fromArray:H,fromObject:I,toArray:K,toObject:Q,mapFirst:V,mapSecond:W,map:le,swap:pe,fold:Te,match:ae,eq:X,eql:Y,fst:l,snd:i,app:Z,apply:ue,zip:ce};var E=t=>({v:t}),R=t=>({e:t}),Ae=E,fe=R,p=t=>"v"in t,B=t=>"e"in t,et=p,ot=B,_=(t,e)=>t==null?R(e):E(t),xe=(t,e)=>{try{return E(t())}catch(o){return R(e(o))}},rt=(t,e)=>t.then(E,o=>R(e(o))),Be=(t,e,o)=>{t.then(T=>o(E(T)),T=>o(R(e(T))));},he=(t,e,o)=>{B(t)?o(t):e(n(t)).then(o);},de=t=>p(t)?Promise.resolve(n(t)):Promise.reject(y(t)),me=(t,e)=>p(t)?E(e(n(t))):t,g=(t,e)=>B(t)?R(e(y(t))):t,ye=(t,e,o)=>p(t)?E(e(n(t))):R(o(y(t))),tt=(t,e)=>p(t)?e(n(t)):t,Pe=(t,e,o)=>p(t)?e(n(t))?t:R(o):t,be=(t,e,o)=>p(t)?o(n(t)):e(y(t)),Oe=(t,e)=>p(t)?e.done(n(t)):e.fail(y(t)),Re=(t,e)=>B(t)?E(e(y(t))):t;var n=t=>t.v,y=t=>t.e,Ue=(t,e)=>p(t)?n(t):e,ge=t=>p(t)?n(t):void 0,ve=t=>p(t)?n(t):null,Ce=t=>{if(p(t))return n(t);let e=y(t);throw e instanceof Error?e:new Error(String(e))},we=(t,e)=>B(t)?t:B(e)?e:E([n(t),n(e)]),Me=(t,e)=>B(t)?t:B(e)?e:E(n(t)(n(e))),Ne=(t,e)=>p(t)?t:e,Fe=(t,e)=>(p(t)&&e(n(t)),t),v=(t,e)=>(B(t)&&e(y(t)),t),nt=t=>{let e=[];for(let o of t){if(B(o))return o;e.push(n(o));}return E(e)},ke=nt,Le=t=>p(t)?n(t):t,De=t=>{let e=[],o=[];for(let T of t)p(T)?e.push(n(T)):o.push(y(T));return {done:e,fail:o}},Se={new:_,done:E,fail:R,isDone:p,isFail:B,isOk:et,isErr:ot,fromNullable:_,fromThrowable:xe,fromPromise:rt,fromPromiseCallback:Be,toPromise:de,map:me,mapFail:g,mapErr:g,bimap:ye,flatMap:tt,filter:Pe,match:Oe,fold:be,chain:tt,recover:Re,flatMapCallback:he,val:n,err:y,getOrElse:Ue,getOrUndefined:ge,getOrNull:ve,getOrThrow:Ce,all:nt,collect:ke,flatten:Le,partition:De,zip:we,apply:Me,orElse:Ne,tap:Fe,tapFail:v,tapErr:v};"toResult"in Promise.prototype||Object.defineProperty(Promise.prototype,"toResult",{value:function(t){return rt(this,t)},writable:true,configurable:true});export{Ut as Either,fe as Err,Gt as Maybe,Ae as Ok,ie as Option,Ee as Pair,Se as Result,Z as app,G as curry,E as done,X as eq,Y as eql,y as err,R as fail,H as fromArray,I as fromObject,l as fst,p as isDone,ot as isErr,B as isFail,U as isJust,P as isLeft,q as isNone,f as isNothing,$ as isNull,et as isOk,s as isRight,a as isSome,j as isUndefined,c as just,b as left,h as lft,g as mapFail,V as mapFirst,N as mapLeft,W as mapSecond,x as none,d as nothing,D as nothingNull,S as nothingUndefined,se as pair,r as rgt,A as right,i as snd,O as some,v as tapFail,F as tapLeft,K as toArray,Q as toObject,u as unwrap,n as val};
|