aang 2.0.0-alpha.7 → 2.0.0-alpha.8

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/option.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Exception } from "./exceptions.js";
2
+ import type { Result } from "./result.js";
2
3
  export type Option<A> = Some<A> | None;
3
4
  declare abstract class OptionMethods {
4
5
  abstract readonly isSome: boolean;
@@ -8,6 +9,7 @@ declare abstract class OptionMethods {
8
9
  filter<A>(this: Option<A>, predicate: (value: A) => boolean): Option<A>;
9
10
  safeExtract<A>(this: Option<A>, getDefaultValue: () => A): A;
10
11
  unsafeExtract<A>(this: Option<A>, error: Exception | string): A;
12
+ toResult<E, A>(this: Option<A>, getError: () => E): Result<E, A>;
11
13
  }
12
14
  export declare class Some<out A> extends OptionMethods {
13
15
  readonly value: A;
package/lib/option.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { UnsafeExtractError } from "./errors.js";
2
2
  import { Exception } from "./exceptions.js";
3
+ import { Failure, Success } from "./result.js";
3
4
  class OptionMethods {
4
5
  map(morphism) {
5
6
  return this.isSome ? new Some(morphism(this.value)) : None.instance;
@@ -18,6 +19,9 @@ class OptionMethods {
18
19
  return this.value;
19
20
  throw error instanceof Exception ? error : new UnsafeExtractError(error);
20
21
  }
22
+ toResult(getError) {
23
+ return this.isSome ? new Success(this.value) : new Failure(getError());
24
+ }
21
25
  }
22
26
  export class Some extends OptionMethods {
23
27
  value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aang",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "A powerful functional programming library for TypeScript.",
5
5
  "keywords": [
6
6
  "aang",