@fncts/io 0.0.41 → 0.0.43

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.
Files changed (221) hide show
  1. package/Fiber/FiberRuntime.d.ts +2 -2
  2. package/Fiber/definition.d.ts +1 -0
  3. package/FiberSet.d.ts +66 -0
  4. package/Hub/definition.d.ts +3 -0
  5. package/Hub/internal.d.ts +1 -0
  6. package/IO/api/diffFiberRefs.d.ts +7 -0
  7. package/IO/api/timeout.d.ts +5 -0
  8. package/IO/api.d.ts +12 -1
  9. package/IO/definition.d.ts +18 -7
  10. package/IO.d.ts +1 -0
  11. package/Layer/api.d.ts +5 -0
  12. package/Queue/api/dimapIO.d.ts +5 -0
  13. package/Queue/api/filterInputIO.d.ts +1 -1
  14. package/Queue/api/filterOutputIO.d.ts +1 -0
  15. package/Queue/api/operations.d.ts +11 -0
  16. package/Queue/api/zipWithIO.d.ts +1 -0
  17. package/Queue/definition.d.ts +5 -0
  18. package/Queue/internal.d.ts +1 -0
  19. package/STM/definition.d.ts +1 -1
  20. package/Stream/api.d.ts +10 -0
  21. package/_cjs/Channel/api/mapOutConcurrentIO.cjs +2 -8
  22. package/_cjs/Channel/api/mapOutConcurrentIO.cjs.map +1 -1
  23. package/_cjs/Channel/api/mergeAllWith.cjs +14 -23
  24. package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
  25. package/_cjs/Channel/api/mergeWith.cjs +4 -16
  26. package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
  27. package/_cjs/Channel/api.cjs +18 -33
  28. package/_cjs/Channel/api.cjs.map +1 -1
  29. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs +2 -8
  30. package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs.map +1 -1
  31. package/_cjs/Fiber/FiberRuntime.cjs +86 -75
  32. package/_cjs/Fiber/FiberRuntime.cjs.map +1 -1
  33. package/_cjs/Fiber/definition.cjs.map +1 -1
  34. package/_cjs/FiberSet.cjs +129 -0
  35. package/_cjs/FiberSet.cjs.map +1 -0
  36. package/_cjs/Hub/api.cjs +20 -11
  37. package/_cjs/Hub/api.cjs.map +1 -1
  38. package/_cjs/Hub/definition.cjs +3 -0
  39. package/_cjs/Hub/definition.cjs.map +1 -1
  40. package/_cjs/Hub/internal.cjs +65 -49
  41. package/_cjs/Hub/internal.cjs.map +1 -1
  42. package/_cjs/IO/api/asyncInterrupt.cjs +4 -7
  43. package/_cjs/IO/api/asyncInterrupt.cjs.map +1 -1
  44. package/_cjs/IO/api/diffFiberRefs.cjs +17 -0
  45. package/_cjs/IO/api/diffFiberRefs.cjs.map +1 -0
  46. package/_cjs/IO/api/memoize.cjs +7 -4
  47. package/_cjs/IO/api/memoize.cjs.map +1 -1
  48. package/_cjs/IO/api/timeout.cjs +8 -0
  49. package/_cjs/IO/api/timeout.cjs.map +1 -1
  50. package/_cjs/IO/api.cjs +33 -42
  51. package/_cjs/IO/api.cjs.map +1 -1
  52. package/_cjs/IO/definition.cjs +9 -3
  53. package/_cjs/IO/definition.cjs.map +1 -1
  54. package/_cjs/IO/runtime.cjs +3 -6
  55. package/_cjs/IO/runtime.cjs.map +1 -1
  56. package/_cjs/IO.cjs +11 -0
  57. package/_cjs/IO.cjs.map +1 -1
  58. package/_cjs/Layer/api.cjs +9 -5
  59. package/_cjs/Layer/api.cjs.map +1 -1
  60. package/_cjs/Push/api.cjs +1 -4
  61. package/_cjs/Push/api.cjs.map +1 -1
  62. package/_cjs/Queue/api/dimapIO.cjs +28 -10
  63. package/_cjs/Queue/api/dimapIO.cjs.map +1 -1
  64. package/_cjs/Queue/api/filterInputIO.cjs +21 -9
  65. package/_cjs/Queue/api/filterInputIO.cjs.map +1 -1
  66. package/_cjs/Queue/api/filterOutputIO.cjs +28 -16
  67. package/_cjs/Queue/api/filterOutputIO.cjs.map +1 -1
  68. package/_cjs/Queue/api/operations.cjs +20 -0
  69. package/_cjs/Queue/api/operations.cjs.map +1 -1
  70. package/_cjs/Queue/api/zipWithIO.cjs +16 -9
  71. package/_cjs/Queue/api/zipWithIO.cjs.map +1 -1
  72. package/_cjs/Queue/definition.cjs.map +1 -1
  73. package/_cjs/Queue/internal.cjs +84 -54
  74. package/_cjs/Queue/internal.cjs.map +1 -1
  75. package/_cjs/Ref/Derived.cjs +8 -35
  76. package/_cjs/Ref/Derived.cjs.map +1 -1
  77. package/_cjs/Ref/DerivedAll.cjs +8 -35
  78. package/_cjs/Ref/DerivedAll.cjs.map +1 -1
  79. package/_cjs/STM/api/core-api.cjs +1 -4
  80. package/_cjs/STM/api/core-api.cjs.map +1 -1
  81. package/_cjs/STM/api.cjs +4 -16
  82. package/_cjs/STM/api.cjs.map +1 -1
  83. package/_cjs/STM/definition.cjs +1 -1
  84. package/_cjs/STM/definition.cjs.map +1 -1
  85. package/_cjs/Schedule/api.cjs +1 -7
  86. package/_cjs/Schedule/api.cjs.map +1 -1
  87. package/_cjs/Sink/api.cjs +1 -7
  88. package/_cjs/Sink/api.cjs.map +1 -1
  89. package/_cjs/Stream/api/zipAllWith.cjs +1 -4
  90. package/_cjs/Stream/api/zipAllWith.cjs.map +1 -1
  91. package/_cjs/Stream/api/zipWithChunks.cjs +1 -4
  92. package/_cjs/Stream/api/zipWithChunks.cjs.map +1 -1
  93. package/_cjs/Stream/api.cjs +51 -37
  94. package/_cjs/Stream/api.cjs.map +1 -1
  95. package/_cjs/TRef/definition.cjs +20 -74
  96. package/_cjs/TRef/definition.cjs.map +1 -1
  97. package/_cjs/internal/BackgroundScheduler.cjs +0 -1
  98. package/_cjs/internal/BackgroundScheduler.cjs.map +1 -1
  99. package/_mjs/Channel/api/mapOutConcurrentIO.mjs +2 -8
  100. package/_mjs/Channel/api/mapOutConcurrentIO.mjs.map +1 -1
  101. package/_mjs/Channel/api/mergeAllWith.mjs +14 -23
  102. package/_mjs/Channel/api/mergeAllWith.mjs.map +1 -1
  103. package/_mjs/Channel/api/mergeWith.mjs +4 -16
  104. package/_mjs/Channel/api/mergeWith.mjs.map +1 -1
  105. package/_mjs/Channel/api.mjs +18 -33
  106. package/_mjs/Channel/api.mjs.map +1 -1
  107. package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs +2 -8
  108. package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs.map +1 -1
  109. package/_mjs/Fiber/FiberRuntime.mjs +86 -75
  110. package/_mjs/Fiber/FiberRuntime.mjs.map +1 -1
  111. package/_mjs/Fiber/definition.mjs.map +1 -1
  112. package/_mjs/FiberSet.mjs +113 -0
  113. package/_mjs/FiberSet.mjs.map +1 -0
  114. package/_mjs/Hub/api.mjs +20 -11
  115. package/_mjs/Hub/api.mjs.map +1 -1
  116. package/_mjs/Hub/definition.mjs +3 -0
  117. package/_mjs/Hub/definition.mjs.map +1 -1
  118. package/_mjs/Hub/internal.mjs +65 -49
  119. package/_mjs/Hub/internal.mjs.map +1 -1
  120. package/_mjs/IO/api/asyncInterrupt.mjs +4 -7
  121. package/_mjs/IO/api/asyncInterrupt.mjs.map +1 -1
  122. package/_mjs/IO/api/diffFiberRefs.mjs +9 -0
  123. package/_mjs/IO/api/diffFiberRefs.mjs.map +1 -0
  124. package/_mjs/IO/api/memoize.mjs +7 -4
  125. package/_mjs/IO/api/memoize.mjs.map +1 -1
  126. package/_mjs/IO/api/timeout.mjs +7 -0
  127. package/_mjs/IO/api/timeout.mjs.map +1 -1
  128. package/_mjs/IO/api.mjs +30 -40
  129. package/_mjs/IO/api.mjs.map +1 -1
  130. package/_mjs/IO/definition.mjs +7 -2
  131. package/_mjs/IO/definition.mjs.map +1 -1
  132. package/_mjs/IO/runtime.mjs +3 -6
  133. package/_mjs/IO/runtime.mjs.map +1 -1
  134. package/_mjs/IO.mjs +1 -0
  135. package/_mjs/IO.mjs.map +1 -1
  136. package/_mjs/Layer/api.mjs +8 -5
  137. package/_mjs/Layer/api.mjs.map +1 -1
  138. package/_mjs/Push/api.mjs +1 -4
  139. package/_mjs/Push/api.mjs.map +1 -1
  140. package/_mjs/Queue/api/dimapIO.mjs +28 -10
  141. package/_mjs/Queue/api/dimapIO.mjs.map +1 -1
  142. package/_mjs/Queue/api/filterInputIO.mjs +21 -9
  143. package/_mjs/Queue/api/filterInputIO.mjs.map +1 -1
  144. package/_mjs/Queue/api/filterOutputIO.mjs +28 -16
  145. package/_mjs/Queue/api/filterOutputIO.mjs.map +1 -1
  146. package/_mjs/Queue/api/operations.mjs +18 -0
  147. package/_mjs/Queue/api/operations.mjs.map +1 -1
  148. package/_mjs/Queue/api/zipWithIO.mjs +16 -9
  149. package/_mjs/Queue/api/zipWithIO.mjs.map +1 -1
  150. package/_mjs/Queue/definition.mjs.map +1 -1
  151. package/_mjs/Queue/internal.mjs +84 -54
  152. package/_mjs/Queue/internal.mjs.map +1 -1
  153. package/_mjs/Ref/Derived.mjs +8 -35
  154. package/_mjs/Ref/Derived.mjs.map +1 -1
  155. package/_mjs/Ref/DerivedAll.mjs +8 -35
  156. package/_mjs/Ref/DerivedAll.mjs.map +1 -1
  157. package/_mjs/STM/api/core-api.mjs +1 -4
  158. package/_mjs/STM/api/core-api.mjs.map +1 -1
  159. package/_mjs/STM/api.mjs +4 -16
  160. package/_mjs/STM/api.mjs.map +1 -1
  161. package/_mjs/STM/definition.mjs +1 -1
  162. package/_mjs/STM/definition.mjs.map +1 -1
  163. package/_mjs/Schedule/api.mjs +1 -7
  164. package/_mjs/Schedule/api.mjs.map +1 -1
  165. package/_mjs/Sink/api.mjs +1 -7
  166. package/_mjs/Sink/api.mjs.map +1 -1
  167. package/_mjs/Stream/api/zipAllWith.mjs +1 -4
  168. package/_mjs/Stream/api/zipAllWith.mjs.map +1 -1
  169. package/_mjs/Stream/api/zipWithChunks.mjs +1 -4
  170. package/_mjs/Stream/api/zipWithChunks.mjs.map +1 -1
  171. package/_mjs/Stream/api.mjs +47 -36
  172. package/_mjs/Stream/api.mjs.map +1 -1
  173. package/_mjs/TRef/definition.mjs +20 -74
  174. package/_mjs/TRef/definition.mjs.map +1 -1
  175. package/_mjs/internal/BackgroundScheduler.mjs +0 -1
  176. package/_mjs/internal/BackgroundScheduler.mjs.map +1 -1
  177. package/_src/Channel/api/mapOutConcurrentIO.ts +5 -5
  178. package/_src/Channel/api/mergeAllWith.ts +9 -9
  179. package/_src/Channel/api/mergeWith.ts +16 -16
  180. package/_src/Channel/api.ts +12 -32
  181. package/_src/Channel/internal/SingleProducerAsyncInput.ts +2 -2
  182. package/_src/Fiber/FiberRuntime.ts +50 -36
  183. package/_src/Fiber/definition.ts +2 -0
  184. package/_src/FiberSet.ts +115 -0
  185. package/_src/Hub/api.ts +15 -6
  186. package/_src/Hub/definition.ts +6 -0
  187. package/_src/Hub/internal.ts +19 -0
  188. package/_src/IO/api/asyncInterrupt.ts +4 -4
  189. package/_src/IO/api/diffFiberRefs.ts +11 -0
  190. package/_src/IO/api/memoize.ts +5 -3
  191. package/_src/IO/api/timeout.ts +8 -0
  192. package/_src/IO/api.ts +32 -19
  193. package/_src/IO/definition.ts +20 -4
  194. package/_src/IO/runtime.ts +3 -6
  195. package/_src/IO.ts +1 -0
  196. package/_src/Layer/api.ts +11 -4
  197. package/_src/Push/api.ts +4 -4
  198. package/_src/Queue/api/dimapIO.ts +25 -0
  199. package/_src/Queue/api/filterInputIO.ts +16 -0
  200. package/_src/Queue/api/filterOutputIO.ts +16 -0
  201. package/_src/Queue/api/operations.ts +20 -0
  202. package/_src/Queue/api/zipWithIO.ts +8 -0
  203. package/_src/Queue/definition.ts +4 -0
  204. package/_src/Queue/internal.ts +32 -0
  205. package/_src/Ref/Derived.ts +18 -20
  206. package/_src/Ref/DerivedAll.ts +18 -21
  207. package/_src/STM/api/core-api.ts +1 -1
  208. package/_src/STM/api.ts +4 -4
  209. package/_src/STM/definition.ts +1 -1
  210. package/_src/Schedule/api.ts +8 -8
  211. package/_src/Sink/api.ts +8 -8
  212. package/_src/Stream/api/zipAllWith.ts +4 -4
  213. package/_src/Stream/api/zipWithChunks.ts +4 -4
  214. package/_src/Stream/api.ts +75 -22
  215. package/_src/TRef/definition.ts +33 -36
  216. package/_src/global.ts +4 -0
  217. package/_src/index.ts +1 -0
  218. package/_src/internal/BackgroundScheduler.ts +0 -1
  219. package/global.d.ts +4 -0
  220. package/index.d.ts +1 -0
  221. package/package.json +4 -4
