aang 2.0.0-alpha.5 → 2.0.0-alpha.7
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/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/option.d.ts +5 -5
- package/lib/option.js +9 -7
- package/lib/result.d.ts +19 -0
- package/lib/result.js +23 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/option.d.ts
CHANGED
|
@@ -9,16 +9,16 @@ declare abstract class OptionMethods {
|
|
|
9
9
|
safeExtract<A>(this: Option<A>, getDefaultValue: () => A): A;
|
|
10
10
|
unsafeExtract<A>(this: Option<A>, error: Exception | string): A;
|
|
11
11
|
}
|
|
12
|
-
declare class Some<out A> extends OptionMethods {
|
|
12
|
+
export declare class Some<out A> extends OptionMethods {
|
|
13
13
|
readonly value: A;
|
|
14
14
|
readonly isSome = true;
|
|
15
15
|
readonly isNone = false;
|
|
16
16
|
constructor(value: A);
|
|
17
17
|
}
|
|
18
|
-
declare class None extends OptionMethods {
|
|
18
|
+
export declare class None extends OptionMethods {
|
|
19
19
|
readonly isSome = false;
|
|
20
20
|
readonly isNone = true;
|
|
21
|
+
private constructor();
|
|
22
|
+
static readonly instance: None;
|
|
21
23
|
}
|
|
22
|
-
export
|
|
23
|
-
export declare const none: None;
|
|
24
|
-
export type { Some, None };
|
|
24
|
+
export {};
|
package/lib/option.js
CHANGED
|
@@ -2,13 +2,13 @@ import { UnsafeExtractError } from "./errors.js";
|
|
|
2
2
|
import { Exception } from "./exceptions.js";
|
|
3
3
|
class OptionMethods {
|
|
4
4
|
map(morphism) {
|
|
5
|
-
return this.isSome ? new Some(morphism(this.value)) :
|
|
5
|
+
return this.isSome ? new Some(morphism(this.value)) : None.instance;
|
|
6
6
|
}
|
|
7
7
|
flatMap(arrow) {
|
|
8
|
-
return this.isSome ? arrow(this.value) :
|
|
8
|
+
return this.isSome ? arrow(this.value) : None.instance;
|
|
9
9
|
}
|
|
10
10
|
filter(predicate) {
|
|
11
|
-
return this.isSome && predicate(this.value) ? this :
|
|
11
|
+
return this.isSome && predicate(this.value) ? this : None.instance;
|
|
12
12
|
}
|
|
13
13
|
safeExtract(getDefaultValue) {
|
|
14
14
|
return this.isSome ? this.value : getDefaultValue();
|
|
@@ -19,7 +19,7 @@ class OptionMethods {
|
|
|
19
19
|
throw error instanceof Exception ? error : new UnsafeExtractError(error);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
class Some extends OptionMethods {
|
|
22
|
+
export class Some extends OptionMethods {
|
|
23
23
|
value;
|
|
24
24
|
isSome = true;
|
|
25
25
|
isNone = false;
|
|
@@ -28,9 +28,11 @@ class Some extends OptionMethods {
|
|
|
28
28
|
this.value = value;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
class None extends OptionMethods {
|
|
31
|
+
export class None extends OptionMethods {
|
|
32
32
|
isSome = false;
|
|
33
33
|
isNone = true;
|
|
34
|
+
constructor() {
|
|
35
|
+
super();
|
|
36
|
+
}
|
|
37
|
+
static instance = new None();
|
|
34
38
|
}
|
|
35
|
-
export const some = (value) => new Some(value);
|
|
36
|
-
export const none = new None();
|
package/lib/result.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type Result<E, A> = Success<A> | Failure<E>;
|
|
2
|
+
declare abstract class ResultMethods {
|
|
3
|
+
abstract readonly isSuccess: boolean;
|
|
4
|
+
abstract readonly isFailure: boolean;
|
|
5
|
+
map<E, A, B>(this: Result<E, A>, morphism: (value: A) => B): Result<E, B>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Success<out A> extends ResultMethods {
|
|
8
|
+
readonly value: A;
|
|
9
|
+
readonly isSuccess = true;
|
|
10
|
+
readonly isFailure = false;
|
|
11
|
+
constructor(value: A);
|
|
12
|
+
}
|
|
13
|
+
export declare class Failure<out E> extends ResultMethods {
|
|
14
|
+
readonly error: E;
|
|
15
|
+
readonly isSuccess = false;
|
|
16
|
+
readonly isFailure = true;
|
|
17
|
+
constructor(error: E);
|
|
18
|
+
}
|
|
19
|
+
export {};
|
package/lib/result.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class ResultMethods {
|
|
2
|
+
map(morphism) {
|
|
3
|
+
return this.isSuccess ? new Success(morphism(this.value)) : this;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export class Success extends ResultMethods {
|
|
7
|
+
value;
|
|
8
|
+
isSuccess = true;
|
|
9
|
+
isFailure = false;
|
|
10
|
+
constructor(value) {
|
|
11
|
+
super();
|
|
12
|
+
this.value = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class Failure extends ResultMethods {
|
|
16
|
+
error;
|
|
17
|
+
isSuccess = false;
|
|
18
|
+
isFailure = true;
|
|
19
|
+
constructor(error) {
|
|
20
|
+
super();
|
|
21
|
+
this.error = error;
|
|
22
|
+
}
|
|
23
|
+
}
|