aang 2.0.0-alpha.2 → 2.0.0-alpha.20

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 ADDED
@@ -0,0 +1,18 @@
1
+ import type { Option } from "./option.js";
2
+ import type { TotalOrder } from "./order.js";
3
+ import type { Ordering } from "./ordering.js";
4
+ export declare class Bool implements TotalOrder<Bool> {
5
+ readonly value: boolean;
6
+ constructor(value: boolean);
7
+ static of(value: boolean): Bool;
8
+ isSame(this: Bool, that: Bool): boolean;
9
+ isNotSame(this: Bool, that: Bool): boolean;
10
+ isLess(this: Bool, that: Bool): boolean;
11
+ isNotLess(this: Bool, that: Bool): boolean;
12
+ isMore(this: Bool, that: Bool): boolean;
13
+ isNotMore(this: Bool, that: Bool): boolean;
14
+ compare(this: Bool, that: Bool): Option<Ordering>;
15
+ max(this: Bool, that: Bool): Bool;
16
+ min(this: Bool, that: Bool): Bool;
17
+ clamp(this: Bool, lower: Bool, upper: Bool): Bool;
18
+ }
package/lib/bool.js ADDED
@@ -0,0 +1,44 @@
1
+ import { Some } from "./option.js";
2
+ export class Bool {
3
+ value;
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
7
+ static of(value) {
8
+ return new Bool(value);
9
+ }
10
+ isSame(that) {
11
+ return this.value === that.value;
12
+ }
13
+ isNotSame(that) {
14
+ return this.value !== that.value;
15
+ }
16
+ isLess(that) {
17
+ return this.value < that.value;
18
+ }
19
+ isNotLess(that) {
20
+ return this.value >= that.value;
21
+ }
22
+ isMore(that) {
23
+ return this.value > that.value;
24
+ }
25
+ isNotMore(that) {
26
+ return this.value <= that.value;
27
+ }
28
+ compare(that) {
29
+ if (this.value < that.value)
30
+ return new Some("<");
31
+ if (this.value > that.value)
32
+ return new Some(">");
33
+ return new Some("=");
34
+ }
35
+ max(that) {
36
+ return this.value >= that.value ? this : that;
37
+ }
38
+ min(that) {
39
+ return this.value <= that.value ? this : that;
40
+ }
41
+ clamp(lower, upper) {
42
+ return this.max(lower).min(upper);
43
+ }
44
+ }
@@ -0,0 +1,18 @@
1
+ import type { Option } from "./option.js";
2
+ import type { TotalOrder } from "./order.js";
3
+ import type { Ordering } from "./ordering.js";
4
+ export declare class DateTime implements TotalOrder<DateTime> {
5
+ readonly value: Date;
6
+ constructor(value: Date);
7
+ static of(value: Date): DateTime;
8
+ isSame(this: DateTime, that: DateTime): boolean;
9
+ isNotSame(this: DateTime, that: DateTime): boolean;
10
+ isLess(this: DateTime, that: DateTime): boolean;
11
+ isNotLess(this: DateTime, that: DateTime): boolean;
12
+ isMore(this: DateTime, that: DateTime): boolean;
13
+ isNotMore(this: DateTime, that: DateTime): boolean;
14
+ compare(this: DateTime, that: DateTime): Option<Ordering>;
15
+ max(this: DateTime, that: DateTime): DateTime;
16
+ min(this: DateTime, that: DateTime): DateTime;
17
+ clamp(this: DateTime, lower: DateTime, upper: DateTime): DateTime;
18
+ }
@@ -0,0 +1,54 @@
1
+ import { None, Some } from "./option.js";
2
+ export class DateTime {
3
+ value;
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
7
+ static of(value) {
8
+ return new DateTime(value);
9
+ }
10
+ isSame(that) {
11
+ return Object.is(this.value.getTime(), that.value.getTime());
12
+ }
13
+ isNotSame(that) {
14
+ return !this.isSame(that);
15
+ }
16
+ isLess(that) {
17
+ return this.value < that.value;
18
+ }
19
+ isNotLess(that) {
20
+ return this.value > that.value || this.isSame(that);
21
+ }
22
+ isMore(that) {
23
+ return this.value > that.value;
24
+ }
25
+ isNotMore(that) {
26
+ return this.value < that.value || this.isSame(that);
27
+ }
28
+ compare(that) {
29
+ if (this.isSame(that))
30
+ return new Some("=");
31
+ if (this.value < that.value)
32
+ return new Some("<");
33
+ if (this.value > that.value)
34
+ return new Some(">");
35
+ return None.instance;
36
+ }
37
+ max(that) {
38
+ if (Number.isNaN(this.value.getTime()))
39
+ return this;
40
+ if (Number.isNaN(that.value.getTime()))
41
+ return that;
42
+ return this.value >= that.value ? this : that;
43
+ }
44
+ min(that) {
45
+ if (Number.isNaN(this.value.getTime()))
46
+ return this;
47
+ if (Number.isNaN(that.value.getTime()))
48
+ return that;
49
+ return this.value <= that.value ? this : that;
50
+ }
51
+ clamp(lower, upper) {
52
+ return this.max(lower).min(upper);
53
+ }
54
+ }
@@ -0,0 +1,18 @@
1
+ import type { Option } from "./option.js";
2
+ import type { TotalOrder } from "./order.js";
3
+ import type { Ordering } from "./ordering.js";
4
+ export declare class Double implements TotalOrder<Double> {
5
+ readonly value: number;
6
+ constructor(value: number);
7
+ static of(value: number): Double;
8
+ isSame(this: Double, that: Double): boolean;
9
+ isNotSame(this: Double, that: Double): boolean;
10
+ isLess(this: Double, that: Double): boolean;
11
+ isNotLess(this: Double, that: Double): boolean;
12
+ isMore(this: Double, that: Double): boolean;
13
+ isNotMore(this: Double, that: Double): boolean;
14
+ compare(this: Double, that: Double): Option<Ordering>;
15
+ max(this: Double, that: Double): Double;
16
+ min(this: Double, that: Double): Double;
17
+ clamp(this: Double, lower: Double, upper: Double): Double;
18
+ }
package/lib/double.js ADDED
@@ -0,0 +1,46 @@
1
+ import { None, Some } from "./option.js";
2
+ export class Double {
3
+ value;
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
7
+ static of(value) {
8
+ return new Double(value);
9
+ }
10
+ isSame(that) {
11
+ return Object.is(this.value, that.value);
12
+ }
13
+ isNotSame(that) {
14
+ return !Object.is(this.value, that.value);
15
+ }
16
+ isLess(that) {
17
+ return this.value < that.value;
18
+ }
19
+ isNotLess(that) {
20
+ return this.value > that.value || Object.is(this.value, that.value);
21
+ }
22
+ isMore(that) {
23
+ return this.value > that.value;
24
+ }
25
+ isNotMore(that) {
26
+ return this.value < that.value || Object.is(this.value, that.value);
27
+ }
28
+ compare(that) {
29
+ if (Object.is(this.value, that.value))
30
+ return new Some("=");
31
+ if (this.value < that.value)
32
+ return new Some("<");
33
+ if (this.value > that.value)
34
+ return new Some(">");
35
+ return None.instance;
36
+ }
37
+ max(that) {
38
+ return new Double(Math.max(this.value, that.value));
39
+ }
40
+ min(that) {
41
+ return new Double(Math.min(this.value, that.value));
42
+ }
43
+ clamp(lower, upper) {
44
+ return this.max(lower).min(upper);
45
+ }
46
+ }
package/lib/index.d.ts CHANGED
@@ -1,2 +1,12 @@
1
+ export * from "./bool.js";
2
+ export * from "./datetime.js";
3
+ export * from "./double.js";
1
4
  export * from "./exceptions.js";