@@ -96,12 +96,9 @@ export class Runtime<R> {
96
96
  };
97
97
 
98
98
  unsafeRun = <E, A>(io: IO<R, E, A>, __tsplusTrace?: string): Exit<E, A> => {
99
- return this.unsafeRunOrFork(io).match({
100
- Left: () => {
101
- throw new Error("Encountered async boundary");
102
- },
103
- Right: Function.identity,
104
- });
99
+ return this.unsafeRunOrFork(io).match(() => {
100
+ throw new Error("Encountered async boundary");
101
+ }, Function.identity);
105
102
  };
106
103
  }
107
104
 
package/_src/IO.ts CHANGED
@@ -50,6 +50,7 @@ export * from "./IO/api/foreachConcurrent.js";
50
50
  export * from "./IO/api/environment.js";
51
51
  export * from "./IO/api/ensuringChildren.js";
52
52
  export * from "./IO/api/disconnect.js";
53
+ export * from "./IO/api/diffFiberRefs.js";
53
54
  export * from "./IO/api/descriptor.js";
54
55
  export * from "./IO/api/delay.js";
55
56
  export * from "./IO/api/daemonChildren.js";
package/_src/Layer/api.ts CHANGED
@@ -206,10 +206,7 @@ export function matchLayer<E, ROut, RIn1, E1, ROut1, RIn2, E2, ROut2>(
206
206
  __tsplusTrace?: string,
207
207
  ) {
208
208
  return <RIn>(self: Layer<RIn, E, ROut>): Layer<RIn | RIn1 | RIn2, E1 | E2, ROut1 | ROut2> => {
209
- return self.matchCauseLayer(
210
- (cause) => cause.failureOrCause.match({ Left: failure, Right: Layer.failCauseNow }),
211
- success,
212
- );
209
+ return self.matchCauseLayer((cause) => cause.failureOrCause.match(failure, Layer.failCauseNow), success);
213
210
  };
214
211
  }
