@fncts/base 0.0.29 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. package/_cjs/collection/immutable/HashSet/api.cjs +18 -7
  2. package/_cjs/collection/immutable/HashSet/api.cjs.map +1 -1
  3. package/_cjs/collection/immutable/HashSet/definition.cjs +2 -2
  4. package/_cjs/collection/immutable/HashSet/definition.cjs.map +1 -1
  5. package/_cjs/control/Eval/api.cjs +4 -1
  6. package/_cjs/control/Eval/api.cjs.map +1 -1
  7. package/_cjs/control/Eval/constructors.cjs +9 -2
  8. package/_cjs/control/Eval/constructors.cjs.map +1 -1
  9. package/_cjs/control/Eval/definition.cjs +10 -28
  10. package/_cjs/control/Eval/definition.cjs.map +1 -1
  11. package/_cjs/control/Eval/run.cjs +7 -7
  12. package/_cjs/control/Eval/run.cjs.map +1 -1
  13. package/_cjs/control/{Z → Pure}/api.cjs +146 -115
  14. package/_cjs/control/Pure/api.cjs.map +1 -0
  15. package/_cjs/control/Pure/definition.cjs +78 -0
  16. package/_cjs/control/Pure/definition.cjs.map +1 -0
  17. package/_cjs/control/{Z → Pure}/instances.cjs +1 -1
  18. package/_cjs/control/Pure/instances.cjs.map +1 -0
  19. package/_cjs/control/{Z → Pure}/runtime.cjs +67 -66
  20. package/_cjs/control/Pure/runtime.cjs.map +1 -0
  21. package/_cjs/control/{Z.cjs → Pure.cjs} +5 -5
  22. package/_cjs/control/Pure.cjs.map +1 -0
  23. package/_cjs/data/Date/definition.cjs +6 -0
  24. package/_cjs/data/Date/definition.cjs.map +1 -0
  25. package/_cjs/data/Date.cjs +17 -0
  26. package/_cjs/data/Date.cjs.map +1 -0
  27. package/_cjs/data/Showable/show.cjs +31 -31
  28. package/_cjs/data/Showable/show.cjs.map +1 -1
  29. package/_mjs/collection/immutable/HashSet/api.mjs +17 -7
  30. package/_mjs/collection/immutable/HashSet/api.mjs.map +1 -1
  31. package/_mjs/collection/immutable/HashSet/definition.mjs +2 -2
  32. package/_mjs/collection/immutable/HashSet/definition.mjs.map +1 -1
  33. package/_mjs/control/Eval/api.mjs +5 -2
  34. package/_mjs/control/Eval/api.mjs.map +1 -1
  35. package/_mjs/control/Eval/constructors.mjs +10 -3
  36. package/_mjs/control/Eval/constructors.mjs.map +1 -1
  37. package/_mjs/control/Eval/definition.mjs +7 -25
  38. package/_mjs/control/Eval/definition.mjs.map +1 -1
  39. package/_mjs/control/Eval/run.mjs +7 -7
  40. package/_mjs/control/Eval/run.mjs.map +1 -1
  41. package/_mjs/control/{Z → Pure}/api.mjs +134 -104
  42. package/_mjs/control/Pure/api.mjs.map +1 -0
  43. package/_mjs/control/Pure/definition.mjs +60 -0
  44. package/_mjs/control/Pure/definition.mjs.map +1 -0
  45. package/_mjs/control/{Z → Pure}/instances.mjs +1 -1
  46. package/_mjs/control/Pure/instances.mjs.map +1 -0
  47. package/_mjs/control/{Z → Pure}/runtime.mjs +68 -67
  48. package/_mjs/control/Pure/runtime.mjs.map +1 -0
  49. package/_mjs/control/Pure.mjs +6 -0
  50. package/_mjs/control/Pure.mjs.map +1 -0
  51. package/_mjs/data/Date/definition.mjs +2 -0
  52. package/_mjs/data/Date/definition.mjs.map +1 -0
  53. package/_mjs/data/Date.mjs +3 -0
  54. package/_mjs/data/Date.mjs.map +1 -0
  55. package/_mjs/data/Showable/show.mjs +31 -31
  56. package/_mjs/data/Showable/show.mjs.map +1 -1
  57. package/_src/collection/immutable/HashSet/api.ts +12 -1
  58. package/_src/collection/immutable/HashSet/definition.ts +2 -2
  59. package/_src/control/Eval/api.ts +5 -2
  60. package/_src/control/Eval/constructors.ts +10 -3
  61. package/_src/control/Eval/definition.ts +39 -27
  62. package/_src/control/Eval/run.ts +7 -7
  63. package/_src/control/Pure/api.ts +629 -0
  64. package/_src/control/Pure/definition.ts +222 -0
  65. package/_src/control/{Z → Pure}/instances.ts +3 -3
  66. package/_src/control/{Z → Pure}/runtime.ts +73 -76
  67. package/_src/control/Pure.ts +6 -0
  68. package/_src/control.ts +1 -1
  69. package/_src/data/Date/definition.ts +6 -0
  70. package/_src/data/Date.ts +3 -0
  71. package/_src/data/Showable/show.ts +55 -53
  72. package/_src/data.ts +1 -0
  73. package/_src/global.ts +1 -1
  74. package/collection/immutable/HashSet/api.d.ts +5 -0
  75. package/collection/immutable/HashSet/definition.d.ts +1 -1
  76. package/control/Eval/constructors.d.ts +4 -0
  77. package/control/Eval/definition.d.ts +25 -28
  78. package/control/Pure/api.d.ts +345 -0
  79. package/control/Pure/definition.d.ts +156 -0
  80. package/control/Pure/instances.d.ts +8 -0
  81. package/control/Pure/runtime.d.ts +56 -0
  82. package/control/Pure.d.ts +4 -0
  83. package/control.d.ts +1 -1
  84. package/data/Date/definition.d.ts +9 -0
  85. package/data/Date.d.ts +1 -0
  86. package/data/Showable/show.d.ts +2 -2
  87. package/data.d.ts +1 -0
  88. package/global.d.ts +1 -1
  89. package/package.json +1 -1
  90. package/_cjs/control/Z/api.cjs.map +0 -1
  91. package/_cjs/control/Z/definition.cjs +0 -163
  92. package/_cjs/control/Z/definition.cjs.map +0 -1
  93. package/_cjs/control/Z/instances.cjs.map +0 -1
  94. package/_cjs/control/Z/runtime.cjs.map +0 -1
  95. package/_cjs/control/Z.cjs.map +0 -1
  96. package/_mjs/control/Z/api.mjs.map +0 -1
  97. package/_mjs/control/Z/definition.mjs +0 -145
  98. package/_mjs/control/Z/definition.mjs.map +0 -1
  99. package/_mjs/control/Z/instances.mjs.map +0 -1
  100. package/_mjs/control/Z/runtime.mjs.map +0 -1
  101. package/_mjs/control/Z.mjs +0 -6
  102. package/_mjs/control/Z.mjs.map +0 -1
  103. package/_src/control/Z/api.ts +0 -590
  104. package/_src/control/Z/definition.ts +0 -199
  105. package/_src/control/Z.ts +0 -6
  106. package/control/Z/api.d.ts +0 -345
  107. package/control/Z/definition.d.ts +0 -151
  108. package/control/Z/instances.d.ts +0 -8
  109. package/control/Z/runtime.d.ts +0 -56
  110. package/control/Z.d.ts +0 -4
