@terrygonguet/utils 0.0.4 → 0.0.5

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.
@@ -1,7 +1,7 @@
1
1
  var g = Object.defineProperty;
2
2
  var p = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
3
  var f = (t, e, r) => (p(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- const a = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", b = "@terrygonguet/utils/functional/maybe/None";
4
+ const a = "@terrygonguet/utils/functional/maybe", _ = "@terrygonguet/utils/functional/maybe/Some", h = "@terrygonguet/utils/functional/maybe/None";
5
5
  function i(t) {
6
6
  return Object.create(
7
7
  {
@@ -34,11 +34,11 @@ const n = Object.create(
34
34
  orDefault: $,
35
35
  map: () => n,
36
36
  flatMap: () => n,
37
- toJSON: () => ({ $_kind: a, $_variant: b })
37
+ toJSON: () => ({ $_kind: a, $_variant: h })
38
38
  },
39
39
  {
40
40
  $_kind: { value: a, enumerable: !1, writable: !1 },
41
- $_variant: { value: b, enumerable: !1, writable: !1 }
41
+ $_variant: { value: h, enumerable: !1, writable: !1 }
42
42
  }
43
43
  ), k = {
44
44
  Some: i,
@@ -55,16 +55,19 @@ const n = Object.create(
55
55
  JSONReviver(t, e) {
56
56
  if ((e == null ? void 0 : e.$_kind) == a) {
57
57
  const r = e == null ? void 0 : e.$_variant;
58
- return r == _ ? i(e == null ? void 0 : e.value) : r == b ? n : e;
58
+ return r == _ ? i(e == null ? void 0 : e.value) : r == h ? n : e;
59
59
  } else
60
60
  return e;
61
61
  }
62
- }, s = "@terrygonguet/utils/functional/result", u = "@terrygonguet/utils/functional/result/Success", m = "@terrygonguet/utils/functional/result/Failure";
62
+ }, s = "@terrygonguet/utils/functional/result", u = "@terrygonguet/utils/functional/result/Success", b = "@terrygonguet/utils/functional/result/Failure";
63
63
  function l(t) {
64
64
  return Object.create(
65
65
  {
66
66
  isSuccess: () => !0,
67
67
  isFailure: () => !1,
68
+ merge(e) {
69
+ return e(this.value);
70
+ },
68
71
  map(e) {
69
72
  return l(e(this.value));
70
73
  },
@@ -82,11 +85,14 @@ function l(t) {
82
85
  }
83
86
  );
84
87
  }
85
- function h(t) {
88
+ function m(t) {
86
89
  return Object.create(
87
90
  {
88
91
  isSuccess: () => !1,
89
92
  isFailure: () => !0,
93
+ merge(e, r) {
94
+ return r(this.reason);
95
+ },
90
96
  map() {
91
97
  return this;
92
98
  },
@@ -94,7 +100,7 @@ function h(t) {
94
100
  return this;
95
101
  },
96
102
  toJSON() {
97
- return { $_kind: s, $_variant: m, reason: this.reason };
103
+ return { $_kind: s, $_variant: b, reason: this.reason };
98
104
  }
99
105
  },
100
106
  {
@@ -106,14 +112,14 @@ function h(t) {
106
112
  }
107
113
  const F = {
108
114
  Success: l,
109
- Failure: h,
115
+ Failure: m,
110
116
  try(t) {
111
117
  return new S(t);
112
118
  },
113
119
  JSONReviver(t, e) {
114
120
  if ((e == null ? void 0 : e.$_kind) == s) {
115
121
  const r = e == null ? void 0 : e.$_variant;
116
- return r == u ? l(e == null ? void 0 : e.value) : r == m ? h(e == null ? void 0 : e.reason) : e;
122
+ return r == u ? l(e == null ? void 0 : e.value) : r == b ? m(e == null ? void 0 : e.reason) : e;
117
123
  } else
118
124
  return e;
119
125
  }
@@ -131,11 +137,11 @@ class S {
131
137
  try {
132
138
  return l(this.tryFn());
133
139
  } catch (e) {
134
- return h(this.catchFn(e));
140
+ return m(this.catchFn(e));
135
141
  }
136
142
  }
137
143
  }
138
- var N = d;
144
+ var v = d;
139
145
  function d(t, e) {
140
146
  if (!arguments.length)
141
147
  throw new Error(
@@ -152,13 +158,8 @@ function $(t) {
152
158
  return t;
153
159
  }
154
160
  export {
155
- h as Failure,
156
161
  k as Maybe,
157
- n as None,
158
162
  F as Result,
159
- i as Some,
160
- l as Success,
161
- S as TryCatch,
162
- N as compose,
163
+ v as compose,
163
164
  $ as identity
164
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrygonguet/utils",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -9,6 +9,7 @@
9
9
  "coverage": "vitest run --coverage"
10
10
  },
11
11
  "devDependencies": {
12
+ "@vitest/coverage-v8": "^0.32.0",
12
13
  "@vitest/ui": "^0.32.0",
13
14
  "prettier": "^2.8.8",
14
15
  "typescript": "^5.0.2",
@@ -17,7 +17,7 @@ const $_kind = "@terrygonguet/utils/functional/maybe"
17
17
  const $_variant_Some = "@terrygonguet/utils/functional/maybe/Some"
18
18
  const $_variant_None = "@terrygonguet/utils/functional/maybe/None"
19
19
 
20
- export function Some<T>(value: NonNullable<T>): Some<T> {
20
+ function Some<T>(value: NonNullable<T>): Some<T> {
21
21
  return Object.create(
22
22
  {
23
23
  isSome: () => true,
@@ -43,7 +43,7 @@ export function Some<T>(value: NonNullable<T>): Some<T> {
43
43
  )
44
44
  }
45
45
 
46
- export const None: None<any> = Object.create(
46
+ const None: None<any> = Object.create(
47
47
  {
48
48
  isSome: () => false,
49
49
  isNone: () => true,
@@ -3,6 +3,7 @@ import { identity } from "./index.ts"
3
3
  interface API<S, F> {
4
4
  isSuccess(this: Result<S, F>): this is Success<S, F>
5
5
  isFailure(this: Result<S, F>): this is Failure<S, F>
6
+ merge<T>(this: Result<S, F>, f: (value: S) => T, g: (reason: F) => T): T
6
7
  map<S2>(this: Result<S, F>, f: (value: S) => S2): Result<S2, F>
7
8
  flatMap<S2, F2>(this: Result<S, F>, f: (value: S) => Result<S2, F | F2>): Result<S2, F | F2>
8
9
  toJSON(this: Result<S, F>): Object
@@ -16,11 +17,14 @@ const $_kind = "@terrygonguet/utils/functional/result"
16
17
  const $_variant_Success = "@terrygonguet/utils/functional/result/Success"
17
18
  const $_variant_Failure = "@terrygonguet/utils/functional/result/Failure"
18
19
 
19
- export function Success<S, F>(value: S): Success<S, F> {
20
+ function Success<S, F>(value: S): Success<S, F> {
20
21
  return Object.create(
21
22
  {
22
23
  isSuccess: () => true,
23
24
  isFailure: () => false,
25
+ merge<T>(this: Success<S, F>, f: (value: S) => T) {
26
+ return f(this.value)
27
+ },
24
28
  map<S2>(this: Success<S, F>, f: (value: S) => S2) {
25
29
  return Success(f(this.value))
26
30
  },
@@ -39,11 +43,14 @@ export function Success<S, F>(value: S): Success<S, F> {
39
43
  )
40
44
  }
41
45
 
42
- export function Failure<S, F>(reason: F): Failure<S, F> {
46
+ function Failure<S, F>(reason: F): Failure<S, F> {
43
47
  return Object.create(
44
48
  {
45
49
  isSuccess: () => false,
46
50
  isFailure: () => true,
51
+ merge<T>(this: Failure<S, F>, _: (value: S) => T, g: (reason: F) => T) {
52
+ return g(this.reason)
53
+ },
47
54
  map<S2>(this: Failure<S, F>) {
48
55
  return this as unknown as Result<S2, F>
49
56
  },
@@ -78,7 +85,7 @@ export const Result = {
78
85
  },
79
86
  }
80
87
 
81
- export class TryCatch<S, F> {
88
+ class TryCatch<S, F> {
82
89
  tryFn: () => S
83
90
  catchFn: (err: unknown) => F
84
91
 
@@ -11,8 +11,7 @@ export type Some<T> = {
11
11
  } & API<T>;
12
12
  export type None<T> = API<T>;
13
13
  export type Maybe<T> = Some<T> | None<T>;
14
- export declare function Some<T>(value: NonNullable<T>): Some<T>;
15
- export declare const None: None<any>;
14
+ declare function Some<T>(value: NonNullable<T>): Some<T>;
16
15
  export declare const Maybe: {
17
16
  Some: typeof Some;
18
17
  None: None<any>;
@@ -1,6 +1,7 @@
1
1
  interface API<S, F> {
2
2
  isSuccess(this: Result<S, F>): this is Success<S, F>;
3
3
  isFailure(this: Result<S, F>): this is Failure<S, F>;
4
+ merge<T>(this: Result<S, F>, f: (value: S) => T, g: (reason: F) => T): T;
4
5
  map<S2>(this: Result<S, F>, f: (value: S) => S2): Result<S2, F>;
5
6
  flatMap<S2, F2>(this: Result<S, F>, f: (value: S) => Result<S2, F | F2>): Result<S2, F | F2>;
6
7
  toJSON(this: Result<S, F>): Object;
@@ -12,15 +13,15 @@ export type Failure<S, F> = {
12
13
  reason: F;
13
14
  } & API<S, F>;
14
15
  export type Result<S, F> = Success<S, F> | Failure<S, F>;
15
- export declare function Success<S, F>(value: S): Success<S, F>;
16
- export declare function Failure<S, F>(reason: F): Failure<S, F>;
16
+ declare function Success<S, F>(value: S): Success<S, F>;
17
+ declare function Failure<S, F>(reason: F): Failure<S, F>;
17
18
  export declare const Result: {
18
19
  Success: typeof Success;
19
20
  Failure: typeof Failure;
20
21
  try<S, F>(tryFn: () => S): TryCatch<S, F>;
21
22
  JSONReviver(_key: string, value: any): any;
22
23
  };
23
- export declare class TryCatch<S, F> {
24
+ declare class TryCatch<S, F> {
24
25
  tryFn: () => S;
25
26
  catchFn: (err: unknown) => F;
26
27
  constructor(tryFn: () => S);