215
212
 
@@ -324,6 +321,16 @@ function retryLoop<RIn, E, ROut, S, RIn1, X>(
324
321
  );
325
322
  }
326
323
 
324
+ /**
325
+ * @tsplus static fncts.io.LayerOps scopedDiscard
326
+ */
327
+ export function scopedDiscard<R, E, A>(
328
+ io: Lazy<IO<R, E, A>>,
329
+ __tsplusTrace?: string,
330
+ ): Layer<Exclude<R, Scope>, E, never> {
331
+ return Layer.scopedEnvironment(io().as(Environment.empty));
332
+ }
333
+
327
334
  /**
328
335
  * @tsplus static fncts.io.LayerOps scoped
329
336
  */
package/_src/Push/api.ts CHANGED
@@ -36,10 +36,10 @@ export function asyncInterrupt<R, E, A>(
36
36
  };
37
37
  const eitherPush = Δ(IO(make(unsafeSink)));
38
38
  Δ(
39
- eitherPush.match({
40
- Left: (canceller) => future.await.onInterrupt(canceller),
41
- Right: (push) => push.run(sink),
42
- }),
39
+ eitherPush.match(
40
+ (canceller) => future.await.onInterrupt(canceller),
41
+ (push) => push.run(sink),
42
+ ),
43
43
  );
