@kaumlaut/pure 2.2.0 → 2.2.1

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.
@@ -86,8 +86,9 @@ export declare function maybeByErrorAwareGuard<T>(guard: ErrorAwareGuard.ErrorAw
86
86
  */
87
87
  export declare function mapToMaybe<T, R>(func: (value: T) => Maybe<R>): (maybe: Maybe<T>) => Maybe<R>;
88
88
  /**
89
- * Maps the a value contained within a Just using the given function without wrapping it in another Just.
90
- * Returns the given Maybe if it is a Nothing.
89
+ * Runs the given function with the contained value if maybe is Just<T>
90
+ * If an error occurs it returns Nothing.
91
+ * Otherwise it returns the mapped value inside a Just<R>.
91
92
  */
92
93
  export declare function tryMap<T, R>(func: (value: T) => R): (maybe: Maybe<T>) => Maybe<R>;
93
94
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/maybe/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAW,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,eAAe,MAAM,kCAAkC,CAAC;AACpE,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAEzC;;GAEG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAIjC;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAKzC;AAED;;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C,KAAK,CAAC,GACpB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAa/B;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EACxB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GACnB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAQvC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAEhE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,IACpD,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,cAOrC"}
@@ -3,6 +3,7 @@
3
3
  * @module maybe
4
4
  */
5
5
  import { err, ok } from "@kaumlaut/pure/result";
6
+ import * as Guard from "@kaumlaut/pure/guard";
6
7
  /**
7
8
  * Creates a maybe not containing a value. (Nothing)
8
9
  */
@@ -30,14 +31,14 @@ export function isNothing(maybe) {
30
31
  * A Guard confirming that the given maybe value is a Just.
31
32
  */
32
33
  export function isJust(maybe) {
33
- return maybe.type === "maybe-just";
34
+ return maybe.type === "maybe-just" && "value" in maybe;
34
35
  }
35
36
  /**
36
37
  * A Guard confirming that the given value is a Maybe.
37
38
  */
38
39
  export function isMaybe(value) {
39
- //@ts-expect-error is validated
40
- return value.type === "maybe-just" || value.type === "maybe-nothing";
40
+ return (Guard.isObjectWithKey("type")(value) &&
41
+ (value.type === "maybe-just" || value.type === "maybe-nothing"));
41
42
  }
42
43
  /**
43
44
  * Applies the func function to the value if the given Maybe is a Just and returns it wrapped in a Just. Otherwise returns the given Maybe.
@@ -116,17 +117,18 @@ export function mapToMaybe(func) {
116
117
  };
117
118
  }
118
119
  /**
119
- * Maps the a value contained within a Just using the given function without wrapping it in another Just.
120
- * Returns the given Maybe if it is a Nothing.
120
+ * Runs the given function with the contained value if maybe is Just<T>
121
+ * If an error occurs it returns Nothing.
122
+ * Otherwise it returns the mapped value inside a Just<R>.
121
123
  */
122
124
  export function tryMap(func) {
123
125
  return (maybe) => {
124
126
  if (isJust(maybe)) {
125
127
  try {
126
128
  return just(func(maybe.value));
129
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
130
  }
128
131
  catch (e) {
129
- console.error(e);
130
132
  return nothing();
131
133
  }
132
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaumlaut/pure",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Types and functions for a state runtime inspired by Elm and functional programming",
5
5
  "author": "Max Kaemmerer",
6
6
  "license": "MIT",