5
+ export * from "./integer.js";
6
+ export * from "./miscellaneous.js";
2
7
  export * from "./option.js";
8
+ export * from "./order.js";
9
+ export * from "./ordering.js";
10
+ export * from "./pair.js";
11
+ export * from "./result.js";
12
+ export * from "./text.js";
package/lib/index.js CHANGED
@@ -1,2 +1,12 @@
1
+ export * from "./bool.js";
2
+ export * from "./datetime.js";
3
+ export * from "./double.js";
1
4
  export * from "./exceptions.js";
5
+ export * from "./integer.js";
6
+ export * from "./miscellaneous.js";
2
7
  export * from "./option.js";
8
+ export * from "./order.js";
9
+ export * from "./ordering.js";
10
+ export * from "./pair.js";
11
+ export * from "./result.js";
12
+ export * from "./text.js";
@@ -0,0 +1,18 @@
1
+ import type { Option } from "./option.js";
2
+ import type { TotalOrder } from "./order.js";
3
+ import type { Ordering } from "./ordering.js";
4
+ export declare class Integer implements TotalOrder<Integer> {
5
+ readonly value: bigint;
6
+ constructor(value: bigint);
7
+ static of(value: bigint): Integer;
8
+ isSame(this: Integer, that: Integer): boolean;
9
+ isNotSame(this: Integer, that: Integer): boolean;
10
+ isLess(this: Integer, that: Integer): boolean;
11
+ isNotLess(this: Integer, that: Integer): boolean;
12
+ isMore(this: Integer, that: Integer): boolean;
13
+ isNotMore(this: Integer, that: Integer): boolean;
14
+ compare(this: Integer, that: Integer): Option<Ordering>;
15
+ max(this: Integer, that: Integer): Integer;
16
+ min(this: Integer, that: Integer): Integer;
17
+ clamp(this: Integer, lower: Integer, upper: Integer): Integer;
18
+ }
package/lib/integer.js ADDED
@@ -0,0 +1,44 @@
1
+ import { Some } from "./option.js";
2
+ export class Integer {
3
+ value;
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
7
+ static of(value) {
8
+ return new Integer(value);
9
+ }
10
+ isSame(that) {
11
+ return this.value === that.value;
12
+ }
13
+ isNotSame(that) {
14
+ return this.value !== that.value;
15
+ }
16
+ isLess(that) {
17
+ return this.value < that.value;
18
+ }
19
+ isNotLess(that) {
20
+ return this.value >= that.value;
21
+ }
22
+ isMore(that) {
23
+ return this.value > that.value;
24
+ }
25
+ isNotMore(that) {
26
+ return this.value <= that.value;
27
+ }
28
+ compare(that) {
29
+ if (this.value < that.value)
30
+ return new Some("<");
31
+ if (this.value > that.value)
32
+ return new Some(">");
33
+ return new Some("=");
34
+ }
35
+ max(that) {
36
+ return this.value >= that.value ? this : that;
37
+ }
38
+ min(that) {
39
+ return this.value <= that.value ? this : that;
40
+ }
41
+ clamp(lower, upper) {
42
+ return this.max(lower).min(upper);
43
+ }
44
+ }
@@ -0,0 +1 @@
1
+ export declare const id: <A>(value: A) => A;
@@ -0,0 +1 @@
1
+ export const id = (value) => value;
package/lib/option.d.ts CHANGED
@@ -1,21 +1,60 @@
1
1
  import { Exception } from "./exceptions.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 type { Result } from "./result.js";
