aang 2.0.0-alpha.4 → 2.0.0-alpha.6
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 +1 -2
- package/lib/option.js +1 -4
- package/lib/result.d.ts +21 -0
- package/lib/result.js +25 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/option.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ declare abstract class OptionMethods {
|
|
|
6
6
|
map<A, B>(this: Option<A>, morphism: (value: A) => B): Option<B>;
|
|
7
7
|
flatMap<A, B>(this: Option<A>, arrow: (value: A) => Option<B>): Option<B>;
|
|
8
8
|
filter<A>(this: Option<A>, predicate: (value: A) => boolean): Option<A>;
|
|
9
|
-
safeExtract<A>(this: Option<A>,
|
|
10
|
-
safeExtractFrom<A>(this: Option<A>, getDefaultValue: () => A): A;
|
|
9
|
+
safeExtract<A>(this: Option<A>, getDefaultValue: () => A): A;
|
|
11
10
|
unsafeExtract<A>(this: Option<A>, error: Exception | string): A;
|
|
12
11
|
}
|
|
13
12
|
declare class Some<out A> extends OptionMethods {
|
package/lib/option.js
CHANGED
|
@@ -10,10 +10,7 @@ class OptionMethods {
|
|
|
10
10
|
filter(predicate) {
|
|
11
11
|
return this.isSome && predicate(this.value) ? this : none;
|
|
12
12
|
}
|
|
13
|
-
safeExtract(
|
|
14
|
-
return this.isSome ? this.value : defaultValue;
|
|
15
|
-
}
|
|
16
|
-
safeExtractFrom(getDefaultValue) {
|
|
13
|
+
safeExtract(getDefaultValue) {
|
|
17
14
|
return this.isSome ? this.value : getDefaultValue();
|
|
18
15
|
}
|
|
19
16
|
unsafeExtract(error) {
|
package/lib/result.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
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
|
+
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 declare const success: <A>(value: A) => Success<A>;
|
|
20
|
+
export declare const failure: <E>(error: E) => Failure<E>;
|
|
21
|
+
export type { Success, Failure };
|
package/lib/result.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class ResultMethods {
|
|
2
|
+
map(morphism) {
|
|
3
|
+
return this.isSuccess ? new Success(morphism(this.value)) : this;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
class Success extends ResultMethods {
|
|
7
|
+
value;
|
|
8
|
+
isSuccess = true;
|
|
9
|
+
isFailure = false;
|
|
10
|
+
constructor(value) {
|
|
11
|
+
super();
|
|
12
|
+
this.value = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class Failure extends ResultMethods {
|
|
16
|
+
error;
|
|
17
|
+
isSuccess = false;
|
|
18
|
+
isFailure = true;
|
|
19
|
+
constructor(error) {
|
|
20
|
+
super();
|
|
21
|
+
this.error = error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const success = (value) => new Success(value);
|
|
25
|
+
export const failure = (error) => new Failure(error);
|