44
44
  }).scoped,
45
45
  );
@@ -1,3 +1,4 @@
1
+ import type { Maybe } from "@fncts/base/data/Maybe";
1
2
  import type { UIO } from "@fncts/io/IO";
2
3
  import type { PDequeue, PDequeueInternal, PEnqueue, PEnqueueInternal } from "@fncts/io/Queue/definition";
3
4
 
@@ -32,6 +33,14 @@ class DimapIO<RA, RB, EA, EB, A, B, RC, EC, C, RD, ED, D> extends QueueInternal<
32
33
 
33
34
  isShutdown: UIO<boolean> = this.queue.isShutdown;
34
35
 
36
+ get unsafeSize(): Maybe<number> {
37
+ return this.queue.unsafeSize;
38
+ }
39
+
40
+ unsafeOffer(a: C): boolean {
41
+ throw new Error("Cannot unsafely offer to an effectful Queue");
42
+ }
43
+
35
44
  offer(c: C): IO<RC | RA, EA | EC, boolean> {
36
45
  return this.f(c).flatMap((a) => this.queue.offer(a));
37
46
  }
@@ -151,6 +160,14 @@ class ContramapIO<RA, RB, EA, EB, A, B, RC, EC, C> implements PEnqueueInternal<R
151
160
 
152
161
  isShutdown: UIO<boolean> = this.queue.isShutdown;
153
162
 
163
+ get unsafeSize(): Maybe<number> {
164
+ return this.queue.unsafeSize;
165
+ }
166
+
167
+ unsafeOffer(a: C): boolean {
168
+ throw new Error("Cannot unsafely offer to an effectful Queue");
169
+ }
170
+
154
171
  offer(c: C): IO<RC | RA, EA | EC, boolean> {
155
172
  return this.f(c).flatMap((a) => this.queue.offer(a));
156
173
  }
@@ -202,6 +219,14 @@ class MapIO<RA, RB, EA, EB, A, B, RC, EC, C> implements PDequeueInternal<RA, RB
202
219
 
203
220
  size: UIO<number> = this.queue.size;
204
221
 
222
+ get unsafeSize(): Maybe<number> {
223
+ return this.queue.unsafeSize;
224
+ }
225
+
226
+ unsafeOffer(a: C): boolean {
227
+ throw new Error("Cannot unsafely offer to an effectful Queue");
228
+ }
229
+
205
230
  take: IO<RB | RC, EB | EC, C> = this.queue.take.flatMap(this.f);
206
231
 
207
232
  takeAll: IO<RB | RC, EB | EC, Conc<C>> = this.queue.takeAll.flatMap((bs) => IO.foreach(bs, this.f));
@@ -16,6 +16,14 @@ class FilterInputIO<RA, RB, EA, EB, B, A, A1 extends A, R2, E2> extends QueueInt
16
16
 
17
17
  isShutdown: UIO<boolean> = this.queue.isShutdown;
18
18
 
19
+ get unsafeSize(): Maybe<number> {
20
+ return this.queue.unsafeSize;
21
+ }
22
+
23
+ unsafeOffer(a: A1): boolean {
24
+ throw new Error("Cannot unsafely offer to an effectful Queue");
25
+ }
26
+
19
27
  offer(a: A1): IO<RA | R2, EA | E2, boolean> {
20
28
  return this.f(a).flatMap((b) => (b ? this.queue.offer(a) : IO.succeedNow(false)));
21
29
  }
@@ -92,6 +100,14 @@ class FilterInputEnqueueIO<RA, RB, EA, EB, B, A, A1 extends A, R2, E2>
92
100
 
93
101
  isShutdown: UIO<boolean> = this.queue.isShutdown;
94
102
 
