aang 2.0.0-alpha.26 → 2.0.0-alpha.28
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/exceptions.d.ts +0 -3
- package/lib/exceptions.js +0 -6
- package/lib/option.d.ts +1 -4
- package/lib/option.js +0 -36
- package/lib/pair.d.ts +6 -2
- package/lib/pair.js +16 -4
- package/lib/result.d.ts +1 -1
- package/package.json +1 -1
package/lib/exceptions.d.ts
CHANGED
package/lib/exceptions.js
CHANGED
package/lib/option.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Pair } from "./pair.js";
|
|
|
4
4
|
import type { Result } from "./result.js";
|
|
5
5
|
import type { Semigroup } from "./semigroup.js";
|
|
6
6
|
export type Option<A> = Some<A> | None;
|
|
7
|
-
declare abstract class OptionTrait
|
|
7
|
+
declare abstract class OptionTrait {
|
|
8
8
|
abstract readonly isSome: boolean;
|
|
9
9
|
abstract readonly isNone: boolean;
|
|
10
10
|
toString<A>(this: Option<A>): string;
|
|
@@ -46,8 +46,6 @@ declare abstract class OptionTrait implements Semigroup<Option<never>>, TotalOrd
|
|
|
46
46
|
min<A extends TotalOrder<A>>(this: Option<A>, that: Option<A>): Option<A>;
|
|
47
47
|
clamp<A extends TotalOrder<A>>(this: Option<A>, lower: Option<A>, upper: Option<A>): Option<A>;
|
|
48
48
|
values<A>(this: Option<A>): Generator<A, void, undefined>;
|
|
49
|
-
effectMap<A, B>(this: Option<A>, morphism: (value: A) => B): Generator<Option<A>, B, A>;
|
|
50
|
-
effect<A>(this: Option<A>): Generator<Option<A>, A, A>;
|
|
51
49
|
}
|
|
52
50
|
export declare class Some<out A> extends OptionTrait {
|
|
53
51
|
readonly value: A;
|
|
@@ -57,7 +55,6 @@ export declare class Some<out A> extends OptionTrait {
|
|
|
57
55
|
static of<A>(value: A): Some<A>;
|
|
58
56
|
static fromValid<A, B extends A>(value: A, validate: (value: A) => value is B): Option<B>;
|
|
59
57
|
static fromValid<A>(value: A, validate: (value: A) => boolean): Option<A>;
|
|
60
|
-
static fromGenerator<A>(getGenerator: () => Generator<Option<unknown>, A, unknown>): Option<A>;
|
|
61
58
|
}
|
|
62
59
|
export declare class None extends OptionTrait {
|
|
63
60
|
readonly isSome = false;
|
package/lib/option.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NoneException } from "./exceptions.js";
|
|
2
1
|
import { Pair } from "./pair.js";
|
|
3
2
|
import { Fail, Okay } from "./result.js";
|
|
4
3
|
class OptionTrait {
|
|
@@ -142,14 +141,6 @@ class OptionTrait {
|
|
|
142
141
|
if (this.isSome)
|
|
143
142
|
yield this.value;
|
|
144
143
|
}
|
|
145
|
-
*effectMap(morphism) {
|
|
146
|
-
const value = yield this;
|
|
147
|
-
return morphism(value);
|
|
148
|
-
}
|
|
149
|
-
*effect() {
|
|
150
|
-
const value = yield this;
|
|
151
|
-
return value;
|
|
152
|
-
}
|
|
153
144
|
}
|
|
154
145
|
export class Some extends OptionTrait {
|
|
155
146
|
value;
|
|
@@ -165,33 +156,6 @@ export class Some extends OptionTrait {
|
|
|
165
156
|
static fromValid(value, validate) {
|
|
166
157
|
return validate(value) ? new Some(value) : None.instance;
|
|
167
158
|
}
|
|
168
|
-
// TODO: <A, B>(getGenerator: () => Generator<Option<A>, B, A>) => Option<B>
|
|
169
|
-
static fromGenerator(getGenerator) {
|
|
170
|
-
const generator = getGenerator();
|
|
171
|
-
let result;
|
|
172
|
-
try {
|
|
173
|
-
result = generator.next();
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
if (error instanceof NoneException)
|
|
177
|
-
return None.instance;
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
180
|
-
while (!result.done) {
|
|
181
|
-
const option = result.value;
|
|
182
|
-
try {
|
|
183
|
-
result = option.isSome
|
|
184
|
-
? generator.next(option.value)
|
|
185
|
-
: generator.throw(new NoneException());
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
if (error instanceof NoneException)
|
|
189
|
-
return None.instance;
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return new Some(result.value);
|
|
194
|
-
}
|
|
195
159
|
}
|
|
196
160
|
export class None extends OptionTrait {
|
|
197
161
|
isSome = false;
|
package/lib/pair.d.ts
CHANGED
|
@@ -19,8 +19,12 @@ export declare class Pair<out A, out B> {
|
|
|
19
19
|
replaceFst<A, B, C>(this: Pair<A, C>, fst: B): Pair<B, C>;
|
|
20
20
|
replaceSnd<A, B, C>(this: Pair<A, B>, snd: C): Pair<A, C>;
|
|
21
21
|
and<A, B, C, D>(this: Pair<A, B>, that: Pair<C, D>): Pair<Pair<A, C>, Pair<B, D>>;
|
|
22
|
-
andFst<A, B, C
|
|
23
|
-
|
|
22
|
+
andFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, that: Pair<B, C>): Pair<Pair<A, B>, C>;
|
|
23
|
+
andThenFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, that: Pair<B, C>): Pair<B, C>;
|
|
24
|
+
andWhenFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, that: Pair<B, C>): Pair<A, C>;
|
|
25
|
+
andSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, that: Pair<A, C>): Pair<A, Pair<B, C>>;
|
|
26
|
+
andThenSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, that: Pair<A, C>): Pair<A, C>;
|
|
27
|
+
andWhenSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, that: Pair<A, C>): Pair<A, B>;
|
|
24
28
|
flatMapFst<A, B, C extends Semigroup<C>>(this: Pair<A, C>, arrow: (value: A) => Pair<B, C>): Pair<B, C>;
|
|
25
29
|
flatMapSnd<A extends Semigroup<A>, B, C>(this: Pair<A, B>, arrow: (value: B) => Pair<A, C>): Pair<A, C>;
|
|
26
30
|
flattenFst<A, B extends Semigroup<B>>(this: Pair<Pair<A, B>, B>): Pair<A, B>;
|
package/lib/pair.js
CHANGED
|
@@ -44,11 +44,23 @@ export class Pair {
|
|
|
44
44
|
and(that) {
|
|
45
45
|
return new Pair(new Pair(this.fst, that.fst), new Pair(this.snd, that.snd));
|
|
46
46
|
}
|
|
47
|
-
andFst(
|
|
48
|
-
return new Pair(new Pair(this.fst,
|
|
47
|
+
andFst(that) {
|
|
48
|
+
return new Pair(new Pair(this.fst, that.fst), this.snd.append(that.snd));
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
return new Pair(
|
|
50
|
+
andThenFst(that) {
|
|
51
|
+
return new Pair(that.fst, this.snd.append(that.snd));
|
|
52
|
+
}
|
|
53
|
+
andWhenFst(that) {
|
|
54
|
+
return new Pair(this.fst, this.snd.append(that.snd));
|
|
55
|
+
}
|
|
56
|
+
andSnd(that) {
|
|
57
|
+
return new Pair(this.fst.append(that.fst), new Pair(this.snd, that.snd));
|
|
58
|
+
}
|
|
59
|
+
andThenSnd(that) {
|
|
60
|
+
return new Pair(this.fst.append(that.fst), that.snd);
|
|
61
|
+
}
|
|
62
|
+
andWhenSnd(that) {
|
|
63
|
+
return new Pair(this.fst.append(that.fst), this.snd);
|
|
52
64
|
}
|
|
53
65
|
flatMapFst(arrow) {
|
|
54
66
|
return arrow(this.fst).mapSnd((snd) => this.snd.append(snd));
|
package/lib/result.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { PartialOrder, Setoid, TotalOrder } from "./order.js";
|
|
|
3
3
|
import type { Ordering } from "./ordering.js";
|
|
4
4
|
import { Pair } from "./pair.js";
|
|
5
5
|
export type Result<A, E> = Okay<A> | Fail<E>;
|
|
6
|
-
declare abstract class ResultTrait
|
|
6
|
+
declare abstract class ResultTrait {
|
|
7
7
|
abstract readonly isOkay: boolean;
|
|
8
8
|
abstract readonly isFail: boolean;
|
|
9
9
|
toString<A, E>(this: Result<A, E>): string;
|