@@ -0,0 +1,222 @@
1
+ export interface PureF extends HKT {
2
+ type: Pure<this["W"], this["S"], this["S"], this["R"], this["E"], this["A"]>;
3
+ variance: {
4
+ W: "+";
5
+ S: "_";
6
+ R: "-";
7
+ E: "+";
8
+ A: "+";
9
+ };
10
+ }
11
+
12
+ export const PureVariance = Symbol.for("fncts.Pure.Variance");
13
+ export type PureVariance = typeof PureVariance;
14
+
15
+ export const PureTypeId = Symbol.for("fncts.Pure");
16
+ export type PureTypeId = typeof PureTypeId;
17
+
18
+ /**
19
+ * `Pure<W, S1, S2, R, E, A>` is a purely functional description of a synchronous computation
20
+ * that requires an environment `R` and an initial state `S1` and may either
21
+ * fail with an `E` or succeed with an updated state `S2` and an `A`. Because
22
+ * of its polymorphism `Z` can be used to model a variety of effects
23
+ * including context, state, failure, and logging.
24
+ *
25
+ * @tsplus type fncts.control.Pure
26
+ * @tsplus companion fncts.control.PureOps
27
+ */
28
+ export abstract class Pure<W, S1, S2, R, E, A> {
29
+ readonly [PureTypeId]: PureTypeId = PureTypeId;
30
+ declare [PureVariance]: {
31
+ readonly _W: (_: never) => W;
32
+ readonly _S1: (_: S1) => void;
33
+ readonly _S2: (_: never) => S2;
34
+ readonly _R: (_: never) => R;
35
+ readonly _E: (_: never) => E;
36
+ readonly _A: (_: never) => A;
37
+ };
38
+ }
39
+
40
+ /**
41
+ * @tsplus unify fncts.control.Pure
42
+ */
43
+ export function unifyPure<X extends Pure<any, any, any, any, any, any>>(
44
+ _: X,
45
+ ): Pure<
46
+ [X] extends [Pure<infer W, any, any, any, any, any>] ? W : never,
47
+ [X] extends [Pure<any, infer S1, any, any, any, any>] ? S1 : never,
48
+ [X] extends [Pure<any, any, infer S2, any, any, any>] ? S2 : never,
49
+ [X] extends [Pure<any, any, any, infer R, any, any>] ? R : never,
50
+ [X] extends [Pure<any, any, any, any, infer E, any>] ? E : never,
51
+ [X] extends [Pure<any, any, any, any, any, infer A>] ? A : never
52
+ > {
53
+ return _;
54
+ }
55
+
56
+ export class PurePrimitive {
57
+ readonly [PureTypeId]: PureTypeId = PureTypeId;
58
+ declare [PureVariance]: {
59
+ readonly _W: (_: never) => never;
60
+ readonly _S1: (_: unknown) => void;
61
+ readonly _S2: (_: never) => never;
62
+ readonly _R: (_: never) => never;
63
+ readonly _E: (_: never) => never;
64
+ readonly _A: (_: never) => never;
65
+ };
66
+ constructor(readonly _tag: unknown) {}
67
+ readonly i0: unknown = undefined;
68
+ readonly i1: unknown = undefined;
69
+ readonly i2: unknown = undefined;
70
+ }
71
+
72
+ /**
73
+ * @tsplus static fncts.control.PureOps isPure
74
+ */
75
+ export function isPure(u: unknown): u is Pure<unknown, unknown, unknown, unknown, unknown, unknown> {
76
+ return isObject(u) && PureTypeId in u;
77
+ }
78
+
79
+ export const enum PureTag {
80
+ SucceedNow,
81
+ Succeed,
82
+ Defer,
83
+ Fail,
84
+ Modify,
85
+ Chain,
86
+ Match,
87
+ Access,
88
+ Provide,
89
+ Tell,
90
+ Listen,
91
+ MapLog,
92
+ }
93
+
94
+ export type PureOp<Tag extends number, Body = {}> = PurePrimitive &
95
+ Body & {
96
+ _tag: Tag;
97
+ };
98
+
99
+ export interface SucceedNow
100
+ extends PureOp<
101
+ PureTag.SucceedNow,
102
+ {
103
+ readonly i0: any;
104
+ }
105
+ > {}
106
+
107
+ export interface Succeed
108
+ extends PureOp<
109
+ PureTag.Succeed,
110
+ {
111
+ readonly i0: () => any;
112
+ }
113
+ > {}
114
+
115
+ export interface Defer
116
+ extends PureOp<
117
+ PureTag.Defer,
118
+ {
119
+ readonly i0: () => Primitive;
120
+ }
121
+ > {}
122
+
123
+ export interface Fail
124
+ extends PureOp<
125
+ PureTag.Fail,
126
+ {
127
+ readonly i0: Cause<unknown>;
128
+ }
129
+ > {}
130
+
131
+ export interface Modify
132
+ extends PureOp<
133
+ PureTag.Modify,
134
+ {
135
+ readonly i0: (s1: any) => readonly [any, any];
136
+ }
137
+ > {}
138
+
139
+ export interface FlatMap
140
+ extends PureOp<
141
+ PureTag.Chain,
142
+ {
143
+ readonly i0: Primitive;
144
+ readonly i1: (a: any) => Primitive;
145
+ }
146
+ > {}
147
+
148
+ export interface Match
149
+ extends PureOp<
150
+ PureTag.Match,
151
+ {
152
+ readonly i0: Primitive;
153
+ readonly i1: (ws: Conc<any>, e: Cause<unknown>) => Primitive;
154
+ readonly i2: (ws: Conc<any>, a: any) => Primitive;
155
+ }
156
+ > {}
157
+
158
+ export interface Access
159
+ extends PureOp<
160
+ PureTag.Access,
161
+ {
162
+ readonly i0: (r: Environment<any>) => Primitive;
163
+ }
164
+ > {}
165
+
166
+ export interface Provide
167
+ extends PureOp<
168
+ PureTag.Provide,
169
+ {
170
+ readonly i0: Primitive;
171
+ readonly i1: Environment<any>;
172
+ }
173
+ > {}
174
+
175
+ export interface Tell
176
+ extends PureOp<
177
+ PureTag.Tell,
178
+ {
179
+ readonly i0: Conc<any>;
180
+ }
181
+ > {}
182
+
183
+ export interface MapLog
184
+ extends PureOp<
185
+ PureTag.MapLog,
186
+ {
187
+ readonly i0: Primitive;
188
+ readonly i1: (ws: Conc<any>) => Conc<any>;
189
+ }
190
+ > {}
191
+
192
+ export type Primitive =
193
+ | SucceedNow
194
+ | Fail
195
+ | Modify
196
+ | FlatMap
197
+ | Match
198
+ | Access
199
+ | Provide
200
+ | Defer
201
+ | Succeed
202
+ | Tell
203
+ | MapLog;
204
+
205
+ /**
206
+ * @tsplus static fncts.control.PureOps concrete
207
+ */
208
+ export function concrete(_: Pure<any, any, any, any, any, any>): asserts _ is Primitive {
209
+ //
210
+ }
211
+
212
+ export const PureErrorTypeId = Symbol.for("fncts.Pure.ZError");
213
+ export type PureErrorTypeId = typeof PureErrorTypeId;
214
+
215
+ export class PureError<E> {
216
+ readonly [PureErrorTypeId]: PureErrorTypeId = PureErrorTypeId;
217
+ constructor(readonly cause: Cause<E>) {}
218
+ }
219
+
220
+ export function isPureError(u: unknown): u is PureError<unknown> {
221
+ return isObject(u) && PureErrorTypeId in u;
222
+ }
@@ -1,12 +1,12 @@
1
1
  import type * as P from "../../typeclass.js";
