aang 2.0.0-alpha.3 → 2.0.0-alpha.31
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/lib/bool.d.ts +30 -0
- package/lib/bool.js +69 -0
- package/lib/datetime.d.ts +19 -0
- package/lib/datetime.js +57 -0
- package/lib/double.d.ts +19 -0
- package/lib/double.js +49 -0
- package/lib/exceptions.js +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +12 -0
- package/lib/integer.d.ts +30 -0
- package/lib/integer.js +69 -0
- package/lib/miscellaneous.d.ts +5 -0
- package/lib/miscellaneous.js +6 -0
- package/lib/option.d.ts +58 -10
- package/lib/option.js +149 -13
- package/lib/order.d.ts +18 -0
- package/lib/order.js +1 -0
- package/lib/ordering.d.ts +7 -0
- package/lib/ordering.js +6 -0
- package/lib/pair.d.ts +106 -0
- package/lib/pair.js +322 -0
- package/lib/result.d.ts +125 -0
- package/lib/result.js +406 -0
- package/lib/semigroup.d.ts +3 -0
- package/lib/semigroup.js +1 -0
- package/lib/task.d.ts +35 -0
- package/lib/task.js +274 -0
- package/lib/text.d.ts +21 -0
- package/lib/text.js +50 -0
- package/package.json +75 -88
- package/lib/errors.d.ts +0 -4
- package/lib/errors.js +0 -7
package/lib/order.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Option } from "./option.js";
|
|
2
|
+
import type { Ordering } from "./ordering.js";
|
|
3
|
+
export interface Setoid<in A> {
|
|
4
|
+
isSame: (this: A, that: A) => boolean;
|
|
5
|
+
isNotSame: (this: A, that: A) => boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PartialOrder<in A> extends Setoid<A> {
|
|
8
|
+
isLess: (this: A, that: A) => boolean;
|
|
9
|
+
isNotLess: (this: A, that: A) => boolean;
|
|
10
|
+
isMore: (this: A, that: A) => boolean;
|
|
11
|
+
isNotMore: (this: A, that: A) => boolean;
|
|
12
|
+
compare: (this: A, that: A) => Option<Ordering>;
|
|
13
|
+
}
|
|
14
|
+
export interface TotalOrder<in out A> extends PartialOrder<A> {
|
|
15
|
+
max: (this: A, that: A) => A;
|
|
16
|
+
min: (this: A, that: A) => A;
|
|
17
|
+
clamp: (this: A, lower: A, upper: A) => A;
|
|
18
|
+
}
|
package/lib/order.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Ordering = "<" | "=" | ">";
|
|
2
|
+
export declare const isSame: (x: Ordering) => x is "=";
|
|
3
|
+
export declare const isNotSame: (x: Ordering) => x is "<" | ">";
|
|
4
|
+
export declare const isLess: (x: Ordering) => x is "<";
|
|
5
|
+
export declare const isNotLess: (x: Ordering) => x is "=" | ">";
|
|
6
|
+
export declare const isMore: (x: Ordering) => x is ">";
|
|
7
|
+
export declare const isNotMore: (x: Ordering) => x is "<" | "=";
|
package/lib/ordering.js
ADDED
package/lib/pair.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Option } from "./option.js";
|
|
2
|
+
import type { PartialOrder, Setoid, TotalOrder } from "./order.js";
|
|
3
|
+
import type { Ordering } from "./ordering.js";
|
|
4
|
+
import type { Result } from "./result.js";
|
|
5
|
+
import type { Semigroup } from "./semigroup.js";
|
|
6
|
+
import { Task } from "./task.js";
|
|
7
|
+
export declare class Pair<out A, out B> {
|
|
8
|
+
readonly fst: A;
|
|
9
|
+
readonly snd: B;
|
|
10
|
+
constructor(fst: A, snd: B);
|
|
11
|
+
static of<A, B>(fst: A, snd: B): Pair<A, B>;
|
|
12
|
+
static from<A>(value: A): Pair<A, A>;
|
|
13
|
+
static fst<A>(value: A): Pair<A, void>;
|
|
14
|
+
static snd<B>(value: B): Pair<void, B>;
|
|
15
|
+
toString<A, B>(this: Pair<A, B>): string;
|
|
16
|
+
fold<A, B, C>(this: Pair<A, B>, morphism: (a: A, b: B) => C): C;
|
|
17
|
+
map<A, B, C, D>(this: Pair<A, B>, fstMorphism: (fst: A) => C, sndMorphism: (snd: B) => D): Pair<C, D>;
|
|
18
|
+
mapFst<A, B, C>(this: Pair<A, C>, morphism: (fst: A) => B): Pair<B, C>;
|
|
19
|
+
mapSnd<A, B, C>(this: Pair<A, B>, morphism: (snd: B) => C): Pair<A, C>;
|
|
20
|
+
replaceFst<A, B, C>(this: Pair<A, C>, fst: B): Pair<B, C>;
|
|
21
|
+
replaceSnd<A, B, C>(this: Pair<A, B>, snd: C): Pair<A, C>;
|
|
22
|
+
and<A, B, C, D>(this: Pair<A, B>, that: Pair<C, D>): Pair<Pair<A, C>, Pair<B, D>>;
|
|
23
|
+
andFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, that: Pair<B, C>): Pair<Pair<A, B>, C>;
|
|
24
|
+
andThenFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, that: Pair<B, C>): Pair<B, C>;
|
|
25
|
+
andWhenFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, that: Pair<B, C>): Pair<A, C>;
|
|
26
|
+
andSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, that: Pair<A, C>): Pair<A, Pair<B, C>>;
|
|
27
|
+
andThenSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, that: Pair<A, C>): Pair<A, C>;
|
|
28
|
+
andWhenSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, that: Pair<A, C>): Pair<A, B>;
|
|
29
|
+
flatMapFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, arrow: (value: A) => Pair<B, C>): Pair<B, C>;
|
|
30
|
+
flatMapSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, arrow: (value: B) => Pair<A, C>): Pair<A, C>;
|
|
31
|
+
flattenFst<A, B extends Semigroup<B>>(this: Pair<Pair<A, B>, B>): Pair<A, B>;
|
|
32
|
+
flattenSnd<A extends Semigroup<A>, B>(this: Pair<A, Pair<A, B>>): Pair<A, B>;
|
|
33
|
+
flatMapFstUntil<A, B, C extends Semigroup<C>>(this: Pair<A, C>, arrow: (value: A) => Pair<Result<B, A>, C>): Pair<B, C>;
|
|
34
|
+
flatMapSndUntil<A extends Semigroup<A>, B, C>(this: Pair<A, B>, arrow: (value: B) => Pair<A, Result<C, B>>): Pair<A, C>;
|
|
35
|
+
extendMapFst<A, B, C>(this: Pair<A, C>, arrow: (pair: Pair<A, C>) => B): Pair<B, C>;
|
|
36
|
+
extendMapSnd<A, B, C>(this: Pair<A, B>, arrow: (pair: Pair<A, B>) => C): Pair<A, C>;
|
|
37
|
+
extendFst<A, B>(this: Pair<A, B>): Pair<Pair<A, B>, B>;
|
|
38
|
+
extendSnd<A, B>(this: Pair<A, B>): Pair<A, Pair<A, B>>;
|
|
39
|
+
commute<A, B>(this: Pair<A, B>): Pair<B, A>;
|
|
40
|
+
andMapOption<X, Y, A, B>(this: Pair<X, Y>, fstMorphism: (value: X) => Option<A>, sndMorphism: (value: Y) => Option<B>): Option<Pair<A, B>>;
|
|
41
|
+
andMapFstOption<X, A, B>(this: Pair<X, B>, morphism: (value: X) => Option<A>): Option<Pair<A, B>>;
|
|
42
|
+
andMapSndOption<Y, A, B>(this: Pair<A, Y>, morphism: (value: Y) => Option<B>): Option<Pair<A, B>>;
|
|
43
|
+
andOption<A, B>(this: Pair<Option<A>, Option<B>>): Option<Pair<A, B>>;
|
|
44
|
+
andFstOption<A, B>(this: Pair<Option<A>, B>): Option<Pair<A, B>>;
|
|
45
|
+
andSndOption<A, B>(this: Pair<A, Option<B>>): Option<Pair<A, B>>;
|
|
46
|
+
andMapResult<X, Y, A, B, E>(this: Pair<X, Y>, fstMorphism: (value: X) => Result<A, E>, sndMorphism: (value: Y) => Result<B, E>): Result<Pair<A, B>, E>;
|
|
47
|
+
andMapFstResult<X, A, B, E>(this: Pair<X, B>, morphism: (value: X) => Result<A, E>): Result<Pair<A, B>, E>;
|
|
48
|
+
andMapSndResult<Y, A, B, E>(this: Pair<A, Y>, morphism: (value: Y) => Result<B, E>): Result<Pair<A, B>, E>;
|
|
49
|
+
andResult<A, B, E>(this: Pair<Result<A, E>, Result<B, E>>): Result<Pair<A, B>, E>;
|
|
50
|
+
andFstResult<A, B, E>(this: Pair<Result<A, E>, B>): Result<Pair<A, B>, E>;
|
|
51
|
+
andSndResult<A, B, E>(this: Pair<A, Result<B, E>>): Result<Pair<A, B>, E>;
|
|
52
|
+
orMapResult<X, Y, A, E, F>(this: Pair<X, Y>, fstMorphism: (value: X) => Result<A, E>, sndMorphism: (value: Y) => Result<A, F>): Result<A, Pair<E, F>>;
|
|
53
|
+
orMapFstResult<X, A, E, F>(this: Pair<X, F>, morphism: (value: X) => Result<A, E>): Result<A, Pair<E, F>>;
|
|
54
|
+
orMapSndResult<Y, A, E, F>(this: Pair<E, Y>, morphism: (value: Y) => Result<A, F>): Result<A, Pair<E, F>>;
|
|
55
|
+
orResult<A, E, F>(this: Pair<Result<A, E>, Result<A, F>>): Result<A, Pair<E, F>>;
|
|
56
|
+
orFstResult<A, E, F>(this: Pair<Result<A, E>, F>): Result<A, Pair<E, F>>;
|
|
57
|
+
orSndResult<A, E, F>(this: Pair<E, Result<A, F>>): Result<A, Pair<E, F>>;
|
|
58
|
+
andMapTask<X, Y, A, B, E>(this: Pair<X, Y>, fstMorphism: (value: X) => Task<A, E>, sndMorphism: (value: Y) => Task<B, E>): Task<Pair<A, B>, E>;
|
|
59
|
+
andMapFstTask<X, A, B, E>(this: Pair<X, B>, morphism: (value: X) => Task<A, E>): Task<Pair<A, B>, E>;
|
|
60
|
+
andMapSndTask<Y, A, B, E>(this: Pair<A, Y>, morphism: (value: Y) => Task<B, E>): Task<Pair<A, B>, E>;
|
|
61
|
+
andTask<A, B, E>(this: Pair<Task<A, E>, Task<B, E>>): Task<Pair<A, B>, E>;
|
|
62
|
+
andFstTask<A, B, E>(this: Pair<Task<A, E>, B>): Task<Pair<A, B>, E>;
|
|
63
|
+
andSndTask<A, B, E>(this: Pair<A, Task<B, E>>): Task<Pair<A, B>, E>;
|
|
64
|
+
orMapTask<X, Y, A, E, F>(this: Pair<X, Y>, fstMorphism: (value: X) => Task<A, E>, sndMorphism: (value: Y) => Task<A, F>): Task<A, Pair<E, F>>;
|
|
65
|
+
orMapFstTask<X, A, E, F>(this: Pair<X, F>, morphism: (value: X) => Task<A, E>): Task<A, Pair<E, F>>;
|
|
66
|
+
orMapSndTask<Y, A, E, F>(this: Pair<E, Y>, morphism: (value: Y) => Task<A, F>): Task<A, Pair<E, F>>;
|
|
67
|
+
orTask<A, E, F>(this: Pair<Task<A, E>, Task<A, F>>): Task<A, Pair<E, F>>;
|
|
68
|
+
orFstTask<A, E, F>(this: Pair<Task<A, E>, F>): Task<A, Pair<E, F>>;
|
|
69
|
+
orSndTask<A, E, F>(this: Pair<E, Task<A, F>>): Task<A, Pair<E, F>>;
|
|
70
|
+
distributeMap<X, Y, A, B, C, D>(this: Pair<X, Y>, fstMorphism: (value: X) => Pair<A, B>, sndMorphism: (value: Y) => Pair<C, D>): Pair<Pair<A, C>, Pair<B, D>>;
|
|
71
|
+
distributeMapFst<X, A, B, C>(this: Pair<X, C>, morphism: (value: X) => Pair<A, B>): Pair<Pair<A, C>, Pair<B, C>>;
|
|
72
|
+
distributeMapSnd<Y, A, B, C>(this: Pair<A, Y>, morphism: (value: Y) => Pair<B, C>): Pair<Pair<A, B>, Pair<A, C>>;
|
|
73
|
+
distribute<A, B, C, D>(this: Pair<Pair<A, B>, Pair<C, D>>): Pair<Pair<A, C>, Pair<B, D>>;
|
|
74
|
+
distributeFst<A, B, C>(this: Pair<Pair<A, B>, C>): Pair<Pair<A, C>, Pair<B, C>>;
|
|
75
|
+
distributeSnd<A, B, C>(this: Pair<A, Pair<B, C>>): Pair<Pair<A, B>, Pair<A, C>>;
|
|
76
|
+
exchangeMapSnd<X, A, B, C>(this: Pair<X, C>, morphism: (value: X) => Pair<A, B>): Pair<Pair<A, C>, B>;
|
|
77
|
+
associateMapLeft<Y, A, B, C>(this: Pair<A, Y>, morphism: (value: Y) => Pair<B, C>): Pair<Pair<A, B>, C>;
|
|
78
|
+
exchangeSnd<A, B, C>(this: Pair<Pair<A, B>, C>): Pair<Pair<A, C>, B>;
|
|
79
|
+
associateLeft<A, B, C>(this: Pair<A, Pair<B, C>>): Pair<Pair<A, B>, C>;
|
|
80
|
+
exchangeMapFst<Y, A, B, C>(this: Pair<A, Y>, morphism: (value: Y) => Pair<B, C>): Pair<B, Pair<A, C>>;
|
|
81
|
+
associateMapRight<X, A, B, C>(this: Pair<X, C>, morphism: (value: X) => Pair<A, B>): Pair<A, Pair<B, C>>;
|
|
82
|
+
exchangeFst<A, B, C>(this: Pair<A, Pair<B, C>>): Pair<B, Pair<A, C>>;
|
|
83
|
+
associateRight<A, B, C>(this: Pair<Pair<A, B>, C>): Pair<A, Pair<B, C>>;
|
|
84
|
+
distributeMapOkay<Y, A, B, C>(this: Pair<A, Y>, morphism: (value: Y) => Result<B, C>): Result<Pair<A, B>, Pair<A, C>>;
|
|
85
|
+
distributeOkay<A, B, C>(this: Pair<A, Result<B, C>>): Result<Pair<A, B>, Pair<A, C>>;
|
|
86
|
+
distributeMapFail<X, A, B, C>(this: Pair<X, C>, morphism: (value: X) => Result<A, B>): Result<Pair<A, C>, Pair<B, C>>;
|
|
87
|
+
distributeFail<A, B, C>(this: Pair<Result<A, B>, C>): Result<Pair<A, C>, Pair<B, C>>;
|
|
88
|
+
scatterMapOkay<Y, A, B, C>(this: Pair<A, Y>, morphism: (value: Y) => Task<B, C>): Task<Pair<A, B>, Pair<A, C>>;
|
|
89
|
+
scatterOkay<A, B, C>(this: Pair<A, Task<B, C>>): Task<Pair<A, B>, Pair<A, C>>;
|
|
90
|
+
scatterMapFail<X, A, B, C>(this: Pair<X, C>, morphism: (value: X) => Task<A, B>): Task<Pair<A, C>, Pair<B, C>>;
|
|
91
|
+
scatterFail<A, B, C>(this: Pair<Task<A, B>, C>): Task<Pair<A, C>, Pair<B, C>>;
|
|
92
|
+
isSame<A extends Setoid<A>, B extends Setoid<B>>(this: Pair<A, B>, that: Pair<A, B>): boolean;
|
|
93
|
+
isNotSame<A extends Setoid<A>, B extends Setoid<B>>(this: Pair<A, B>, that: Pair<A, B>): boolean;
|
|
94
|
+
isLess<A extends PartialOrder<A>, B extends PartialOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): boolean;
|
|
95
|
+
isNotLess<A extends PartialOrder<A>, B extends PartialOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): boolean;
|
|
96
|
+
isMore<A extends PartialOrder<A>, B extends PartialOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): boolean;
|
|
97
|
+
isNotMore<A extends PartialOrder<A>, B extends PartialOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): boolean;
|
|
98
|
+
compare<A extends PartialOrder<A>, B extends PartialOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): Option<Ordering>;
|
|
99
|
+
max<A extends TotalOrder<A>, B extends TotalOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): Pair<A, B>;
|
|
100
|
+
min<A extends TotalOrder<A>, B extends TotalOrder<B>>(this: Pair<A, B>, that: Pair<A, B>): Pair<A, B>;
|
|
101
|
+
clamp<A extends TotalOrder<A>, B extends TotalOrder<B>>(this: Pair<A, B>, lower: Pair<A, B>, upper: Pair<A, B>): Pair<A, B>;
|
|
102
|
+
values<A, B>(this: Pair<A, B>): [A, B];
|
|
103
|
+
effectMap<A, B, C>(this: Pair<A, C>, morphism: (value: A) => B): Generator<Pair<A, C>, B, A>;
|
|
104
|
+
effect<A, B>(this: Pair<A, B>): Generator<Pair<A, B>, A, A>;
|
|
105
|
+
static fromGenerator<A, B extends Semigroup<B>>(value: B, getGenerator: () => Generator<Pair<unknown, B>, A, unknown>): Pair<A, B>;
|
|
106
|
+
}
|
package/lib/pair.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { Some } from "./option.js";
|
|
2
|
+
import { isLess, isMore, isNotLess, isNotMore, isSame } from "./ordering.js";
|
|
3
|
+
import { Fail, Okay } from "./result.js";
|
|
4
|
+
import { Task } from "./task.js";
|
|
5
|
+
export class Pair {
|
|
6
|
+
fst;
|
|
7
|
+
snd;
|
|
8
|
+
constructor(fst, snd) {
|
|
9
|
+
this.fst = fst;
|
|
10
|
+
this.snd = snd;
|
|
11
|
+
}
|
|
12
|
+
static of(fst, snd) {
|
|
13
|
+
return new Pair(fst, snd);
|
|
14
|
+
}
|
|
15
|
+
static from(value) {
|
|
16
|
+
return new Pair(value, value);
|
|
17
|
+
}
|
|
18
|
+
static fst(value) {
|
|
19
|
+
return new Pair(value, undefined);
|
|
20
|
+
}
|
|
21
|
+
static snd(value) {
|
|
22
|
+
return new Pair(undefined, value);
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return `Pair(${String(this.fst)}, ${String(this.snd)})`;
|
|
26
|
+
}
|
|
27
|
+
fold(morphism) {
|
|
28
|
+
return morphism(this.fst, this.snd);
|
|
29
|
+
}
|
|
30
|
+
map(fstMorphism, sndMorphism) {
|
|
31
|
+
return new Pair(fstMorphism(this.fst), sndMorphism(this.snd));
|
|
32
|
+
}
|
|
33
|
+
mapFst(morphism) {
|
|
34
|
+
return new Pair(morphism(this.fst), this.snd);
|
|
35
|
+
}
|
|
36
|
+
mapSnd(morphism) {
|
|
37
|
+
return new Pair(this.fst, morphism(this.snd));
|
|
38
|
+
}
|
|
39
|
+
replaceFst(fst) {
|
|
40
|
+
return new Pair(fst, this.snd);
|
|
41
|
+
}
|
|
42
|
+
replaceSnd(snd) {
|
|
43
|
+
return new Pair(this.fst, snd);
|
|
44
|
+
}
|
|
45
|
+
and(that) {
|
|
46
|
+
return new Pair(new Pair(this.fst, that.fst), new Pair(this.snd, that.snd));
|
|
47
|
+
}
|
|
48
|
+
andFst(that) {
|
|
49
|
+
return new Pair(new Pair(this.fst, that.fst), this.snd.append(that.snd));
|
|
50
|
+
}
|
|
51
|
+
andThenFst(that) {
|
|
52
|
+
return new Pair(that.fst, this.snd.append(that.snd));
|
|
53
|
+
}
|
|
54
|
+
andWhenFst(that) {
|
|
55
|
+
return new Pair(this.fst, this.snd.append(that.snd));
|
|
56
|
+
}
|
|
57
|
+
andSnd(that) {
|
|
58
|
+
return new Pair(this.fst.append(that.fst), new Pair(this.snd, that.snd));
|
|
59
|
+
}
|
|
60
|
+
andThenSnd(that) {
|
|
61
|
+
return new Pair(this.fst.append(that.fst), that.snd);
|
|
62
|
+
}
|
|
63
|
+
andWhenSnd(that) {
|
|
64
|
+
return new Pair(this.fst.append(that.fst), this.snd);
|
|
65
|
+
}
|
|
66
|
+
flatMapFst(arrow) {
|
|
67
|
+
return arrow(this.fst).mapSnd((snd) => this.snd.append(snd));
|
|
68
|
+
}
|
|
69
|
+
flatMapSnd(arrow) {
|
|
70
|
+
return arrow(this.snd).mapFst((fst) => this.fst.append(fst));
|
|
71
|
+
}
|
|
72
|
+
flattenFst() {
|
|
73
|
+
return this.fst.mapSnd((snd) => this.snd.append(snd));
|
|
74
|
+
}
|
|
75
|
+
flattenSnd() {
|
|
76
|
+
return this.snd.mapFst((fst) => this.fst.append(fst));
|
|
77
|
+
}
|
|
78
|
+
flatMapFstUntil(arrow) {
|
|
79
|
+
let result = this.flatMapFst(arrow).distributeFail();
|
|
80
|
+
while (result.isFail)
|
|
81
|
+
result = result.value.flatMapFst(arrow).distributeFail();
|
|
82
|
+
return result.value;
|
|
83
|
+
}
|
|
84
|
+
flatMapSndUntil(arrow) {
|
|
85
|
+
let result = this.flatMapSnd(arrow).distributeOkay();
|
|
86
|
+
while (result.isFail)
|
|
87
|
+
result = result.value.flatMapSnd(arrow).distributeOkay();
|
|
88
|
+
return result.value;
|
|
89
|
+
}
|
|
90
|
+
extendMapFst(arrow) {
|
|
91
|
+
return new Pair(arrow(this), this.snd);
|
|
92
|
+
}
|
|
93
|
+
extendMapSnd(arrow) {
|
|
94
|
+
return new Pair(this.fst, arrow(this));
|
|
95
|
+
}
|
|
96
|
+
extendFst() {
|
|
97
|
+
return new Pair(this, this.snd);
|
|
98
|
+
}
|
|
99
|
+
extendSnd() {
|
|
100
|
+
return new Pair(this.fst, this);
|
|
101
|
+
}
|
|
102
|
+
commute() {
|
|
103
|
+
return new Pair(this.snd, this.fst);
|
|
104
|
+
}
|
|
105
|
+
andMapOption(fstMorphism, sndMorphism) {
|
|
106
|
+
return fstMorphism(this.fst).and(sndMorphism(this.snd));
|
|
107
|
+
}
|
|
108
|
+
andMapFstOption(morphism) {
|
|
109
|
+
return morphism(this.fst).and(new Some(this.snd));
|
|
110
|
+
}
|
|
111
|
+
andMapSndOption(morphism) {
|
|
112
|
+
return new Some(this.fst).and(morphism(this.snd));
|
|
113
|
+
}
|
|
114
|
+
andOption() {
|
|
115
|
+
return this.fst.and(this.snd);
|
|
116
|
+
}
|
|
117
|
+
andFstOption() {
|
|
118
|
+
return this.fst.and(new Some(this.snd));
|
|
119
|
+
}
|
|
120
|
+
andSndOption() {
|
|
121
|
+
return new Some(this.fst).and(this.snd);
|
|
122
|
+
}
|
|
123
|
+
andMapResult(fstMorphism, sndMorphism) {
|
|
124
|
+
return fstMorphism(this.fst).and(sndMorphism(this.snd));
|
|
125
|
+
}
|
|
126
|
+
andMapFstResult(morphism) {
|
|
127
|
+
return morphism(this.fst).and(new Okay(this.snd));
|
|
128
|
+
}
|
|
129
|
+
andMapSndResult(morphism) {
|
|
130
|
+
return new Okay(this.fst).and(morphism(this.snd));
|
|
131
|
+
}
|
|
132
|
+
andResult() {
|
|
133
|
+
return this.fst.and(this.snd);
|
|
134
|
+
}
|
|
135
|
+
andFstResult() {
|
|
136
|
+
return this.fst.and(new Okay(this.snd));
|
|
137
|
+
}
|
|
138
|
+
andSndResult() {
|
|
139
|
+
return new Okay(this.fst).and(this.snd);
|
|
140
|
+
}
|
|
141
|
+
orMapResult(fstMorphism, sndMorphism) {
|
|
142
|
+
return fstMorphism(this.fst).or(sndMorphism(this.snd));
|
|
143
|
+
}
|
|
144
|
+
orMapFstResult(morphism) {
|
|
145
|
+
return morphism(this.fst).or(new Fail(this.snd));
|
|
146
|
+
}
|
|
147
|
+
orMapSndResult(morphism) {
|
|
148
|
+
return new Fail(this.fst).or(morphism(this.snd));
|
|
149
|
+
}
|
|
150
|
+
orResult() {
|
|
151
|
+
return this.fst.or(this.snd);
|
|
152
|
+
}
|
|
153
|
+
orFstResult() {
|
|
154
|
+
return this.fst.or(new Fail(this.snd));
|
|
155
|
+
}
|
|
156
|
+
orSndResult() {
|
|
157
|
+
return new Fail(this.fst).or(this.snd);
|
|
158
|
+
}
|
|
159
|
+
andMapTask(fstMorphism, sndMorphism) {
|
|
160
|
+
return fstMorphism(this.fst).and(sndMorphism(this.snd));
|
|
161
|
+
}
|
|
162
|
+
andMapFstTask(morphism) {
|
|
163
|
+
return morphism(this.fst).and(Task.okay(this.snd));
|
|
164
|
+
}
|
|
165
|
+
andMapSndTask(morphism) {
|
|
166
|
+
return Task.okay(this.fst).and(morphism(this.snd));
|
|
167
|
+
}
|
|
168
|
+
andTask() {
|
|
169
|
+
return this.fst.and(this.snd);
|
|
170
|
+
}
|
|
171
|
+
andFstTask() {
|
|
172
|
+
return this.fst.and(Task.okay(this.snd));
|
|
173
|
+
}
|
|
174
|
+
andSndTask() {
|
|
175
|
+
return Task.okay(this.fst).and(this.snd);
|
|
176
|
+
}
|
|
177
|
+
orMapTask(fstMorphism, sndMorphism) {
|
|
178
|
+
return fstMorphism(this.fst).or(sndMorphism(this.snd));
|
|
179
|
+
}
|
|
180
|
+
orMapFstTask(morphism) {
|
|
181
|
+
return morphism(this.fst).or(Task.fail(this.snd));
|
|
182
|
+
}
|
|
183
|
+
orMapSndTask(morphism) {
|
|
184
|
+
return Task.fail(this.fst).or(morphism(this.snd));
|
|
185
|
+
}
|
|
186
|
+
orTask() {
|
|
187
|
+
return this.fst.or(this.snd);
|
|
188
|
+
}
|
|
189
|
+
orFstTask() {
|
|
190
|
+
return this.fst.or(Task.fail(this.snd));
|
|
191
|
+
}
|
|
192
|
+
orSndTask() {
|
|
193
|
+
return Task.fail(this.fst).or(this.snd);
|
|
194
|
+
}
|
|
195
|
+
distributeMap(fstMorphism, sndMorphism) {
|
|
196
|
+
const fst = fstMorphism(this.fst);
|
|
197
|
+
const snd = sndMorphism(this.snd);
|
|
198
|
+
return new Pair(new Pair(fst.fst, snd.fst), new Pair(fst.snd, snd.snd));
|
|
199
|
+
}
|
|
200
|
+
distributeMapFst(morphism) {
|
|
201
|
+
const fst = morphism(this.fst);
|
|
202
|
+
return new Pair(new Pair(fst.fst, this.snd), new Pair(fst.snd, this.snd));
|
|
203
|
+
}
|
|
204
|
+
distributeMapSnd(morphism) {
|
|
205
|
+
const snd = morphism(this.snd);
|
|
206
|
+
return new Pair(new Pair(this.fst, snd.fst), new Pair(this.fst, snd.snd));
|
|
207
|
+
}
|
|
208
|
+
distribute() {
|
|
209
|
+
return new Pair(new Pair(this.fst.fst, this.snd.fst), new Pair(this.fst.snd, this.snd.snd));
|
|
210
|
+
}
|
|
211
|
+
distributeFst() {
|
|
212
|
+
return new Pair(new Pair(this.fst.fst, this.snd), new Pair(this.fst.snd, this.snd));
|
|
213
|
+
}
|
|
214
|
+
distributeSnd() {
|
|
215
|
+
return new Pair(new Pair(this.fst, this.snd.fst), new Pair(this.fst, this.snd.snd));
|
|
216
|
+
}
|
|
217
|
+
exchangeMapSnd(morphism) {
|
|
218
|
+
const fst = morphism(this.fst);
|
|
219
|
+
return new Pair(new Pair(fst.fst, this.snd), fst.snd);
|
|
220
|
+
}
|
|
221
|
+
associateMapLeft(morphism) {
|
|
222
|
+
const snd = morphism(this.snd);
|
|
223
|
+
return new Pair(new Pair(this.fst, snd.fst), snd.snd);
|
|
224
|
+
}
|
|
225
|
+
exchangeSnd() {
|
|
226
|
+
return new Pair(new Pair(this.fst.fst, this.snd), this.fst.snd);
|
|
227
|
+
}
|
|
228
|
+
associateLeft() {
|
|
229
|
+
return new Pair(new Pair(this.fst, this.snd.fst), this.snd.snd);
|
|
230
|
+
}
|
|
231
|
+
exchangeMapFst(morphism) {
|
|
232
|
+
const snd = morphism(this.snd);
|
|
233
|
+
return new Pair(snd.fst, new Pair(this.fst, snd.snd));
|
|
234
|
+
}
|
|
235
|
+
associateMapRight(morphism) {
|
|
236
|
+
const fst = morphism(this.fst);
|
|
237
|
+
return new Pair(fst.fst, new Pair(fst.snd, this.snd));
|
|
238
|
+
}
|
|
239
|
+
exchangeFst() {
|
|
240
|
+
return new Pair(this.snd.fst, new Pair(this.fst, this.snd.snd));
|
|
241
|
+
}
|
|
242
|
+
associateRight() {
|
|
243
|
+
return new Pair(this.fst.fst, new Pair(this.fst.snd, this.snd));
|
|
244
|
+
}
|
|
245
|
+
distributeMapOkay(morphism) {
|
|
246
|
+
return morphism(this.snd).map((snd) => new Pair(this.fst, snd), (snd) => new Pair(this.fst, snd));
|
|
247
|
+
}
|
|
248
|
+
distributeOkay() {
|
|
249
|
+
return this.snd.map((snd) => new Pair(this.fst, snd), (snd) => new Pair(this.fst, snd));
|
|
250
|
+
}
|
|
251
|
+
distributeMapFail(morphism) {
|
|
252
|
+
return morphism(this.fst).map((fst) => new Pair(fst, this.snd), (fst) => new Pair(fst, this.snd));
|
|
253
|
+
}
|
|
254
|
+
distributeFail() {
|
|
255
|
+
return this.fst.map((fst) => new Pair(fst, this.snd), (fst) => new Pair(fst, this.snd));
|
|
256
|
+
}
|
|
257
|
+
scatterMapOkay(morphism) {
|
|
258
|
+
return morphism(this.snd).map((snd) => new Pair(this.fst, snd), (snd) => new Pair(this.fst, snd));
|
|
259
|
+
}
|
|
260
|
+
scatterOkay() {
|
|
261
|
+
return this.snd.map((snd) => new Pair(this.fst, snd), (snd) => new Pair(this.fst, snd));
|
|
262
|
+
}
|
|
263
|
+
scatterMapFail(morphism) {
|
|
264
|
+
return morphism(this.fst).map((fst) => new Pair(fst, this.snd), (fst) => new Pair(fst, this.snd));
|
|
265
|
+
}
|
|
266
|
+
scatterFail() {
|
|
267
|
+
return this.fst.map((fst) => new Pair(fst, this.snd), (fst) => new Pair(fst, this.snd));
|
|
268
|
+
}
|
|
269
|
+
isSame(that) {
|
|
270
|
+
return this.fst.isSame(that.fst) && this.snd.isSame(that.snd);
|
|
271
|
+
}
|
|
272
|
+
isNotSame(that) {
|
|
273
|
+
return this.fst.isNotSame(that.fst) || this.snd.isNotSame(that.snd);
|
|
274
|
+
}
|
|
275
|
+
isLess(that) {
|
|
276
|
+
return this.compare(that).isSomeAnd(isLess);
|
|
277
|
+
}
|
|
278
|
+
isNotLess(that) {
|
|
279
|
+
return this.compare(that).isSomeAnd(isNotLess);
|
|
280
|
+
}
|
|
281
|
+
isMore(that) {
|
|
282
|
+
return this.compare(that).isSomeAnd(isMore);
|
|
283
|
+
}
|
|
284
|
+
isNotMore(that) {
|
|
285
|
+
return this.compare(that).isSomeAnd(isNotMore);
|
|
286
|
+
}
|
|
287
|
+
compare(that) {
|
|
288
|
+
const option = this.fst.compare(that.fst);
|
|
289
|
+
return option.isSomeAnd(isSame) ? this.snd.compare(that.snd) : option;
|
|
290
|
+
}
|
|
291
|
+
max(that) {
|
|
292
|
+
return this.isNotLess(that) ? this : that;
|
|
293
|
+
}
|
|
294
|
+
min(that) {
|
|
295
|
+
return this.isNotMore(that) ? this : that;
|
|
296
|
+
}
|
|
297
|
+
clamp(lower, upper) {
|
|
298
|
+
return this.max(lower).min(upper);
|
|
299
|
+
}
|
|
300
|
+
values() {
|
|
301
|
+
return [this.fst, this.snd];
|
|
302
|
+
}
|
|
303
|
+
*effectMap(morphism) {
|
|
304
|
+
const value = yield this;
|
|
305
|
+
return morphism(value);
|
|
306
|
+
}
|
|
307
|
+
*effect() {
|
|
308
|
+
const value = yield this;
|
|
309
|
+
return value;
|
|
310
|
+
}
|
|
311
|
+
static fromGenerator(value, getGenerator) {
|
|
312
|
+
const generator = getGenerator();
|
|
313
|
+
let result = generator.next();
|
|
314
|
+
let snd = value;
|
|
315
|
+
while (!result.done) {
|
|
316
|
+
const pair = result.value;
|
|
317
|
+
snd = snd.append(pair.snd);
|
|
318
|
+
result = generator.next(pair.fst);
|
|
319
|
+
}
|
|
320
|
+
return new Pair(result.value, snd);
|
|
321
|
+
}
|
|
322
|
+
}
|
package/lib/result.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Option } from "./option.js";
|
|
2
|
+
import type { PartialOrder, Setoid, TotalOrder } from "./order.js";
|
|
3
|
+
import type { Ordering } from "./ordering.js";
|
|
4
|
+
import { Pair } from "./pair.js";
|
|
5
|
+
import { Task } from "./task.js";
|
|
6
|
+
export type Result<A, E> = Okay<A> | Fail<E>;
|
|
7
|
+
declare abstract class ResultTrait {
|
|
8
|
+
abstract readonly isOkay: boolean;
|
|
9
|
+
abstract readonly isFail: boolean;
|
|
10
|
+
toString<A, E>(this: Result<A, E>): string;
|
|
11
|
+
fold<A, E, T>(this: Result<A, E>, okayMorphism: (value: A) => T, failMorphism: (value: E) => T): T;
|
|
12
|
+
map<A, B, E, F>(this: Result<A, E>, okayMorphism: (value: A) => B, failMorphism: (value: E) => F): Result<B, F>;
|
|
13
|
+
mapOkay<A, B, E>(this: Result<A, E>, morphism: (value: A) => B): Result<B, E>;
|
|
14
|
+
mapFail<A, E, F>(this: Result<A, E>, morphism: (value: E) => F): Result<A, F>;
|
|
15
|
+
replace<A, B, E, F>(this: Result<A, E>, okayValue: B, failValue: F): Result<B, F>;
|
|
16
|
+
replaceOkay<A, B, E>(this: Result<A, E>, value: B): Result<B, E>;
|
|
17
|
+
replaceFail<A, E, F>(this: Result<A, E>, value: F): Result<A, F>;
|
|
18
|
+
and<A, B, E>(this: Result<A, E>, that: Result<B, E>): Result<Pair<A, B>, E>;
|
|
19
|
+
andThen<A, B, E>(this: Result<A, E>, that: Result<B, E>): Result<B, E>;
|
|
20
|
+
andWhen<A, B, E>(this: Result<A, E>, that: Result<B, E>): Result<A, E>;
|
|
21
|
+
or<A, E, F>(this: Result<A, E>, that: Result<A, F>): Result<A, Pair<E, F>>;
|
|
22
|
+
orElse<A, E, F>(this: Result<A, E>, that: Result<A, F>): Result<A, F>;
|
|
23
|
+
orErst<A, E, F>(this: Result<A, E>, that: Result<A, F>): Result<A, E>;
|
|
24
|
+
flatMap<A, B, E, F>(this: Result<A, E>, okayArrow: (value: A) => Result<B, F>, failArrow: (value: E) => Result<B, F>): Result<B, F>;
|
|
25
|
+
flatMapOkay<A, B, E>(this: Result<A, E>, arrow: (value: A) => Result<B, E>): Result<B, E>;
|
|
26
|
+
flatMapFail<A, E, F>(this: Result<A, E>, arrow: (value: E) => Result<A, F>): Result<A, F>;
|
|
27
|
+
flattenOkay<A, E>(this: Result<Result<A, E>, E>): Result<A, E>;
|
|
28
|
+
flattenFail<A, E>(this: Result<A, Result<A, E>>): Result<A, E>;
|
|
29
|
+
flatMapUntil<A, B, E, F>(this: Result<A, E>, okayArrow: (value: A) => Result<Result<B, A>, Result<F, E>>, failArrow: (value: E) => Result<Result<B, A>, Result<F, E>>): Result<B, F>;
|
|
30
|
+
flatMapOkayUntil<A, B, E>(this: Result<A, E>, arrow: (value: A) => Result<Result<B, A>, E>): Result<B, E>;
|
|
31
|
+
flatMapFailUntil<A, E, F>(this: Result<A, E>, arrow: (value: E) => Result<A, Result<F, E>>): Result<A, F>;
|
|
32
|
+
commute<A>(this: Okay<A>): Fail<A>;
|
|
33
|
+
commute<A>(this: Fail<A>): Okay<A>;
|
|
34
|
+
commute<A, B>(this: Result<A, B>): Result<B, A>;
|
|
35
|
+
isOkayAnd<A, B extends A, E>(this: Result<A, E>, predicate: (value: A) => value is B): this is Okay<B>;
|
|
36
|
+
isOkayAnd<A, E>(this: Result<A, E>, predicate: (value: A) => boolean): this is Okay<A>;
|
|
37
|
+
isFailAnd<A, E, F extends E>(this: Result<A, E>, predicate: (value: E) => value is F): this is Fail<F>;
|
|
38
|
+
isFailAnd<A, E>(this: Result<A, E>, predicate: (value: E) => boolean): this is Fail<E>;
|
|
39
|
+
isOkayOr<A, E, F extends E>(this: Result<A, E>, predicate: (value: E) => value is F): this is Result<A, F>;
|
|
40
|
+
isOkayOr<A, E>(this: Result<A, E>, predicate: (value: E) => boolean): boolean;
|
|
41
|
+
isFailOr<A, B extends A, E>(this: Result<A, E>, predicate: (value: A) => value is B): this is Result<B, E>;
|
|
42
|
+
isFailOr<A, E>(this: Result<A, E>, predicate: (value: A) => boolean): boolean;
|
|
43
|
+
transposeMap<A, B, E, F>(this: Result<A, E>, transposeOkay: (value: A) => Option<B>, transposeFail: (value: E) => Option<F>): Option<Result<B, F>>;
|
|
44
|
+
transposeMapOkay<A, B, E>(this: Result<A, E>, transpose: (value: A) => Option<B>): Option<Result<B, E>>;
|
|
45
|
+
transposeMapFail<A, E, F>(this: Result<A, E>, transpose: (value: E) => Option<F>): Option<Result<A, F>>;
|
|
46
|
+
transpose<A, E>(this: Result<Option<A>, Option<E>>): Option<Result<A, E>>;
|
|
47
|
+
transposeOkay<A, E>(this: Result<Option<A>, E>): Option<Result<A, E>>;
|
|
48
|
+
transposeFail<A, E>(this: Result<A, Option<E>>): Option<Result<A, E>>;
|
|
49
|
+
unzipWith<X, Y, A, B, E, F>(this: Result<X, Y>, unzipOkay: (value: X) => Pair<A, B>, unzipFail: (value: Y) => Pair<E, F>): Pair<Result<A, E>, Result<B, F>>;
|
|
50
|
+
unzipWithOkay<X, A, B, E>(this: Result<X, E>, unzip: (value: X) => Pair<A, B>): Pair<Result<A, E>, Result<B, E>>;
|
|
51
|
+
unzipWithFail<Y, A, E, F>(this: Result<A, Y>, unzip: (value: Y) => Pair<E, F>): Pair<Result<A, E>, Result<A, F>>;
|
|
52
|
+
unzip<A, B, E, F>(this: Result<Pair<A, B>, Pair<E, F>>): Pair<Result<A, E>, Result<B, F>>;
|
|
53
|
+
unzipOkay<A, B, E>(this: Result<Pair<A, B>, E>): Pair<Result<A, E>, Result<B, E>>;
|
|
54
|
+
unzipFail<A, E, F>(this: Result<A, Pair<E, F>>): Pair<Result<A, E>, Result<A, F>>;
|
|
55
|
+
collectMapFst<X, Y, A, B, C>(this: Result<X, Y>, okayMorphism: (value: X) => Pair<A, C>, failMorphism: (value: Y) => Pair<B, C>): Pair<Result<A, B>, C>;
|
|
56
|
+
collectFst<A, B, C>(this: Result<Pair<A, C>, Pair<B, C>>): Pair<Result<A, B>, C>;
|
|
57
|
+
collectMapSnd<X, Y, A, B, C>(this: Result<X, Y>, okayMorphism: (value: X) => Pair<A, B>, failMorphism: (value: Y) => Pair<A, C>): Pair<A, Result<B, C>>;
|
|
58
|
+
collectSnd<A, B, C>(this: Result<Pair<A, B>, Pair<A, C>>): Pair<A, Result<B, C>>;
|
|
59
|
+
collectMapOkay<X, Y, A, B, E>(this: Result<X, Y>, okayMorphism: (value: X) => Result<A, E>, failMorphism: (value: Y) => Result<B, E>): Result<Result<A, B>, E>;
|
|
60
|
+
exchangeMapFail<X, A, E, F>(this: Result<X, F>, exchange: (value: X) => Result<A, E>): Result<Result<A, F>, E>;
|
|
61
|
+
associateMapLeft<Y, A, B, C>(this: Result<A, Y>, morphism: (value: Y) => Result<B, C>): Result<Result<A, B>, C>;
|
|
62
|
+
collectOkay<A, B, E>(this: Result<Result<A, E>, Result<B, E>>): Result<Result<A, B>, E>;
|
|
63
|
+
exchangeFail<A, E, F>(this: Result<Result<A, E>, F>): Result<Result<A, F>, E>;
|
|
64
|
+
associateLeft<A, B, C>(this: Result<A, Result<B, C>>): Result<Result<A, B>, C>;
|
|
65
|
+
collectMapFail<X, Y, A, E, F>(this: Result<X, Y>, okayMorphism: (value: X) => Result<A, E>, failMorphism: (value: Y) => Result<A, F>): Result<A, Result<E, F>>;
|
|
66
|
+
exchangeMapOkay<Y, A, B, E>(this: Result<A, Y>, exchange: (value: Y) => Result<B, E>): Result<B, Result<A, E>>;
|
|
67
|
+
associateMapRight<X, A, B, C>(this: Result<X, C>, morphism: (value: X) => Result<A, B>): Result<A, Result<B, C>>;
|
|
68
|
+
collectFail<A, E, F>(this: Result<Result<A, E>, Result<A, F>>): Result<A, Result<E, F>>;
|
|
69
|
+
exchangeOkay<A, B, E>(this: Result<A, Result<B, E>>): Result<B, Result<A, E>>;
|
|
70
|
+
associateRight<A, B, C>(this: Result<Result<A, B>, C>): Result<A, Result<B, C>>;
|
|
71
|
+
distributeMap<X, Y, A, B, E, F>(this: Result<X, Y>, okayMorphism: (value: X) => Result<A, B>, failMorphism: (value: Y) => Result<E, F>): Result<Result<A, E>, Result<B, F>>;
|
|
72
|
+
distribute<A, B, E, F>(this: Result<Result<A, B>, Result<E, F>>): Result<Result<A, E>, Result<B, F>>;
|
|
73
|
+
gatherMapOkay<X, Y, A, B, E>(this: Result<X, Y>, okayMorphism: (value: X) => Task<A, E>, failMorphism: (value: Y) => Task<B, E>): Task<Result<A, B>, E>;
|
|
74
|
+
swapMapFail<X, A, E, F>(this: Result<X, F>, morphism: (value: X) => Task<A, E>): Task<Result<A, F>, E>;
|
|
75
|
+
groupMapLeft<Y, A, B, C>(this: Result<A, Y>, morphism: (value: Y) => Task<B, C>): Task<Result<A, B>, C>;
|
|
76
|
+
gatherOkay<A, B, E>(this: Result<Task<A, E>, Task<B, E>>): Task<Result<A, B>, E>;
|
|
77
|
+
swapFail<A, E, F>(this: Result<Task<A, E>, F>): Task<Result<A, F>, E>;
|
|
78
|
+
groupLeft<A, B, C>(this: Result<A, Task<B, C>>): Task<Result<A, B>, C>;
|
|
79
|
+
gatherMapFail<X, Y, A, E, F>(this: Result<X, Y>, okayMorphism: (value: X) => Task<A, E>, failMorphism: (value: Y) => Task<A, F>): Task<A, Result<E, F>>;
|
|
80
|
+
swapMapOkay<Y, A, B, E>(this: Result<A, Y>, morphism: (value: Y) => Task<B, E>): Task<B, Result<A, E>>;
|
|
81
|
+
groupMapRight<X, A, B, C>(this: Result<X, C>, morphism: (value: X) => Task<A, B>): Task<A, Result<B, C>>;
|
|
82
|
+
gatherFail<A, E, F>(this: Result<Task<A, E>, Task<A, F>>): Task<A, Result<E, F>>;
|
|
83
|
+
swapOkay<A, B, E>(this: Result<A, Task<B, E>>): Task<B, Result<A, E>>;
|
|
84
|
+
groupRight<A, B, C>(this: Result<Task<A, B>, C>): Task<A, Result<B, C>>;
|
|
85
|
+
interchangeMap<X, Y, A, B, E, F>(this: Result<X, Y>, okayMorphism: (value: X) => Task<A, B>, failMorphism: (value: Y) => Task<E, F>): Task<Result<A, E>, Result<B, F>>;
|
|
86
|
+
interchange<A, B, E, F>(this: Result<Task<A, B>, Task<E, F>>): Task<Result<A, E>, Result<B, F>>;
|
|
87
|
+
extractOkay<A, E>(this: Result<A, E>, defaultValue: A): A;
|
|
88
|
+
extractFail<A, E>(this: Result<A, E>, defaultValue: E): E;
|
|
89
|
+
extractMapOkay<A, E>(this: Result<A, E>, getOkayValue: (value: E) => A): A;
|
|
90
|
+
extractMapFail<A, E>(this: Result<A, E>, getFailValue: (value: A) => E): E;
|
|
91
|
+
toOptionOkay<A, E>(this: Result<A, E>): Option<A>;
|
|
92
|
+
toOptionFail<A, E>(this: Result<A, E>): Option<E>;
|
|
93
|
+
toTask<A, E>(this: Result<A, E>): Task<A, E>;
|
|
94
|
+
isSame<A extends Setoid<A>, E extends Setoid<E>>(this: Result<A, E>, that: Result<A, E>): boolean;
|
|
95
|
+
isNotSame<A extends Setoid<A>, E extends Setoid<E>>(this: Result<A, E>, that: Result<A, E>): boolean;
|
|
96
|
+
isLess<A extends PartialOrder<A>, E extends PartialOrder<E>>(this: Result<A, E>, that: Result<A, E>): boolean;
|
|
97
|
+
isNotLess<A extends PartialOrder<A>, E extends PartialOrder<E>>(this: Result<A, E>, that: Result<A, E>): boolean;
|
|
98
|
+
isMore<A extends PartialOrder<A>, E extends PartialOrder<E>>(this: Result<A, E>, that: Result<A, E>): boolean;
|
|
99
|
+
isNotMore<A extends PartialOrder<A>, E extends PartialOrder<E>>(this: Result<A, E>, that: Result<A, E>): boolean;
|
|
100
|
+
compare<A extends PartialOrder<A>, E extends PartialOrder<E>>(this: Result<A, E>, that: Result<A, E>): Option<Ordering>;
|
|
101
|
+
max<A extends TotalOrder<A>, E extends TotalOrder<E>>(this: Result<A, E>, that: Result<A, E>): Result<A, E>;
|
|
102
|
+
min<A extends TotalOrder<A>, E extends TotalOrder<E>>(this: Result<A, E>, that: Result<A, E>): Result<A, E>;
|
|
103
|
+
clamp<A extends TotalOrder<A>, E extends TotalOrder<E>>(this: Result<A, E>, lower: Result<A, E>, upper: Result<A, E>): Result<A, E>;
|
|
104
|
+
okayValues<A, E>(this: Result<A, E>): Generator<A, void, undefined>;
|
|
105
|
+
failValues<A, E>(this: Result<A, E>): Generator<E, void, undefined>;
|
|
106
|
+
values<A, E>(this: Result<A, E>): Generator<A | E, void, undefined>;
|
|
107
|
+
effectMap<A, B, E>(this: Result<A, E>, morphism: (value: A) => B): Generator<Result<A, E>, B, A>;
|
|
108
|
+
effect<A, E>(this: Result<A, E>): Generator<Result<A, E>, A, A>;
|
|
109
|
+
}
|
|
110
|
+
export declare class Okay<out A> extends ResultTrait {
|
|
111
|
+
readonly value: A;
|
|
112
|
+
readonly isOkay = true;
|
|
113
|
+
readonly isFail = false;
|
|
114
|
+
constructor(value: A);
|
|
115
|
+
static of<A>(value: A): Okay<A>;
|
|
116
|
+
static fromGenerator<A>(getGenerator: () => Generator<Result<unknown, unknown>, A, unknown>): Result<A, unknown>;
|
|
117
|
+
}
|
|
118
|
+
export declare class Fail<out E> extends ResultTrait {
|
|
119
|
+
readonly value: E;
|
|
120
|
+
readonly isOkay = false;
|
|
121
|
+
readonly isFail = true;
|
|
122
|
+
constructor(value: E);
|
|
123
|
+
static of<E>(value: E): Fail<E>;
|
|
124
|
+
}
|
|
125
|
+
export {};
|