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.
@@ -5,6 +5,3 @@ export declare abstract class Exception extends Error {
5
5
  constructor(message?: string, options?: ErrorOptions);
6
6
  protected setName(name: string): void;
7
7
  }
8
- export declare class NoneException extends Exception {
9
- constructor();
10
- }
package/lib/exceptions.js CHANGED
@@ -15,9 +15,3 @@ export class Exception extends Error {
15
15
  });
16
16
  }
17
17
  }
18
- export class NoneException extends Exception {
19
- constructor() {
20
- super();
21
- this.setName("NoneException");
22
- }
23
- }
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 implements Semigroup<Option<never>>, TotalOrder<Option<never>> {
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>(this: Pair<A, C>, snd: B): Pair<Pair<A, B>, C>;
23
- andSnd<A, B, C>(this: Pair<A, B>, snd: C): Pair<A, Pair<B, C>>;
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(snd) {
48
- return new Pair(new Pair(this.fst, snd), this.snd);
47
+ andFst(that) {
48
+ return new Pair(new Pair(this.fst, that.fst), this.snd.append(that.snd));
49
49
  }
50
- andSnd(snd) {
51
- return new Pair(this.fst, new Pair(this.snd, snd));
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 implements TotalOrder<Result<never, never>> {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aang",
3
- "version": "2.0.0-alpha.26",
3
+ "version": "2.0.0-alpha.28",
4
4
  "description": "A powerful functional programming library for TypeScript.",
5
5
  "keywords": [
6
6
  "aang",