103
+ get unsafeSize(): Maybe<number> {
104
+ return this.queue.unsafeSize;
105
+ }
106
+
107
+ unsafeOffer(a: A1): boolean {
108
+ throw new Error("Cannot unsafely offer to an effectful Queue");
109
+ }
110
+
95
111
  offer(a: A1): IO<RA | R2, EA | E2, boolean> {
96
112
  return this.f(a).flatMap((b) => (b ? this.queue.offer(a) : IO.succeedNow(false)));
97
113
  }
@@ -16,6 +16,14 @@ class FilterOutputIO<RA, RB, EA, EB, A, B, RB1, EB1> extends QueueInternal<RA, R
16
16
 
17
17
  isShutdown: UIO<boolean> = this.queue.isShutdown;
18
18
 
19
+ get unsafeSize(): Maybe<number> {
20
+ return this.queue.unsafeSize;
21
+ }
22
+
23
+ unsafeOffer(a: A): boolean {
24
+ throw new Error("Cannot unsafely offer to an effectful Queue");
25
+ }
26
+
19
27
  offer(a: A): IO<RA, EA, boolean> {
20
28
  return this.queue.offer(a);
21
29
  }
@@ -104,6 +112,14 @@ class FilterOutputDequeueIO<RA, RB, EA, EB, A, B, RB1, EB1>
104
112
 
105
113
  size: UIO<number> = this.queue.size;
106
114
 
115
+ get unsafeSize(): Maybe<number> {
116
+ return this.queue.unsafeSize;
117
+ }
118
+
119
+ unsafeOffer(a: A): boolean {
120
+ throw new Error("Cannot unsafely offer to an effectful Queue");
121
+ }
122
+
107
123
  take: IO<RB | RB1, EB1 | EB, B> = this.queue.take.flatMap((b) =>
108
124
  this.f(b).flatMap((p) => (p ? IO.succeedNow(b) : this.take)),
109
125
  );
@@ -43,6 +43,18 @@ export function isShutdown<RA, RB, EA, EB, A, B>(
43
43
  return queue.isShutdown;
44
44
  }
45
45
 
46
+ /**
47
+ * Places one value in the queue.
48
+ *
49
+ * @tsplus pipeable fncts.io.Queue unsafeOffer
50
+ */
51
+ export function unsafeOffer<A>(a: A, __tsplusTrace?: string) {
52
+ return <RA, RB, EA, EB, B>(queue: PEnqueue<RA, RB, EA, EB, A, B>): boolean => {
53
+ concrete(queue);
54
+ return queue.unsafeOffer(a);
55
+ };
56
+ }
57
+
46
58
  /**
47
59
  * Places one value in the queue.
48
60
  *
@@ -103,6 +115,14 @@ export function size<RA, RB, EA, EB, A, B>(queue: PQueueCommon<RA, RB, EA, EB, A
103
115
  return queue.size;
104
116
  }
105
117
 
118
+ /**
119
+ * @tsplus getter fncts.io.Queue unsafeSize
120
+ */
121
+ export function unsafeSize<RA, RB, EA, EB, A, B>(queue: PQueueCommon<RA, RB, EA, EB, A, B>, __tsplusTrace?: string) {
122
+ concrete(queue);
123
+ return queue.unsafeSize;
124
+ }
125
+
106
126
  /**
107
127
  * Removes the oldest value in the queue. If the queue is empty, this will
108
128
  * return a computation that resumes when an item has been added to the queue.
@@ -23,6 +23,14 @@ class ZipWithIO<RA, RB, EA, EB, A, B, RA1, RB1, EA1, EB1, A1 extends A, B1, R3,
23
23
 
24
24
  isShutdown: UIO<boolean> = this.fa.isShutdown;
25
25
 
26
+ get unsafeSize(): Maybe<number> {
27
+ return this.fa.unsafeSize.zipWith(this.fb.unsafeSize, (a, b) => Math.max(a, b));
28
+ }
29
+
30
+ unsafeOffer(a: A): boolean {
31
+ throw new Error("Cannot unsafely offer to an effectful Queue");
32
+ }
33
+
26
34
  offer(a: A1): IO<RA | RA1, EA1 | EA, boolean> {
27
35
  return this.fa.offer(a).zipWithConcurrent(this.fb.offer(a), (x, y) => x && y);
28
36
  }
@@ -113,6 +113,7 @@ export abstract class QueueInternal<RA, RB, EA, EB, A, B>
113
113
  * `true` if `shutdown` has been called.
114
114
  */
115
115
  abstract readonly isShutdown: UIO<boolean>;
116
+ abstract unsafeOffer(a: A): boolean;
116
117
  /**
117
118
  * Places one value in the queue.
118
119
  */
@@ -140,6 +141,7 @@ export abstract class QueueInternal<RA, RB, EA, EB, A, B>
140
141
  * Future calls to `offer*` and `take*` will be interrupted immediately.
141
142
  */
142
143
  abstract readonly shutdown: UIO<void>;
144
+ abstract readonly unsafeSize: Maybe<number>;
143
145
  /**
144
146
  * Retrieves the size of the queue, which is equal to the number of elements
145
147
  * in the queue. This may be negative if fibers are suspended waiting for
@@ -211,6 +213,7 @@ export interface PQueueCommonInternal<RA, RB, EA, EB, A, B> {
211
213
  * Future calls to `offer*` and `take*` will be interrupted immediately.
212
214
  */
213
215
  readonly shutdown: UIO<void>;
