lite-fp 0.5.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 +114 -60
- package/dist/index.d.ts +114 -60
- 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
|
@@ -1,45 +1,60 @@
|
|
|
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 mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
14
|
+
declare const lft: <A>(e: Left<A>) => A;
|
|
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: {
|
|
19
|
+
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
17
20
|
left: <A>(value: A) => Left<A>;
|
|
18
21
|
right: <B>(value: B) => Right<B>;
|
|
19
|
-
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
20
22
|
isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
21
23
|
isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
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>;
|
|
34
|
+
chain: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
30
35
|
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
31
36
|
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
32
37
|
right: (value: B) => C;
|
|
33
38
|
left: (value: A) => C;
|
|
34
39
|
}) => C;
|
|
35
40
|
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
flatMapCallback: <A, B, C>(e: Either<A, B>, fn: (value: B) => Promise<Either<A, C>>, callback: (result: Either<A, C>) => void) => void;
|
|
42
|
+
lft: <A>(e: Left<A>) => A;
|
|
43
|
+
rgt: <B>(e: Right<B>) => B;
|
|
38
44
|
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
45
|
+
getOrNull: <A, B>(e: Either<A, B>) => B | null;
|
|
39
46
|
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
40
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
|
+
};
|
|
41
55
|
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
42
56
|
apply: <E, A, B>(fn: Either<E, (value: A) => B>, arg: Either<E, A>) => Either<E, B>;
|
|
57
|
+
orElse: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, A | B>;
|
|
43
58
|
tap: <A, B>(e: Either<A, B>, f: (r: B) => void) => Either<A, B>;
|
|
44
59
|
tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
45
60
|
};
|
|
@@ -49,52 +64,55 @@ declare global {
|
|
|
49
64
|
}
|
|
50
65
|
}
|
|
51
66
|
|
|
52
|
-
type
|
|
53
|
-
|
|
54
|
-
type Nothing = NothingNull | NothingUndefined;
|
|
55
|
-
declare const just: <T>(value: T) => Maybe<T>;
|
|
67
|
+
type Nothing = null | undefined;
|
|
68
|
+
declare const just: <T>(value: T) => NonNullable<T>;
|
|
56
69
|
declare const nothing: () => Nothing;
|
|
70
|
+
declare const nothingNull: () => null;
|
|
71
|
+
declare const nothingUndefined: () => undefined;
|
|
57
72
|
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
58
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;
|
|
59
76
|
type Maybe<T> = T | Nothing;
|
|
60
77
|
declare const Maybe: {
|
|
61
|
-
just: <T>(value: T) => Maybe<T>;
|
|
62
|
-
nothing: () => Nothing;
|
|
63
78
|
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
just: <T>(value: T) => NonNullable<T>;
|
|
80
|
+
nothing: () => Nothing;
|
|
81
|
+
nothingNull: () => null;
|
|
82
|
+
nothingUndefined: () => undefined;
|
|
66
83
|
isJust: <T>(m: Maybe<T>) => m is T;
|
|
67
84
|
isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
isNull: <T>(m: Maybe<T>) => m is null;
|
|
86
|
+
isUndefined: <T>(m: Maybe<T>) => m is undefined;
|
|
70
87
|
fromNullable: <T>(m: T | null | undefined) => Maybe<T>;
|
|
71
88
|
fromThrowable: <T>(fn: () => T) => Maybe<T>;
|
|
89
|
+
fromPredicate: <T>(value: T, predicate: (value: T) => boolean) => Maybe<T>;
|
|
72
90
|
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
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
|
-
|
|
83
|
-
getOrElse: <T>(m: Maybe<T>, d: T) => T;
|
|
99
|
+
getOrElse: <T>(m: Maybe<T>, defaultValue: T) => T;
|
|
84
100
|
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
101
|
+
getOrNull: <T>(m: Maybe<T>) => T | null;
|
|
85
102
|
getOrThrow: <T>(m: Maybe<T>) => T;
|
|
86
103
|
zip: <T, U>(a: Maybe<T>, b: Maybe<U>) => Maybe<[T, U]>;
|
|
87
104
|
apply: <T, U>(fn: Maybe<(value: T) => U>, opt: Maybe<T>) => Maybe<U>;
|
|
88
105
|
orElse: <T>(opt: Maybe<T>, other: Maybe<T>) => Maybe<T>;
|
|
106
|
+
tap: <T>(m: Maybe<T>, fn: (v: T) => void) => Maybe<T>;
|
|
89
107
|
};
|
|
90
108
|
|
|
91
|
-
|
|
109
|
+
interface None {
|
|
92
110
|
readonly $: "None";
|
|
93
|
-
}
|
|
94
|
-
|
|
111
|
+
}
|
|
112
|
+
interface Some<T> {
|
|
95
113
|
readonly $: "Some";
|
|
96
114
|
readonly value: T;
|
|
97
|
-
}
|
|
115
|
+
}
|
|
98
116
|
declare const none: <T>() => Option<T>;
|
|
99
117
|
declare const some: <T>(value: T) => Option<T>;
|
|
100
118
|
declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
@@ -102,9 +120,9 @@ declare const isNone: <T>(option: Option<T>) => option is None;
|
|
|
102
120
|
declare const unwrap: <T>(option: Some<T>) => T;
|
|
103
121
|
type Option<T> = None | Some<T>;
|
|
104
122
|
declare const Option: {
|
|
123
|
+
new: <T>(value: T | null | undefined) => Option<T>;
|
|
105
124
|
none: <T>() => Option<T>;
|
|
106
125
|
some: <T>(value: T) => Option<T>;
|
|
107
|
-
new: <T>(value: T | null | undefined) => Option<T>;
|
|
108
126
|
isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
109
127
|
isNone: <T>(option: Option<T>) => option is None;
|
|
110
128
|
fromNullable: <T>(value: T | null | undefined) => Option<T>;
|
|
@@ -114,6 +132,7 @@ declare const Option: {
|
|
|
114
132
|
map: <T, U>(option: Option<T>, fn: (value: T) => U) => Option<U>;
|
|
115
133
|
flatMap: <T, U>(option: Option<T>, fn: (value: T) => Option<U>) => Option<U>;
|
|
116
134
|
filter: <T>(option: Option<T>, predicate: (value: T) => boolean) => Option<T>;
|
|
135
|
+
fold: <T, U>(option: Option<T>, onNone: () => U, onSome: (value: T) => U) => U;
|
|
117
136
|
match: <T, U>(option: Option<T>, matcher: {
|
|
118
137
|
some: (value: T) => U;
|
|
119
138
|
none: () => U;
|
|
@@ -121,10 +140,12 @@ declare const Option: {
|
|
|
121
140
|
unwrap: <T>(option: Some<T>) => T;
|
|
122
141
|
getOrElse: <T>(option: Option<T>, defaultValue: T) => T;
|
|
123
142
|
getOrUndefined: <T>(option: Option<T>) => T | undefined;
|
|
143
|
+
getOrNull: <T>(option: Option<T>) => T | null;
|
|
124
144
|
getOrThrow: <T>(option: Option<T>) => T;
|
|
125
145
|
zip: <T, U>(a: Option<T>, b: Option<U>) => Option<[T, U]>;
|
|
126
146
|
apply: <T, U>(fn: Option<(value: T) => U>, opt: Option<T>) => Option<U>;
|
|
127
147
|
orElse: <T>(opt: Option<T>, other: Option<T>) => Option<T>;
|
|
148
|
+
tap: <T>(option: Option<T>, f: (value: T) => void) => Option<T>;
|
|
128
149
|
};
|
|
129
150
|
declare global {
|
|
130
151
|
interface Array<T> {
|
|
@@ -135,62 +156,79 @@ declare global {
|
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
|
|
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;
|
|
138
175
|
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
139
176
|
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
140
|
-
declare const
|
|
177
|
+
declare const app: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
141
178
|
type Pair<A, B> = readonly [A, B];
|
|
142
179
|
declare const Pair: {
|
|
143
|
-
fst: <A, B>(p: Pair<A, B>) => A;
|
|
144
|
-
snd: <A, B>(p: Pair<A, B>) => B;
|
|
145
180
|
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
181
|
+
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
146
182
|
fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
147
183
|
fromObject: <A, B>(obj: {
|
|
148
184
|
fst: A;
|
|
149
185
|
snd: B;
|
|
150
186
|
}) => 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
187
|
toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
160
188
|
toObject: <A, B>(p: Pair<A, B>) => {
|
|
161
189
|
fst: A;
|
|
162
190
|
snd: B;
|
|
163
191
|
};
|
|
192
|
+
mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
193
|
+
mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
194
|
+
map: <A, B, C, D>(p: Pair<A, B>, fnA: (a: A) => C, fnB: (b: B) => D) => Pair<C, D>;
|
|
195
|
+
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
196
|
+
fold: <A, B, C>(p: Pair<A, B>, fn: (first: A, second: B) => C) => C;
|
|
197
|
+
match: <A, B, C>(p: Pair<A, B>, matcher: {
|
|
198
|
+
new: (first: A, second: B) => C;
|
|
199
|
+
}) => C;
|
|
164
200
|
eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
165
|
-
|
|
201
|
+
eql: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>, eqA: (a1: A, a2: A) => boolean, eqB: (b1: B, b2: B) => boolean) => boolean;
|
|
202
|
+
fst: <A, B>(p: Pair<A, B>) => A;
|
|
203
|
+
snd: <A, B>(p: Pair<A, B>) => B;
|
|
204
|
+
app: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
205
|
+
apply: <A, B, C>(fnPair: Pair<(a: A) => B, (b: B) => C>, vPair: Pair<A, B>) => Pair<A, C>;
|
|
166
206
|
zip: <A, B, C, D>(p1: Pair<A, B>, p2: Pair<C, D>) => Pair<Pair<A, C>, Pair<B, D>>;
|
|
167
207
|
};
|
|
168
208
|
|
|
169
|
-
|
|
209
|
+
interface Done<T> {
|
|
170
210
|
readonly v: T;
|
|
171
|
-
}
|
|
172
|
-
|
|
211
|
+
}
|
|
212
|
+
interface Fail<E> {
|
|
173
213
|
readonly e: E;
|
|
174
|
-
}
|
|
175
|
-
declare const done: <T>(
|
|
176
|
-
declare const fail: <E>(
|
|
177
|
-
declare const Ok: <T>(
|
|
178
|
-
declare const Err: <E>(
|
|
214
|
+
}
|
|
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>;
|
|
179
219
|
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
180
220
|
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
181
221
|
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
182
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>;
|
|
183
224
|
declare const val: <T>(r: Done<T>) => T;
|
|
184
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>;
|
|
185
227
|
type Result<T, E> = Done<T> | Fail<E>;
|
|
186
228
|
declare const Result: {
|
|
187
|
-
done: <T>(v: T) => Done<T>;
|
|
188
|
-
fail: <E>(e: E) => Fail<E>;
|
|
189
|
-
Ok: <T>(v: T) => Done<T>;
|
|
190
|
-
Err: <E>(e: E) => Fail<E>;
|
|
191
|
-
val: <T>(r: Done<T>) => T;
|
|
192
|
-
err: <E>(r: Fail<E>) => E;
|
|
193
229
|
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
230
|
+
done: <T>(value: T) => Done<T>;
|
|
231
|
+
fail: <E>(value: E) => Fail<E>;
|
|
194
232
|
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
195
233
|
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
196
234
|
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
@@ -198,24 +236,40 @@ declare const Result: {
|
|
|
198
236
|
fromNullable: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
199
237
|
fromThrowable: <T, E>(fn: () => T, onError: (e: unknown) => E) => Result<T, E>;
|
|
200
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>;
|
|
201
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>;
|
|
202
243
|
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
203
244
|
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
204
245
|
flatMap: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
246
|
+
filter: <T, E>(r: Result<T, E>, predicate: (a: T) => boolean, onFalse: E) => Result<T, E>;
|
|
205
247
|
match: <T, E, U>(r: Result<T, E>, matcher: {
|
|
206
248
|
done: (a: T) => U;
|
|
207
249
|
fail: (b: E) => U;
|
|
208
250
|
}) => U;
|
|
209
|
-
fold: <T, E, U>(r: Result<T, E>, onFail: (
|
|
210
|
-
|
|
211
|
-
|
|
251
|
+
fold: <T, E, U>(r: Result<T, E>, onFail: (e: E) => U, onDone: (v: T) => U) => U;
|
|
252
|
+
chain: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
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;
|
|
255
|
+
val: <T>(r: Done<T>) => T;
|
|
256
|
+
err: <E>(r: Fail<E>) => E;
|
|
257
|
+
getOrElse: <T, E>(r: Result<T, E>, defaultValue: T) => T;
|
|
212
258
|
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
259
|
+
getOrNull: <T, E>(r: Result<T, E>) => T | null;
|
|
213
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
|
+
};
|
|
214
268
|
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
215
269
|
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
216
270
|
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
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>;
|
|
219
273
|
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
220
274
|
};
|
|
221
275
|
declare global {
|
|
@@ -224,4 +278,4 @@ declare global {
|
|
|
224
278
|
}
|
|
225
279
|
}
|
|
226
280
|
|
|
227
|
-
export { type Done, Either, Err, type Fail, type Left, Maybe, type None, type Nothing,
|
|
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
|
@@ -1,45 +1,60 @@
|
|
|
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 mapLeft: <A, B, C>(e: Either<A, B>, fn: (l: A) => C) => Either<C, B>;
|
|
14
|
+
declare const lft: <A>(e: Left<A>) => A;
|
|
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: {
|
|
19
|
+
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
17
20
|
left: <A>(value: A) => Left<A>;
|
|
18
21
|
right: <B>(value: B) => Right<B>;
|
|
19
|
-
new: <A, B>(value: B | null | undefined, error: A) => Either<A, B>;
|
|
20
22
|
isLeft: <A, B>(e: Either<A, B>) => e is Left<A>;
|
|
21
23
|
isRight: <A, B>(e: Either<A, B>) => e is Right<B>;
|
|
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>;
|
|
34
|
+
chain: <A, B, C>(e: Either<A, B>, fn: (value: B) => Either<A, C>) => Either<A, C>;
|
|
30
35
|
fold: <A, B, C>(e: Either<A, B>, onLeft: (l: A) => C, onRight: (r: B) => C) => C;
|
|
31
36
|
match: <A, B, C>(e: Either<A, B>, matcher: {
|
|
32
37
|
right: (value: B) => C;
|
|
33
38
|
left: (value: A) => C;
|
|
34
39
|
}) => C;
|
|
35
40
|
swap: <A, B>(e: Either<A, B>) => Either<B, A>;
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
flatMapCallback: <A, B, C>(e: Either<A, B>, fn: (value: B) => Promise<Either<A, C>>, callback: (result: Either<A, C>) => void) => void;
|
|
42
|
+
lft: <A>(e: Left<A>) => A;
|
|
43
|
+
rgt: <B>(e: Right<B>) => B;
|
|
38
44
|
getOrElse: <A, B>(e: Either<A, B>, defaultValue: B) => B;
|
|
45
|
+
getOrNull: <A, B>(e: Either<A, B>) => B | null;
|
|
39
46
|
getOrUndefined: <A, B>(e: Either<A, B>) => B | undefined;
|
|
40
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
|
+
};
|
|
41
55
|
zip: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, [A, B]>;
|
|
42
56
|
apply: <E, A, B>(fn: Either<E, (value: A) => B>, arg: Either<E, A>) => Either<E, B>;
|
|
57
|
+
orElse: <E, A, B>(a: Either<E, A>, b: Either<E, B>) => Either<E, A | B>;
|
|
43
58
|
tap: <A, B>(e: Either<A, B>, f: (r: B) => void) => Either<A, B>;
|
|
44
59
|
tapLeft: <A, B>(e: Either<A, B>, f: (l: A) => void) => Either<A, B>;
|
|
45
60
|
};
|
|
@@ -49,52 +64,55 @@ declare global {
|
|
|
49
64
|
}
|
|
50
65
|
}
|
|
51
66
|
|
|
52
|
-
type
|
|
53
|
-
|
|
54
|
-
type Nothing = NothingNull | NothingUndefined;
|
|
55
|
-
declare const just: <T>(value: T) => Maybe<T>;
|
|
67
|
+
type Nothing = null | undefined;
|
|
68
|
+
declare const just: <T>(value: T) => NonNullable<T>;
|
|
56
69
|
declare const nothing: () => Nothing;
|
|
70
|
+
declare const nothingNull: () => null;
|
|
71
|
+
declare const nothingUndefined: () => undefined;
|
|
57
72
|
declare const isJust: <T>(m: Maybe<T>) => m is T;
|
|
58
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;
|
|
59
76
|
type Maybe<T> = T | Nothing;
|
|
60
77
|
declare const Maybe: {
|
|
61
|
-
just: <T>(value: T) => Maybe<T>;
|
|
62
|
-
nothing: () => Nothing;
|
|
63
78
|
new: <T>(m: T | null | undefined) => Maybe<T>;
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
just: <T>(value: T) => NonNullable<T>;
|
|
80
|
+
nothing: () => Nothing;
|
|
81
|
+
nothingNull: () => null;
|
|
82
|
+
nothingUndefined: () => undefined;
|
|
66
83
|
isJust: <T>(m: Maybe<T>) => m is T;
|
|
67
84
|
isNothing: <T>(m: Maybe<T>) => m is Nothing;
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
isNull: <T>(m: Maybe<T>) => m is null;
|
|
86
|
+
isUndefined: <T>(m: Maybe<T>) => m is undefined;
|
|
70
87
|
fromNullable: <T>(m: T | null | undefined) => Maybe<T>;
|
|
71
88
|
fromThrowable: <T>(fn: () => T) => Maybe<T>;
|
|
89
|
+
fromPredicate: <T>(value: T, predicate: (value: T) => boolean) => Maybe<T>;
|
|
72
90
|
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
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
|
-
|
|
83
|
-
getOrElse: <T>(m: Maybe<T>, d: T) => T;
|
|
99
|
+
getOrElse: <T>(m: Maybe<T>, defaultValue: T) => T;
|
|
84
100
|
getOrUndefined: <T>(m: Maybe<T>) => T | undefined;
|
|
101
|
+
getOrNull: <T>(m: Maybe<T>) => T | null;
|
|
85
102
|
getOrThrow: <T>(m: Maybe<T>) => T;
|
|
86
103
|
zip: <T, U>(a: Maybe<T>, b: Maybe<U>) => Maybe<[T, U]>;
|
|
87
104
|
apply: <T, U>(fn: Maybe<(value: T) => U>, opt: Maybe<T>) => Maybe<U>;
|
|
88
105
|
orElse: <T>(opt: Maybe<T>, other: Maybe<T>) => Maybe<T>;
|
|
106
|
+
tap: <T>(m: Maybe<T>, fn: (v: T) => void) => Maybe<T>;
|
|
89
107
|
};
|
|
90
108
|
|
|
91
|
-
|
|
109
|
+
interface None {
|
|
92
110
|
readonly $: "None";
|
|
93
|
-
}
|
|
94
|
-
|
|
111
|
+
}
|
|
112
|
+
interface Some<T> {
|
|
95
113
|
readonly $: "Some";
|
|
96
114
|
readonly value: T;
|
|
97
|
-
}
|
|
115
|
+
}
|
|
98
116
|
declare const none: <T>() => Option<T>;
|
|
99
117
|
declare const some: <T>(value: T) => Option<T>;
|
|
100
118
|
declare const isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
@@ -102,9 +120,9 @@ declare const isNone: <T>(option: Option<T>) => option is None;
|
|
|
102
120
|
declare const unwrap: <T>(option: Some<T>) => T;
|
|
103
121
|
type Option<T> = None | Some<T>;
|
|
104
122
|
declare const Option: {
|
|
123
|
+
new: <T>(value: T | null | undefined) => Option<T>;
|
|
105
124
|
none: <T>() => Option<T>;
|
|
106
125
|
some: <T>(value: T) => Option<T>;
|
|
107
|
-
new: <T>(value: T | null | undefined) => Option<T>;
|
|
108
126
|
isSome: <T>(option: Option<T>) => option is Some<T>;
|
|
109
127
|
isNone: <T>(option: Option<T>) => option is None;
|
|
110
128
|
fromNullable: <T>(value: T | null | undefined) => Option<T>;
|
|
@@ -114,6 +132,7 @@ declare const Option: {
|
|
|
114
132
|
map: <T, U>(option: Option<T>, fn: (value: T) => U) => Option<U>;
|
|
115
133
|
flatMap: <T, U>(option: Option<T>, fn: (value: T) => Option<U>) => Option<U>;
|
|
116
134
|
filter: <T>(option: Option<T>, predicate: (value: T) => boolean) => Option<T>;
|
|
135
|
+
fold: <T, U>(option: Option<T>, onNone: () => U, onSome: (value: T) => U) => U;
|
|
117
136
|
match: <T, U>(option: Option<T>, matcher: {
|
|
118
137
|
some: (value: T) => U;
|
|
119
138
|
none: () => U;
|
|
@@ -121,10 +140,12 @@ declare const Option: {
|
|
|
121
140
|
unwrap: <T>(option: Some<T>) => T;
|
|
122
141
|
getOrElse: <T>(option: Option<T>, defaultValue: T) => T;
|
|
123
142
|
getOrUndefined: <T>(option: Option<T>) => T | undefined;
|
|
143
|
+
getOrNull: <T>(option: Option<T>) => T | null;
|
|
124
144
|
getOrThrow: <T>(option: Option<T>) => T;
|
|
125
145
|
zip: <T, U>(a: Option<T>, b: Option<U>) => Option<[T, U]>;
|
|
126
146
|
apply: <T, U>(fn: Option<(value: T) => U>, opt: Option<T>) => Option<U>;
|
|
127
147
|
orElse: <T>(opt: Option<T>, other: Option<T>) => Option<T>;
|
|
148
|
+
tap: <T>(option: Option<T>, f: (value: T) => void) => Option<T>;
|
|
128
149
|
};
|
|
129
150
|
declare global {
|
|
130
151
|
interface Array<T> {
|
|
@@ -135,62 +156,79 @@ declare global {
|
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
|
|
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;
|
|
138
175
|
declare const fst: <A, B>(p: Pair<A, B>) => A;
|
|
139
176
|
declare const snd: <A, B>(p: Pair<A, B>) => B;
|
|
140
|
-
declare const
|
|
177
|
+
declare const app: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
141
178
|
type Pair<A, B> = readonly [A, B];
|
|
142
179
|
declare const Pair: {
|
|
143
|
-
fst: <A, B>(p: Pair<A, B>) => A;
|
|
144
|
-
snd: <A, B>(p: Pair<A, B>) => B;
|
|
145
180
|
new: <A, B>(a: A, b: B) => Pair<A, B>;
|
|
181
|
+
curry: <A>(a: A) => <B>(b: B) => Pair<A, B>;
|
|
146
182
|
fromArray: <A, B>([a, b]: [A, B]) => Pair<A, B>;
|
|
147
183
|
fromObject: <A, B>(obj: {
|
|
148
184
|
fst: A;
|
|
149
185
|
snd: B;
|
|
150
186
|
}) => 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
187
|
toArray: <A, B>(p: Pair<A, B>) => [A, B];
|
|
160
188
|
toObject: <A, B>(p: Pair<A, B>) => {
|
|
161
189
|
fst: A;
|
|
162
190
|
snd: B;
|
|
163
191
|
};
|
|
192
|
+
mapFirst: <A, B, C>(p: Pair<A, B>, fn: (a: A) => C) => Pair<C, B>;
|
|
193
|
+
mapSecond: <A, B, C>(p: Pair<A, B>, fn: (b: B) => C) => Pair<A, C>;
|
|
194
|
+
map: <A, B, C, D>(p: Pair<A, B>, fnA: (a: A) => C, fnB: (b: B) => D) => Pair<C, D>;
|
|
195
|
+
swap: <A, B>(p: Pair<A, B>) => Pair<B, A>;
|
|
196
|
+
fold: <A, B, C>(p: Pair<A, B>, fn: (first: A, second: B) => C) => C;
|
|
197
|
+
match: <A, B, C>(p: Pair<A, B>, matcher: {
|
|
198
|
+
new: (first: A, second: B) => C;
|
|
199
|
+
}) => C;
|
|
164
200
|
eq: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>) => boolean;
|
|
165
|
-
|
|
201
|
+
eql: <A, B>(p1: Pair<A, B>, p2: Pair<A, B>, eqA: (a1: A, a2: A) => boolean, eqB: (b1: B, b2: B) => boolean) => boolean;
|
|
202
|
+
fst: <A, B>(p: Pair<A, B>) => A;
|
|
203
|
+
snd: <A, B>(p: Pair<A, B>) => B;
|
|
204
|
+
app: <A, B, C>(p: Pair<(a: A) => B, C>, value: A) => Pair<B, C>;
|
|
205
|
+
apply: <A, B, C>(fnPair: Pair<(a: A) => B, (b: B) => C>, vPair: Pair<A, B>) => Pair<A, C>;
|
|
166
206
|
zip: <A, B, C, D>(p1: Pair<A, B>, p2: Pair<C, D>) => Pair<Pair<A, C>, Pair<B, D>>;
|
|
167
207
|
};
|
|
168
208
|
|
|
169
|
-
|
|
209
|
+
interface Done<T> {
|
|
170
210
|
readonly v: T;
|
|
171
|
-
}
|
|
172
|
-
|
|
211
|
+
}
|
|
212
|
+
interface Fail<E> {
|
|
173
213
|
readonly e: E;
|
|
174
|
-
}
|
|
175
|
-
declare const done: <T>(
|
|
176
|
-
declare const fail: <E>(
|
|
177
|
-
declare const Ok: <T>(
|
|
178
|
-
declare const Err: <E>(
|
|
214
|
+
}
|
|
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>;
|
|
179
219
|
declare const isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
180
220
|
declare const isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
181
221
|
declare const isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
182
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>;
|
|
183
224
|
declare const val: <T>(r: Done<T>) => T;
|
|
184
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>;
|
|
185
227
|
type Result<T, E> = Done<T> | Fail<E>;
|
|
186
228
|
declare const Result: {
|
|
187
|
-
done: <T>(v: T) => Done<T>;
|
|
188
|
-
fail: <E>(e: E) => Fail<E>;
|
|
189
|
-
Ok: <T>(v: T) => Done<T>;
|
|
190
|
-
Err: <E>(e: E) => Fail<E>;
|
|
191
|
-
val: <T>(r: Done<T>) => T;
|
|
192
|
-
err: <E>(r: Fail<E>) => E;
|
|
193
229
|
new: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
230
|
+
done: <T>(value: T) => Done<T>;
|
|
231
|
+
fail: <E>(value: E) => Fail<E>;
|
|
194
232
|
isDone: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
195
233
|
isFail: <T, E>(r: Result<T, E>) => r is Fail<E>;
|
|
196
234
|
isOk: <T, E>(r: Result<T, E>) => r is Done<T>;
|
|
@@ -198,24 +236,40 @@ declare const Result: {
|
|
|
198
236
|
fromNullable: <T, E>(value: T | null | undefined, error: E) => Result<T, E>;
|
|
199
237
|
fromThrowable: <T, E>(fn: () => T, onError: (e: unknown) => E) => Result<T, E>;
|
|
200
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>;
|
|
201
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>;
|
|
202
243
|
mapErr: <T, E, F>(r: Result<T, E>, fn: (b: E) => F) => Result<T, F>;
|
|
203
244
|
bimap: <T, E, U, F>(r: Result<T, E>, onDone: (a: T) => U, onFail: (b: E) => F) => Result<U, F>;
|
|
204
245
|
flatMap: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
246
|
+
filter: <T, E>(r: Result<T, E>, predicate: (a: T) => boolean, onFalse: E) => Result<T, E>;
|
|
205
247
|
match: <T, E, U>(r: Result<T, E>, matcher: {
|
|
206
248
|
done: (a: T) => U;
|
|
207
249
|
fail: (b: E) => U;
|
|
208
250
|
}) => U;
|
|
209
|
-
fold: <T, E, U>(r: Result<T, E>, onFail: (
|
|
210
|
-
|
|
211
|
-
|
|
251
|
+
fold: <T, E, U>(r: Result<T, E>, onFail: (e: E) => U, onDone: (v: T) => U) => U;
|
|
252
|
+
chain: <T, E, C>(r: Result<T, E>, fn: (a: T) => Result<C, E>) => Result<C, E>;
|
|
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;
|
|
255
|
+
val: <T>(r: Done<T>) => T;
|
|
256
|
+
err: <E>(r: Fail<E>) => E;
|
|
257
|
+
getOrElse: <T, E>(r: Result<T, E>, defaultValue: T) => T;
|
|
212
258
|
getOrUndefined: <T, E>(r: Result<T, E>) => T | undefined;
|
|
259
|
+
getOrNull: <T, E>(r: Result<T, E>) => T | null;
|
|
213
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
|
+
};
|
|
214
268
|
zip: <T, U, E>(a: Result<T, E>, b: Result<U, E>) => Result<[T, U], E>;
|
|
215
269
|
apply: <T, U, E>(fn: Result<(a: T) => U, E>, arg: Result<T, E>) => Result<U, E>;
|
|
216
270
|
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
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>;
|
|
219
273
|
tapErr: <T, E>(r: Result<T, E>, f: (b: E) => void) => Result<T, E>;
|
|
220
274
|
};
|
|
221
275
|
declare global {
|
|
@@ -224,4 +278,4 @@ declare global {
|
|
|
224
278
|
}
|
|
225
279
|
}
|
|
226
280
|
|
|
227
|
-
export { type Done, Either, Err, type Fail, type Left, Maybe, type None, type Nothing,
|
|
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
|
-
|
|
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};
|