2
6
  export type Option<A> = Some<A> | None;
3
- declare abstract class OptionMethods {
7
+ declare abstract class OptionTrait implements TotalOrder<Option<never>> {
4
8
  abstract readonly isSome: boolean;
5
9
  abstract readonly isNone: boolean;
10
+ toString<A>(this: Option<A>): string;
6
11
  map<A, B>(this: Option<A>, morphism: (value: A) => B): Option<B>;
12
+ replace<A, B>(this: Option<A>, value: B): Option<B>;
13
+ and<A, B>(this: Option<A>, that: Option<B>): Option<Pair<A, B>>;
14
+ andThen<A, B>(this: Option<A>, that: Option<B>): Option<B>;
15
+ andWith<A, B>(this: Option<A>, that: Option<B>): Option<A>;
16
+ or<A>(this: Option<A>, that: Option<A>): Option<A>;
17
+ flatMap<A, B>(this: Option<A>, arrow: (value: A) => Option<B>): Option<B>;
18
+ flatten<A>(this: Option<Option<A>>): Option<A>;
19
+ filter<A, B extends A>(this: Option<A>, predicate: (value: A) => value is B): Option<B>;
20
+ filter<A>(this: Option<A>, predicate: (value: A) => boolean): Option<A>;
21
+ isSomeAnd<A, B extends A>(this: Option<A>, predicate: (value: A) => value is B): this is Option<B>;
22
+ isSomeAnd<A>(this: Option<A>, predicate: (value: A) => boolean): boolean;
23
+ isNoneOr<A, B extends A>(this: Option<A>, predicate: (value: A) => value is B): this is Option<B>;
24
+ isNoneOr<A>(this: Option<A>, predicate: (value: A) => boolean): boolean;
25
+ unzipWith<A, B, C>(this: Option<A>, unzip: (value: A) => Pair<B, C>): Pair<Option<B>, Option<C>>;
26
+ unzip<A, B>(this: Option<Pair<A, B>>): Pair<Option<A>, Option<B>>;
27
+ transposeMap<A, E, B>(this: Option<A>, transpose: (value: A) => Result<E, B>): Result<E, Option<B>>;
28
+ transpose<E, A>(this: Option<Result<E, A>>): Result<E, Option<A>>;
29
+ safeExtract<A>(this: Option<A>, defaultValue: A): A;
7
30
  unsafeExtract<A>(this: Option<A>, error: Exception | string): A;
31
+ toResult<E, A>(this: Option<A>, defaultValue: E): Result<E, A>;
32
+ isSame<A extends Setoid<A>>(this: Option<A>, that: Option<A>): boolean;
33
+ isNotSame<A extends Setoid<A>>(this: Option<A>, that: Option<A>): boolean;
34
+ isLess<A extends PartialOrder<A>>(this: Option<A>, that: Option<A>): boolean;
35
+ isNotLess<A extends PartialOrder<A>>(this: Option<A>, that: Option<A>): boolean;
36
+ isMore<A extends PartialOrder<A>>(this: Option<A>, that: Option<A>): boolean;
37
+ isNotMore<A extends PartialOrder<A>>(this: Option<A>, that: Option<A>): boolean;
38
+ compare<A extends PartialOrder<A>>(this: Option<A>, that: Option<A>): Option<Ordering>;
39
+ max<A extends TotalOrder<A>>(this: Option<A>, that: Option<A>): Option<A>;
40
+ min<A extends TotalOrder<A>>(this: Option<A>, that: Option<A>): Option<A>;
41
+ clamp<A extends TotalOrder<A>>(this: Option<A>, lower: Option<A>, upper: Option<A>): Option<A>;
42
+ [Symbol.iterator]<A>(this: Option<A>): Generator<A, void, undefined>;
8
43
  }
9
- declare class Some<out A> extends OptionMethods {
44
+ export declare class Some<out A> extends OptionTrait {
10
45
  readonly value: A;
11
46
  readonly isSome = true;
12
47
  readonly isNone = false;
13
48
  constructor(value: A);
49
+ static of<A>(value: A): Some<A>;
14
50
  }
15
- declare class None extends OptionMethods {
51
+ export declare class None extends OptionTrait {
16
52
  readonly isSome = false;
17
53
  readonly isNone = true;
54
+ static readonly instance: None;
18
55
  }
19
- export declare const some: <A>(value: A) => Some<A>;
20
- export declare const none: None;
21
- export type { Some, None };
56
+ export declare const fromNullable: <A>(value: A) => Option<NonNullable<A>>;
57
+ export declare const fromFalsy: <A>(value: A) => Option<NonNullable<A>>;
58
+ export declare function fromValue<A, B extends A>(value: A, predicate: (value: A) => value is B): Option<B>;
59
+ export declare function fromValue<A>(value: A, predicate: (value: A) => boolean): Option<A>;
60
+ export {};
package/lib/option.js CHANGED
@@ -1,16 +1,125 @@
1
1
  import { UnsafeExtractError } from "./errors.js";
2
2
  import { Exception } from "./exceptions.js";
3
- class OptionMethods {
3
+ import { Pair } from "./pair.js";
4
+ import { Fail, Okay } from "./result.js";
5
+ class OptionTrait {
6
+ toString() {
7
+ return this.isSome ? `Some(${String(this.value)})` : "None";
8
+ }
4
9
  map(morphism) {
5
- return this.isSome ? new Some(morphism(this.value)) : none;
10
+ return this.isSome ? new Some(morphism(this.value)) : None.instance;
11
+ }
12
+ replace(value) {
13
+ return this.isSome ? new Some(value) : None.instance;
14
+ }
15
+ and(that) {
16
+ return this.isSome && that.isSome
17
+ ? new Some(new Pair(this.value, that.value))
18
+ : None.instance;
19
+ }
20
+ andThen(that) {
21
+ return this.isSome && that.isSome ? that : None.instance;
22
+ }
23
+ andWith(that) {
24
+ return this.isSome && that.isSome ? this : None.instance;
25
+ }
26
+ or(that) {
27
+ return this.isSome ? this : that;
28
+ }
29
+ flatMap(arrow) {
30
+ return this.isSome ? arrow(this.value) : None.instance;
31
+ }
32
+ flatten() {
33
+ return this.isSome ? this.value : None.instance;
34
+ }
35
+ filter(predicate) {
36
+ return this.isSome && predicate(this.value) ? this : None.instance;
37
+ }
38
+ isSomeAnd(predicate) {
39
+ return this.isSome && predicate(this.value);
40
+ }
41
+ isNoneOr(predicate) {
42
+ return this.isNone || predicate(this.value);
43
+ }
44
+ unzipWith(unzip) {
45
+ return this.isNone
46
+ ? Pair.of(None.instance)
47
+ : unzip(this.value).map(Some.of, Some.of);
48
+ }
49
+ unzip() {
50
+ return this.isNone
51
+ ? Pair.of(None.instance)
52
+ : this.value.map(Some.of, Some.of);
53
+ }
54
+ transposeMap(transpose) {
55
+ return this.isNone
56
+ ? new Okay(None.instance)
57
+ : transpose(this.value).mapOkay(Some.of);
58
+ }
59
+ transpose() {
60
+ return this.isNone ? new Okay(None.instance) : this.value.mapOkay(Some.of);
61
+ }
62
+ safeExtract(defaultValue) {
63
+ return this.isSome ? this.value : defaultValue;
6
64
  }
7
65
  unsafeExtract(error) {
8
66
  if (this.isSome)
9
67
  return this.value;
10
68
  throw error instanceof Exception ? error : new UnsafeExtractError(error);
11
69
  }
70
+ toResult(defaultValue) {
71
+ return this.isSome ? new Okay(this.value) : new Fail(defaultValue);
72
+ }
73
+ isSame(that) {
74
+ return this.isSome
75
+ ? that.isSome && this.value.isSame(that.value)
76
+ : that.isNone;
77
+ }
78
+ isNotSame(that) {
79
+ return this.isSome
80
+ ? that.isNone || this.value.isNotSame(that.value)
81
+ : that.isSome;
82
+ }
83
+ isLess(that) {
84
+ return that.isSome && (this.isNone || this.value.isLess(that.value));
85
+ }
86
+ isNotLess(that) {
87
+ return that.isNone || (this.isSome && this.value.isNotLess(that.value));
88
+ }
89
+ isMore(that) {
90
+ return this.isSome && (that.isNone || this.value.isMore(that.value));
91
+ }
92
+ isNotMore(that) {
93
+ return this.isNone || (that.isSome && this.value.isNotMore(that.value));
94
+ }
95
+ compare(that) {
96
+ if (this.isNone)
97
+ return new Some(that.isSome ? "<" : "=");
98
+ if (that.isNone)
99
+ return new Some(">");
100
+ return this.value.compare(that.value);
101
+ }
102
+ max(that) {
103
+ if (this.isNone)
104
+ return that;
105
+ if (that.isNone)
106
+ return this;
107
+ return new Some(this.value.max(that.value));
108
+ }
109
+ min(that) {
110
+ if (this.isNone || that.isNone)
111
+ return None.instance;
112
+ return new Some(this.value.min(that.value));
113
+ }
114
+ clamp(lower, upper) {
115
+ return this.max(lower).min(upper);
116
+ }
117
+ *[Symbol.iterator]() {
118
+ if (this.isSome)
119
+ yield this.value;
120
+ }
12
121
  }
13
- class Some extends OptionMethods {
122
+ export class Some extends OptionTrait {
14
123
  value;
15
124
  isSome = true;
16
125
  isNone = false;
@@ -18,10 +127,17 @@ class Some extends OptionMethods {
18
127
  super();
19
128
  this.value = value;
20
129
  }
130
+ static of(value) {
131
+ return new Some(value);
132
+ }
21
133
  }
22
- class None extends OptionMethods {
134
+ export class None extends OptionTrait {
23
135
  isSome = false;
24
136
  isNone = true;
137
+ static instance = new None();
138
+ }
139
+ export const fromNullable = (value) => value == null ? None.instance : new Some(value);
140
+ export const fromFalsy = (value) => value ? new Some(value) : None.instance;
141
+ export function fromValue(value, predicate) {
142
+ return predicate(value) ? new Some(value) : None.instance;
25
143
  }
26
- export const some = (value) => new Some(value);
27
- export const none = new None();
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 "<" | "=";
@@ -0,0 +1,6 @@
1
+ export const isSame = (x) => x === "=";
2
+ export const isNotSame = (x) => x !== "=";
3
+ export const isLess = (x) => x === "<";
4
+ export const isNotLess = (x) => x !== "<";
5
+ export const isMore = (x) => x === ">";
6
+ export const isNotMore = (x) => x !== ">";
package/lib/pair.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare class Pair<out A, out B> {
2
+ readonly fst: A;
3
+ readonly snd: B;
4
+ constructor(fst: A, snd: B);
5
+ static of<A>(value: A): Pair<A, A>;
6
+ map<A, B, C, D>(this: Pair<A, B>, fstMorphism: (fst: A) => C, sndMorphism: (snd: B) => D): Pair<C, D>;
7
+ associateLeft<A, B, C>(this: Pair<A, Pair<B, C>>): Pair<Pair<A, B>, C>;
8
+ associateRight<A, B, C>(this: Pair<Pair<A, B>, C>): Pair<A, Pair<B, C>>;
9
+ }
package/lib/pair.js ADDED
@@ -0,0 +1,20 @@
1
+ export class Pair {
2
+ fst;
3
+ snd;
4
+ constructor(fst, snd) {
5
+ this.fst = fst;
6
+ this.snd = snd;
7
+ }
8
+ static of(value) {
9
+ return new Pair(value, value);
10
+ }
11
+ map(fstMorphism, sndMorphism) {
12
+ return new Pair(fstMorphism(this.fst), sndMorphism(this.snd));
13
+ }
14
+ associateLeft() {
15
+ return new Pair(new Pair(this.fst, this.snd.fst), this.snd.snd);
16
+ }
17
+ associateRight() {
18
+ return new Pair(this.fst.fst, new Pair(this.fst.snd, this.snd));
19
+ }
20
+ }
@@ -0,0 +1,22 @@
1
+ export type Result<E, A> = Okay<A> | Fail<E>;
2
+ declare abstract class ResultTrait {
3
+ abstract readonly isOkay: boolean;
4
+ abstract readonly isFail: boolean;
5
+ mapOkay<E, A, B>(this: Result<E, A>, morphism: (value: A) => B): Result<E, B>;
6
+ mapFail<E, F, A>(this: Result<E, A>, morphism: (value: E) => F): Result<F, A>;
7
+ }
8
+ export declare class Okay<out A> extends ResultTrait {
9
+ readonly value: A;
10
+ readonly isOkay = true;
11
+ readonly isFail = false;
12
+ constructor(value: A);
13
+ static of<A>(value: A): Okay<A>;
14
+ }
15
+ export declare class Fail<out E> extends ResultTrait {
16
+ readonly value: E;
17
+ readonly isOkay = false;
18
+ readonly isFail = true;
19
+ constructor(value: E);
20
+ static of<E>(value: E): Fail<E>;
21
+ }
22
+ export {};
package/lib/result.js ADDED
@@ -0,0 +1,32 @@
1
+ class ResultTrait {
2
+ mapOkay(morphism) {
3
+ return this.isOkay ? new Okay(morphism(this.value)) : this;
4
+ }
5
+ mapFail(morphism) {
6
+ return this.isFail ? new Fail(morphism(this.value)) : this;
7
+ }
8
+ }
9
+ export class Okay extends ResultTrait {
10
+ value;
11
+ isOkay = true;
12
+ isFail = false;
13
+ constructor(value) {
14
+ super();
15
+ this.value = value;
16
+ }
17
+ static of(value) {
18
+ return new Okay(value);
19
+ }
20
+ }
21
+ export class Fail extends ResultTrait {
22
+ value;
23
+ isOkay = false;
24
+ isFail = true;
25
+ constructor(value) {
26
+ super();
27
+ this.value = value;
28
+ }
29
+ static of(value) {
30
+ return new Fail(value);
31
+ }
32
+ }
package/lib/text.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Option } from "./option.js";
2
+ import type { TotalOrder } from "./order.js";
3
+ import type { Ordering } from "./ordering.js";
4
+ export declare class Text implements TotalOrder<Text> {
5
+ readonly value: string;
6
+ constructor(value: string);
7
+ static of(value: string): Text;
8
+ isSame(this: Text, that: Text): boolean;
9
+ isNotSame(this: Text, that: Text): boolean;
10
+ isLess(this: Text, that: Text): boolean;
11
+ isNotLess(this: Text, that: Text): boolean;
12
+ isMore(this: Text, that: Text): boolean;
13
+ isNotMore(this: Text, that: Text): boolean;
14
+ compare(this: Text, that: Text): Option<Ordering>;
15
+ max(this: Text, that: Text): Text;
16
+ min(this: Text, that: Text): Text;
17
+ clamp(this: Text, lower: Text, upper: Text): Text;
18
+ }
package/lib/text.js ADDED
@@ -0,0 +1,44 @@
1
+ import { Some } from "./option.js";
2
+ export class Text {
3
+ value;
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
7
+ static of(value) {
8
+ return new Text(value);
9
+ }
10
+ isSame(that) {
11
+ return this.value === that.value;
12
+ }
13
+ isNotSame(that) {
14
+ return this.value !== that.value;
15
+ }
16
+ isLess(that) {
17
+ return this.value < that.value;
18
+ }
19
+ isNotLess(that) {
20
+ return this.value >= that.value;
21
+ }
22
+ isMore(that) {
23
+ return this.value > that.value;
24
+ }
25
+ isNotMore(that) {
26
+ return this.value <= that.value;
27
+ }
28
+ compare(that) {
29
+ if (this.value < that.value)
30
+ return new Some("<");
31
+ if (this.value > that.value)
32
+ return new Some(">");
33
+ return new Some("=");
34
+ }
35
+ max(that) {
36
+ return this.value >= that.value ? this : that;
37
+ }
38
+ min(that) {
39
+ return this.value <= that.value ? this : that;
40
+ }
41
+ clamp(lower, upper) {
42
+ return this.max(lower).min(upper);
43
+ }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aang",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.20",
4
4
  "description": "A powerful functional programming library for TypeScript.",
5
5
  "keywords": [
6
6
  "aang",