216
+ readonly unsafeSize: Maybe<number>;
214
217
  /**
215
218
  * Retrieves the size of the queue, which is equal to the number of elements
216
219
  * in the queue. This may be negative if fibers are suspended waiting for
@@ -221,6 +224,7 @@ export interface PQueueCommonInternal<RA, RB, EA, EB, A, B> {
221
224
 
222
225
  export interface PEnqueueInternal<RA, RB, EA, EB, A, B> extends PQueueCommonInternal<RA, RB, EA, EB, A, B> {
223
226
  readonly [EnqueueTypeId]: EnqueueTypeId;
227
+ unsafeOffer(a: A): boolean;
224
228
  /**
225
229
  * Places one value in the queue.
226
230
  */
@@ -22,6 +22,38 @@ class UnsafeQueue<A> extends QueueInternal<never, never, never, never, A, A> {
22
22
 
23
23
  isShutdown: UIO<boolean> = IO.succeed(this.shutdownFlag.get);
24
24
 
25
+ get unsafeSize(): Maybe<number> {
26
+ if (this.shutdownFlag.get) {
27
+ return Nothing();
28
+ }
29
+ return Just(this.queue.size - this.takers.size + this.strategy.surplusSize);
30
+ }
31
+
32
+ unsafeOffer(a: A): boolean {
33
+ if (this.shutdownFlag.get) {
34
+ return false;
35
+ }
36
+ let noRemaining: boolean;
37
+ if (this.queue.size === 0) {
38
+ const taker = this.takers.dequeue(undefined);
39
+
40
+ if (taker != null) {
41
+ unsafeCompletePromise(taker, a);
42
+ noRemaining = true;
43
+ } else {
44
+ noRemaining = false;
45
+ }
46
+ } else {
47
+ noRemaining = false;
48
+ }
49
+ if (noRemaining) {
50
+ return true;
51
+ }
52
+ const succeeded = this.queue.enqueue(a);
53
+ unsafeCompleteTakers(this.strategy, this.queue, this.takers);
54
+ return succeeded;
55
+ }
56
+
25
57
  offer(a: A, __tsplusTrace?: string): IO<never, never, boolean> {
26
58
  return IO.defer(() => {
27
59
  if (this.shutdownFlag.get) {
@@ -35,8 +35,8 @@ export class Derived<EA, EB, A, B> extends RefInternal<never, never, EA, EB, A,
35
35
  new Derived<EC, ED, C, D>((f) =>
36
36
  f(
37
37
  value,
38
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
39
- (c) => ca(c).flatMap((a) => setEither(a).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
38
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
39
+ (c) => ca(c).flatMap((a) => setEither(a).match((e) => Either.left(ea(e)), Either.right)),
40
40
  ),
41
41
  ),
42
42
  );
@@ -54,43 +54,41 @@ export class Derived<EA, EB, A, B> extends RefInternal<never, never, EA, EB, A,
54
54
  new DerivedAll<EC, ED, C, D>((f) =>
55
55
  f(
56
56
  value,
57
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
57
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
58
58
  (c) => (s) =>
59
59
  getEither(s)
60
- .match({
61
- Left: (eb) => Either.left(ec(eb)),
62
- Right: (b) => ca(c)(b),
63
- })
64
- .flatMap((a) => setEither(a).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
60
+ .match(
61
+ (eb) => Either.left(ec(eb)),
62
+ (b) => ca(c)(b),
63
+ )
64
+ .flatMap((a) => setEither(a).match((e) => Either.left(ea(e)), Either.right)),
65
65
  ),
66
66
  ),
67
67
  );
68
68
  }
69
69
 
70
70
  get get(): FIO<EB, B> {
71
- return this.use((value, getEither) =>
72
- value.get.flatMap((s) => getEither(s).match({ Left: IO.failNow, Right: IO.succeedNow })),
73
- );
71
+ return this.use((value, getEither) => value.get.flatMap((s) => getEither(s).match(IO.failNow, IO.succeedNow)));
74
72
  }
75
73
 
76
74
  set(a: A): FIO<EA, void> {
77
- return this.use((value, _, setEither) => setEither(a).match({ Left: IO.failNow, Right: (s) => value.set(s) }));
75
+ return this.use((value, _, setEither) => setEither(a).match(IO.failNow, (s) => value.set(s)));
78
76
  }
79
77
 
80
78
  modify<C>(f: (b: B) => readonly [C, A], __tsplusTrace?: string | undefined): IO<never, EA | EB, C> {
81
79
  return this.use(
82
80
  (value, getEither, setEither) =>
83
81
  value.modify((s) =>
84
- getEither(s).match({
85
- Left: (e) => tuple(Either.left(e), s),
86
- Right: (a1) => {
82
+ getEither(s).match(
83
+ (e) => tuple(Either.left(e), s),
84
+ (a1) => {
87
85
  const [b, a2] = f(a1);
88
- return setEither(a2).match({
89
- Left: (e) => tuple(Either.left(e), s),
90
- Right: (s) => tuple(Either.right<EA | EB, C>(b), s),
91
- });
86
+ return setEither(a2).match(
87
+ (e) => tuple(Either.left(e), s),
88
+ (s) => tuple(Either.right<EA | EB, C>(b), s),
89
+ );
92
90
  },
93
- }),
91
+ ),
94
92
  ).absolve,
95
93
  );
96
94
  }
@@ -34,9 +34,8 @@ export class DerivedAll<EA, EB, A, B> extends RefInternal<never, never, EA, EB,
34
34
  new DerivedAll((f) =>
35
35
  f(
36
36
  value,
37
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
38
- (c) => (s) =>
39
- ca(c).flatMap((a) => setEither(a)(s).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
37
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
38
+ (c) => (s) => ca(c).flatMap((a) => setEither(a)(s).match((e) => Either.left(ea(e)), Either.right)),
40
39
  ),
41
40
  ),
42
41
  );
@@ -54,30 +53,28 @@ export class DerivedAll<EA, EB, A, B> extends RefInternal<never, never, EA, EB,
54
53
  new DerivedAll((f) =>
55
54
  f(
56
55
  value,
57
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
56
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
58
57
  (c) => (s) =>
59
58
  getEither(s)
60
- .match({ Left: (e) => Either.left(ec(e)), Right: ca(c) })
61
- .flatMap((a) => setEither(a)(s).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
59
+ .match((e) => Either.left(ec(e)), ca(c))
60
+ .flatMap((a) => setEither(a)(s).match((e) => Either.left(ea(e)), Either.right)),
62
61
  ),
63
62
  ),
64
63
  );
65
64
  }
66
65
 
67
66
  get get(): FIO<EB, B> {
68
- return this.use((value, getEither) =>
69
- value.get.flatMap((s) => getEither(s).match({ Left: IO.failNow, Right: IO.succeedNow })),
70
- );
67
+ return this.use((value, getEither) => value.get.flatMap((s) => getEither(s).match(IO.failNow, IO.succeedNow)));
71
68
  }
72
69
 
73
70
  set(a: A): FIO<EA, void> {
74
71
  return this.use(
75
72
  (value, _, setEither) =>
76
73
  value.modify((s) =>
77
- setEither(a)(s).match({
78
- Left: (e) => [Either.left(e), s] as [Either<EA, void>, typeof s],
79
- Right: (s) => [Either.right(undefined), s],
80
- }),
74
+ setEither(a)(s).match(
75
+ (e) => [Either.left(e), s] as [Either<EA, void>, typeof s],
76
+ (s) => [Either.right(undefined), s],
77
+ ),
81
78
  ).absolve,
82
79
  );
83
80
  }
@@ -86,16 +83,16 @@ export class DerivedAll<EA, EB, A, B> extends RefInternal<never, never, EA, EB,
86
83
  return this.use(
87
84
  (value, getEither, setEither) =>
88
85
  value.modify((s) =>
89
- getEither(s).match({
90
- Left: (e) => tuple(Either.left(e), s),
91
- Right: (a1) => {
86
+ getEither(s).match(
87
+ (e) => tuple(Either.left(e), s),
88
+ (a1) => {
92
89
  const [b, a2] = f(a1);
93
- return setEither(a2)(s).match({
94
- Left: (e) => tuple(Either.left(e), s),
95
- Right: (s) => tuple(Either.right<EA | EB, C>(b), s),
96
- });
90
+ return setEither(a2)(s).match(
91
+ (e) => tuple(Either.left(e), s),
92
+ (s) => tuple(Either.right<EA | EB, C>(b), s),
93
+ );
97
94
  },
98
- }),
95
+ ),
99
96
  ).absolve,
100
97
  );
101
98
  }
@@ -65,6 +65,6 @@ export function matchSTM<E, A, R1, E1, B, R2, E2, C>(
65
65
  return self
66
66
  .map(Either.right)
67
67
  .catchAll((e) => g(e).map(Either.left))
68
- .flatMap((ca) => ca.match({ Left: STM.succeedNow, Right: f }));
68
+ .flatMap((ca) => ca.match(STM.succeedNow, f));
69
69
  };
70
70
  }
package/_src/STM/api.ts CHANGED
@@ -429,7 +429,7 @@ export function foreach<A, R, E, B>(
429
429
  * @tsplus static fncts.io.STMOps fromEither
430
430
  */
431
431
  export function fromEither<E, A>(e: Lazy<Either<E, A>>, __tsplusTrace?: string): STM<never, E, A> {
432
- return STM.defer(e().match({ Left: STM.failNow, Right: STM.succeedNow }));
432
+ return STM.defer(e().match(STM.failNow, STM.succeedNow));
433
433
  }
434
434
 
435
435
  /**
@@ -438,7 +438,7 @@ export function fromEither<E, A>(e: Lazy<Either<E, A>>, __tsplusTrace?: string):
438
438
  * @tsplus static fncts.io.STMOps fromEitherNow
439
439
  */
440
440
  export function fromEitherNow<E, A>(e: Either<E, A>, __tsplusTrace?: string): STM<never, E, A> {
441
- return e.match({ Left: STM.failNow, Right: STM.succeedNow });
441
+ return e.match(STM.failNow, STM.succeedNow);
442
442
  }
443
443
 
444
444
  /**
@@ -553,7 +553,7 @@ export function isSuccess<R, E, A>(stm: STM<R, E, A>, __tsplusTrace?: string) {
553
553
  export function left<R, E, B, C>(stm: STM<R, E, Either<B, C>>, __tsplusTrace?: string): STM<R, Maybe<E>, B> {
554
554
  return stm.matchSTM(
555
555
  (e) => STM.fail(Just(e)),
556
- (bc) => bc.match({ Left: STM.succeedNow, Right: () => STM.failNow(Nothing()) }),
556
+ (bc) => bc.match(STM.succeedNow, () => STM.failNow(Nothing())),
557
557
  );
558
558
  }
559
559
 
@@ -564,7 +564,7 @@ export function left<R, E, B, C>(stm: STM<R, E, Either<B, C>>, __tsplusTrace?: s
564
564
  */
565
565
  export function leftOrFail<C, E1>(orFail: (c: C) => E1, __tsplusTrace?: string) {
566
566
  return <R, E, B>(stm: STM<R, E, Either<B, C>>): STM<R, E | E1, B> => {
567
- return stm.flatMap((bc) => bc.match({ Left: STM.succeedNow, Right: (c) => STM.fail(orFail(c)) }));
567
+ return stm.flatMap((bc) => bc.match(STM.succeedNow, (c) => STM.fail(orFail(c))));
568
568
  };
569
569
  }
570
570
 
@@ -25,7 +25,7 @@ export type STMTypeId = typeof STMTypeId;
25
25
  */
26
26
  export abstract class STM<R, E, A> {
27
27
  readonly [IOTypeId]: IOTypeId = IOTypeId;
28
- readonly _tag = IOTag.Commit;
28
+ readonly _ioOpCode = IOTag.Commit;
29
29
  readonly trace?: string;
30
30
  readonly [STMTypeId]: STMTypeId = STMTypeId;
31
31
  declare [IOVariance]: {
@@ -618,17 +618,17 @@ export function reconsiderIO<S, O, R1, O1>(
618
618
  decision.match(
619
619
  () =>
620
620
  f(state, out, decision).map((r) =>
621
- r.match({
622
- Left: (out1) => [state, out1, Decision.Done],
623
- Right: ([out1, _]) => [state, out1, Decision.Done],
624
- }),
621
+ r.match(
622
+ (out1) => [state, out1, Decision.Done],
623
+ ([out1, _]) => [state, out1, Decision.Done],
624
+ ),
625
625
  ),
626
626
  () =>
627
627
  f(state, out, decision).map((r) =>
628
- r.match({
629
- Left: (out1) => [state, out1, Decision.Done],
630
- Right: ([out1, interval]) => [state, out1, Decision.continueWith(interval)],
631
- }),
628
+ r.match(
629
+ (out1) => [state, out1, Decision.Done],
630
+ ([out1, interval]) => [state, out1, Decision.continueWith(interval)],
631
+ ),
632
632
  ),
633
633
  ),
634
634
  ),
package/_src/Sink/api.ts CHANGED
@@ -567,20 +567,20 @@ function fromPushPull<R, E, In, L, Z>(
567
567
  (inp: Conc<In>) =>
568
568
  Channel.fromIO(push(Just(inp))).matchChannel(
569
569
  ([r, leftovers]) =>
570
- r.match({
571
- Left: (e) => Channel.writeNow(leftovers) > Channel.failNow(e),
572
- Right: (z) => Channel.writeNow(leftovers) > Channel.succeedNow(z),
573
- }),
570
+ r.match(
571
+ (e) => Channel.writeNow(leftovers) > Channel.failNow(e),
572
+ (z) => Channel.writeNow(leftovers) > Channel.succeedNow(z),
573
+ ),
574
574
  () => fromPushPull(push),
575
575
  ),
576
576
  Channel.failNow,
577
577
  () =>
578
578
  Channel.fromIO(push(Nothing())).matchChannel(
579
579
  ([r, leftovers]) =>
580
- r.match({
581
- Left: (e) => Channel.writeNow(leftovers) > Channel.failNow(e),
582
- Right: (z) => Channel.writeNow(leftovers) > Channel.succeedNow(z),
583
- }),
580
+ r.match(
581
+ (e) => Channel.writeNow(leftovers) > Channel.failNow(e),
582
+ (z) => Channel.writeNow(leftovers) > Channel.succeedNow(z),
583
+ ),
584
584
  () => Channel.fromIO(IO.halt(new Error("empty sink"))),
585
585
  ),
586
586
  );
@@ -132,8 +132,8 @@ function zipWithChunks<A, B, C>(
132
132
  __tsplusTrace?: string,
133
133
  ): readonly [Conc<C>, State<A, B>] {
134
134
  const [out, r] = zipChunks(leftChunk, rightChunk, f);
135
- return r.match({
136
- Left: (leftChunk) => (leftChunk.isEmpty ? [out, new PullBoth()] : [out, new PullRight(leftChunk)]),
137
- Right: (rightChunk) => (rightChunk.isEmpty ? [out, new PullBoth()] : [out, new PullLeft(rightChunk)]),
138
- });
135
+ return r.match(
136
+ (leftChunk) => (leftChunk.isEmpty ? [out, new PullBoth()] : [out, new PullRight(leftChunk)]),
137
+ (rightChunk) => (rightChunk.isEmpty ? [out, new PullBoth()] : [out, new PullLeft(rightChunk)]),
138
+ );
139
139
  }
@@ -73,10 +73,10 @@ function handleSuccess<A1, A2, A3>(
73
73
  __tsplusTrace?: string,
74
74
  ): readonly [Conc<A3>, State<A1, A2>] {
75
75
  const [out, remaining] = f(leftChunk, rightChunk);
76
- return remaining.match({
77
- Left: (l) => (leftChunk.isEmpty ? [out, new PullBoth()] : [out, new PullRight(leftChunk)]),
78
- Right: (r) => (rightChunk.isEmpty ? [out, new PullBoth()] : [out, new PullLeft(rightChunk)]),
79
- });
76
+ return remaining.match(
77
+ (l) => (leftChunk.isEmpty ? [out, new PullBoth()] : [out, new PullRight(leftChunk)]),
78
+ (r) => (rightChunk.isEmpty ? [out, new PullBoth()] : [out, new PullLeft(rightChunk)]),
79
+ );
80
80
  }
81
81
 
82
82
  /**