2
- import type { ZF } from "./definition.js";
2
+ import type { PureF } from "./definition.js";
3
3
 
4
4
  import { map, succeedNow, zip, zipWith } from "./api.js";
5
5
  /**
6
- * @tsplus static fncts.control.ZOps Applicative
6
+ * @tsplus static fncts.control.PureOps Applicative
7
7
  * @tsplus implicit
8
8
  */
9
- export const Applicative = HKT.instance<P.Applicative<ZF>>({
9
+ export const Applicative = HKT.instance<P.Applicative<PureF>>({
10
10
  map,
11
11
  zip,
12
12
  zipWith,
@@ -1,18 +1,18 @@
1
1
  import { identity } from "../../data/function.js";
2
2
  import { Stack } from "../../internal/Stack.js";
3
- import { concrete, isZError, ZTag } from "./definition.js";
3
+ import { concrete, isPureError, PurePrimitive, PureTag } from "./definition.js";
4
4
 
5
5
  class MatchFrame {
6
- readonly _zTag = "MatchFrame";
6
+ readonly _tag = "MatchFrame";
7
7
  constructor(
8
- readonly failure: (e: any) => Z<any, any, any, any, any, any>,
9
- readonly apply: (a: any) => Z<any, any, any, any, any, any>,
8
+ readonly failure: (e: any) => Pure<any, any, any, any, any, any>,
9
+ readonly apply: (a: any) => Pure<any, any, any, any, any, any>,
10
10
  ) {}
11
11
  }
12
12
 
13
13
  class ApplyFrame {
14
- readonly _zTag = "ApplyFrame";
15
- constructor(readonly apply: (e: any) => Z<any, any, any, any, any, any>) {}
14
+ readonly _tag = "ApplyFrame";
15
+ constructor(readonly apply: (e: any) => Pure<any, any, any, any, any, any>) {}
16
16
  }
17
17
 
18
18
  type Frame = MatchFrame | ApplyFrame;
@@ -21,16 +21,16 @@ type Frame = MatchFrame | ApplyFrame;
21
21
  * Runs this computation with the specified initial state, returning either a
22
22
  * failure or the updated state and the result
23
23
  *
24
- * @tsplus pipeable fncts.control.Z unsafeRunAll
24
+ * @tsplus pipeable fncts.control.Pure unsafeRunAll
25
25
  */
26
26
  export function unsafeRunAll<S1>(s: S1) {
27
- return <W, S2, E, A>(ma: Z<W, S1, S2, never, E, A>): readonly [Conc<W>, Exit<E, readonly [S2, A]>] => {
27
+ return <W, S2, E, A>(ma: Pure<W, S1, S2, never, E, A>): readonly [Conc<W>, Exit<E, readonly [S2, A]>] => {
28
28
  const stack: Stack<Frame> = Stack();
29
29
  let s0 = s as any;
30
30
  let result: any = null;
31
31
  const environment = Stack<Environment<unknown>>();
32
32
  let failed = false;
33
- let current = ma as Z<any, any, any, any, any, any> | undefined;
33
+ let current = ma as Pure<any, any, any, any, any, any> | undefined;
34
34
  let log = Conc.empty<W>();
35
35
  function unsafeUnwindStack() {
36
36
  let unwinding = true;
@@ -39,7 +39,7 @@ export function unsafeRunAll<S1>(s: S1) {
39
39
  if (next == null) {
40
40
  unwinding = false;
41
41
  } else {
42
- if (next._zTag === "MatchFrame") {
42
+ if (next._tag === "MatchFrame") {
43
43
  unwinding = false;
44
44
  stack.push(new ApplyFrame(next.failure));
45
45
  }
@@ -49,24 +49,24 @@ export function unsafeRunAll<S1>(s: S1) {
49
49
  while (current != null) {
50
50
  try {
51
51
  while (current != null) {
52
- const currZ: Z<any, any, any, any, any, any> = current;
53
- concrete(currZ);
54
- switch (currZ._tag) {
55
- case ZTag.Chain: {
56
- const nested = currZ.ma;
57
- const continuation = currZ.f;
52
+ const currPure: Pure<any, any, any, any, any, any> = current;
53
+ concrete(currPure);
54
+ switch (currPure._tag) {
55
+ case PureTag.Chain: {
56
+ const nested = currPure.i0;
57
+ const continuation = currPure.i1;
58
58
  concrete(nested);
59
59
  switch (nested._tag) {
60
- case ZTag.SucceedNow: {
61
- current = continuation(nested.value);
60
+ case PureTag.SucceedNow: {
61
+ current = continuation(nested.i0);
62
62
  break;
63
63
  }
64
- case ZTag.Succeed: {
65
- current = continuation(nested.effect());
64
+ case PureTag.Succeed: {
65
+ current = continuation(nested.i0());
66
66
  break;
67
67
  }
68
- case ZTag.Modify: {
69
- const updated = nested.run(s0);
68
+ case PureTag.Modify: {
69
+ const updated = nested.i0(s0);
70
70
  result = updated[0];
71
71
  s0 = updated[1];
72
72
  current = continuation(result);
@@ -80,8 +80,8 @@ export function unsafeRunAll<S1>(s: S1) {
80
80
  }
81
81
  break;
82
82
  }
83
- case ZTag.Succeed: {
84
- result = currZ.effect();
83
+ case PureTag.Succeed: {
84
+ result = currPure.i0();
85
85
  const nextInstruction = stack.pop();
86
86
  if (nextInstruction) {
87
87
  current = nextInstruction.apply(result);
@@ -90,12 +90,12 @@ export function unsafeRunAll<S1>(s: S1) {
90
90
  }
91
91
  break;
92
92
  }
93
- case ZTag.Defer: {
94
- current = currZ.make();
93
+ case PureTag.Defer: {
94
+ current = currPure.i0();
95
95
  break;
96
96
  }
97
- case ZTag.SucceedNow: {
98
- result = currZ.value;
97
+ case PureTag.SucceedNow: {
98
+ result = currPure.i0;
99
99
  const nextInstr = stack.pop();
100
100
  if (nextInstr) {
101
101
  current = nextInstr.apply(result);
@@ -104,30 +104,30 @@ export function unsafeRunAll<S1>(s: S1) {
104
104
  }
105
105
  break;
106
106
  }
107
- case ZTag.Fail: {
107
+ case PureTag.Fail: {
108
108
  unsafeUnwindStack();
109
109
  const nextInst = stack.pop();
110
110
  if (nextInst) {
111
- current = nextInst.apply(currZ.cause);
111
+ current = nextInst.apply(currPure.i0);
112
112
  } else {
113
113
  failed = true;
114
- result = currZ.cause;
114
+ result = currPure.i0;
115
115
  current = undefined;
116
116
  }
117
117
  break;
118
118
  }
119
- case ZTag.Match: {
120
- current = currZ.z;
119
+ case PureTag.Match: {
120
+ current = currPure.i0;
121
121
  const state = s0;
122
122
  stack.push(
123
123
  new MatchFrame(
124
124
  (cause: Cause<any>) => {
125
- const m = Z.put(state).flatMap(() => currZ.onFailure(log, cause));
125
+ const m = Pure.put(state).flatMap(() => currPure.i1(log, cause));
126
126
  log = Conc.empty();
127
127
  return m;
128
128
  },
129
129
  (a) => {
130
- const m = currZ.onSuccess(log, a);
130
+ const m = currPure.i2(log, a);
131
131
  log = Conc.empty();
132
132
  return m;
133
133
  },
@@ -135,20 +135,20 @@ export function unsafeRunAll<S1>(s: S1) {
135
135
  );
136
136
  break;
137
137
  }
138
- case ZTag.Access: {
139
- current = currZ.asks(environment.peek() ?? Environment());
138
+ case PureTag.Access: {
139
+ current = currPure.i0(environment.peek() ?? Environment());
140
140
  break;
141
141
  }
142
- case ZTag.Provide: {
143
- environment.push(currZ.env);
144
- current = currZ.ma.match(
145
- (e) => Z.succeedNow(environment.pop()).flatMap(() => Z.failNow(e)),
146
- (a) => Z.succeedNow(environment.pop()).flatMap(() => Z.succeedNow(a)),
147
- );
142
+ case PureTag.Provide: {
143
+ environment.push(currPure.i1);
144
+ current = new PurePrimitive(PureTag.Match) as any;
145
+ (current as any).i0 = currPure;
146
+ (current as any).i1 = (e: any) => Pure.succeedNow(environment.pop()).flatMap(() => Pure.failNow(e));
147
+ (current as any).i2 = (a: any) => Pure.succeedNow(environment.pop()).flatMap(() => Pure.succeedNow(a));
148
148
  break;
149
149
  }
150
- case ZTag.Modify: {
151
- const updated = currZ.run(s0);
150
+ case PureTag.Modify: {
151
+ const updated = currPure.i0(s0);
152
152
  s0 = updated[1];
153
153
  result = updated[0];
154
154
  const nextInst = stack.pop();
@@ -159,8 +159,8 @@ export function unsafeRunAll<S1>(s: S1) {
159
159
  }
160
160
  break;
161
161
  }
162
- case ZTag.Tell: {
163
- log = currZ.log;
162
+ case PureTag.Tell: {
163
+ log = currPure.i0;
164
164
  const nextInst = stack.pop();
165
165
  if (nextInst) {
166
166
  current = nextInst.apply(result);
@@ -169,17 +169,17 @@ export function unsafeRunAll<S1>(s: S1) {
169
169
  }
170
170
  break;
171
171
  }
172
- case ZTag.MapLog: {
173
- current = currZ.ma;
172
+ case PureTag.MapLog: {
173
+ current = currPure.i0;
174
174
  stack.push(
175
175
  new MatchFrame(
176
176
  (cause: Cause<any>) => {
177
- log = currZ.modifyLog(log);
178
- return Z.failCauseNow(cause);
177
+ log = currPure.i1(log);
178
+ return Pure.failCauseNow(cause);
179
179
  },
180
180
  (a) => {
181
- log = currZ.modifyLog(log);
182
- return Z.succeedNow(a);
181
+ log = currPure.i1(log);
182
+ return Pure.succeedNow(a);
183
183
  },
184
184
  ),
185
185
  );
@@ -187,8 +187,8 @@ export function unsafeRunAll<S1>(s: S1) {
187
187
  }
188
188
  }
189
189
  } catch (e) {
190
- if (isZError(e)) {
191
- current = Z.failCauseNow(e.cause);
190
+ if (isPureError(e)) {
191
+ current = Pure.failCauseNow(e.cause);
192
192
  } else {
193
193
  failed = true;
194
194
  result = Cause.halt(e);
@@ -206,13 +206,12 @@ export function unsafeRunAll<S1>(s: S1) {
206
206
  * Runs this computation with the specified initial state, returning both
207
207
  * the updated state and the result.
208
208
  *
209
- * @tsplus pipeable fncts.control.Z unsafeRun
209
+ * @tsplus pipeable fncts.control.Pure unsafeRun
210
210
  */
211
211
  export function unsafeRun<S1>(s: S1) {
212
- return <W, S2, A>(ma: Z<W, S1, S2, never, never, A>): readonly [S2, A] => {
212
+ return <W, S2, A>(ma: Pure<W, S1, S2, never, never, A>): readonly [S2, A] => {
213
213
  return ma.unsafeRunAll(s)[1].match((cause) => {
214
- // throw cause.squash
215
- throw new Error();
214
+ throw cause.squashWith(Function.identity);
216
215
  }, identity);
217
216
  };
218
217
  }
@@ -220,19 +219,19 @@ export function unsafeRun<S1>(s: S1) {
220
219
  /**
221
220
  * Runs this computation, returning the result.
222
221
  *
223
- * @tsplus getter fncts.control.Z unsafeRunResult
222
+ * @tsplus getter fncts.control.Pure unsafeRunResult
224
223
  */
225
- export function unsafeRunResult<W, A>(ma: Z<W, unknown, unknown, never, never, A>): A {
224
+ export function unsafeRunResult<W, A>(ma: Pure<W, unknown, unknown, never, never, A>): A {
226
225
  return ma.unsafeRun({})[1];
227
226
  }
228
227
 
229
228
  /**
230
229
  * Runs this computation with the given environment, returning the result.
231
230
  *
232
- * @tsplus pipeable fncts.control.Z unsafeRunReader
231
+ * @tsplus pipeable fncts.control.Pure unsafeRunReader
233
232
  */
234
233
  export function unsafeRunReader<R>(r: Environment<R>) {
235
- return <W, A>(ma: Z<W, unknown, never, R, never, A>): A => {
234
+ return <W, A>(ma: Pure<W, unknown, never, R, never, A>): A => {
236
235
  return unsafeRunResult(ma.provideEnvironment(r));
237
236
  };
238
237
  }
@@ -241,10 +240,10 @@ export function unsafeRunReader<R>(r: Environment<R>) {
241
240
  * Runs this computation with the specified initial state, returning the
242
241
  * updated state and discarding the result.
243
242
  *
244
- * @tsplus pipeable fncts.control.Z unsafeRunState
243
+ * @tsplus pipeable fncts.control.Pure unsafeRunState
245
244
  */
246
245
  export function unsafeRunState<S1>(s: S1) {
247
- return <W, S2, A>(ma: Z<W, S1, S2, never, never, A>): S2 => {
246
+ return <W, S2, A>(ma: Pure<W, S1, S2, never, never, A>): S2 => {
248
247
  return ma.unsafeRun(s)[0];
249
248
  };
250
249
  }
@@ -253,14 +252,13 @@ export function unsafeRunState<S1>(s: S1) {
253
252
  * Runs this computation with the specified initial state, returning the
254
253
  * result and discarding the updated state.
255
254
  *
256
- * @tsplus pipeable fncts.control.Z unsafeRunStateResult
255
+ * @tsplus pipeable fncts.control.Pure unsafeRunStateResult
257
256
  */
258
257
  export function unsafeRunStateResult<S1>(s: S1) {
259
- return <W, S2, A>(ma: Z<W, S1, S2, never, never, A>): A => {
258
+ return <W, S2, A>(ma: Pure<W, S1, S2, never, never, A>): A => {
260
259
  return ma.unsafeRunAll(s)[1].match(
261
260
  (cause) => {
262
- // throw cause.squash
263
- throw new Error();
261
+ throw cause.squashWith(Function.identity);
264
262
  },
265
263
  ([_, a]) => a,
266
264
  );
@@ -270,22 +268,21 @@ export function unsafeRunStateResult<S1>(s: S1) {
270
268
  /**
271
269
  * Runs this computation returning either the result or error
272
270
  *
273
- * @tsplus getter fncts.control.Z unsafeRunExit
271
+ * @tsplus getter fncts.control.Pure unsafeRunExit
274
272
  */
275
- export function unsafeRunExit<E, A>(ma: Z<never, unknown, unknown, never, E, A>): Exit<E, A> {
273
+ export function unsafeRunExit<E, A>(ma: Pure<never, unknown, unknown, never, E, A>): Exit<E, A> {
276
274
  return ma.unsafeRunAll({} as never)[1].map(([_, a]) => a);
277
275
  }
278
276
 
279
277
  /**
280
278
  *
281
- * @tsplus getter fncts.control.Z unsafeRunWriter
279
+ * @tsplus getter fncts.control.Pure unsafeRunWriter
282
280
  */
283
- export function unsafeRunWriter<W, A>(ma: Z<W, unknown, unknown, never, never, A>): readonly [Conc<W>, A] {
281
+ export function unsafeRunWriter<W, A>(ma: Pure<W, unknown, unknown, never, never, A>): readonly [Conc<W>, A] {
284
282
  const [w, exit] = ma.unsafeRunAll({});
285
283
  return exit.match(
286
- () => {
287
- // throw cause.squash
288
- throw new Error();
284
+ (cause) => {
285
+ throw cause.squashWith(Function.identity);
289
286
  },
290
287
  ([_, a]) => [w, a],
291
288
  );
@@ -0,0 +1,6 @@
1
+ // codegen:start { preset: barrel, include: ./Pure/*.ts }
2
+ export * from "./Pure/api.js";
3
+ export * from "./Pure/definition.js";
4
+ export * from "./Pure/instances.js";
5
+ export * from "./Pure/runtime.js";
6
+ // codegen:end
package/_src/control.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  export type {} from "./control/CompletablePromise.js";
3
3
  export type {} from "./control/Eval.js";
4
4
  export type {} from "./control/LazyValue.js";
5
- export type {} from "./control/Z.js";
5
+ export type {} from "./control/Pure.js";
6
6
  // codegen:end
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ /** @tsplus type fncts.Date */
3
+ interface Date {}
4
+ /** @tsplus type fncts.DateOps */
5
+ interface DateConstructor {}
6
+ }
@@ -0,0 +1,3 @@
1
+ // codegen:start { preset: barrel, include: ./Date/*.ts }
2
+ export * from "./Date/definition.js";
3
+ // codegen:end