@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
@@ -3,7 +3,7 @@ import type { Canceler } from "../IO.js";
3
3
  import type { PDequeue, PEnqueue, PQueue } from "../Queue.js";
4
4
  import type { SinkEndReason } from "./internal/SinkEndReason.js";
5
5
 
6
- import { constVoid, identity, tuple } from "@fncts/base/data/function";
6
+ import { identity, tuple } from "@fncts/base/data/function";
7
7
 
8
8
  import { MergeDecision } from "../Channel/internal/MergeDecision.js";
9
9
  import { Hub } from "../Hub.js";
@@ -56,9 +56,7 @@ export function aggregateAsyncWithin<R1, E1, A1, B, R2, C>(
56
56
  __tsplusTrace?: string,
57
57
  ) {
58
58
  return <R, E, A extends A1>(stream: Stream<R, E, A>): Stream<R | R1 | R2, E | E1, B> => {
59
- return stream
60
- .aggregateAsyncWithinEither(sink, schedule)
61
- .filterMap((cb) => cb.match({ Left: () => Nothing(), Right: Maybe.just }));
59
+ return stream.aggregateAsyncWithinEither(sink, schedule).filterMap((cb) => cb.match(() => Nothing(), Maybe.just));
62
60
  };
63
61
  }
64
62
 
@@ -167,14 +165,14 @@ export function aggregateAsyncWithinEither<R1, E1, A1, B, R2, C>(
167
165
  (scheduleExit, sinkFiber) =>
168
166
  IO.fromExit(scheduleExit).matchCauseIO(
169
167
  (cause) =>
170
- cause.failureOrCause.match({
171
- Left: () =>
168
+ cause.failureOrCause.match(
169
+ () =>
172
170
  handoff.offer(HandoffSignal.End(new ScheduleEnd())).forkDaemon >
173
171
  sinkFiber.join.map(([leftovers, b]) => handleSide(leftovers, b, Nothing())),
174
- Right: (cause) =>
172
+ (cause) =>
175
173
  handoff.offer(HandoffSignal.Halt(cause)).forkDaemon >
176
174
  sinkFiber.join.map(([leftovers, b]) => handleSide(leftovers, b, Nothing())),
177
- }),
175
+ ),
178
176
  (c) =>
179
177
  handoff.offer(HandoffSignal.End(new ScheduleEnd())).forkDaemon >
180
178
  sinkFiber.join.map(([leftovers, b]) => handleSide(leftovers, b, Just(c))),
@@ -257,8 +255,8 @@ export function asyncInterrupt<R, E, A>(
257
255
  }),
258
256
  ),
259
257
  );
260
- return eitherStream.match({
261
- Left: (canceler) => {
258
+ return eitherStream.match(
259
+ (canceler) => {
262
260
  const loop: Channel<never, unknown, unknown, unknown, E, Conc<A>, void> = Channel.unwrap(
263
261
  output.take
264
262
  .flatMap((take) => take.done)
@@ -269,8 +267,8 @@ export function asyncInterrupt<R, E, A>(
269
267
  );
270
268
  return new Stream(loop).ensuring(canceler);
271
269
  },
272
- Right: (stream) => Stream.unwrap(output.shutdown.as(stream)),
273
- });
270
+ (stream) => Stream.unwrap(output.shutdown.as(stream)),
271
+ );
274
272
  }),
275
273
  );
276
274
  }
@@ -338,10 +336,10 @@ export function asyncIO<R, E, A, R1 = R, E1 = E>(
338
336
  .matchCauseIO(
339
337
  (cause) =>
340
338
  output.shutdown.as(
341
- cause.failureOrCause.match({
342
- Left: (maybeError) => maybeError.match(() => Channel.endNow(undefined), Channel.failNow),
343
- Right: Channel.failCauseNow,
344
- }),
339
+ cause.failureOrCause.match(
340
+ (maybeError) => maybeError.match(() => Channel.endNow(undefined), Channel.failNow),
341
+ Channel.failCauseNow,
342
+ ),
345
343
  ),
346
344
  (as) => IO.succeed(Channel.writeNow(as) > loop),
347
345
  ),
@@ -579,7 +577,7 @@ function bufferSignalConsumer<R, E, A>(
579
577
  */
580
578
  export function catchAll<R1, E, E1, A1>(f: (e: E) => Stream<R1, E1, A1>, __tsplusTrace?: string) {
581
579
  return <R, A>(stream: Stream<R, E, A>): Stream<R | R1, E1, A | A1> => {
582
- return stream.catchAllCause((cause) => cause.failureOrCause.match({ Left: f, Right: Stream.failCauseNow }));
580
+ return stream.catchAllCause((cause) => cause.failureOrCause.match(f, Stream.failCauseNow));
583
581
  };
584
582
  }
585
583
 
@@ -1592,6 +1590,26 @@ export function fromChunk<O>(c: Lazy<Conc<O>>, __tsplusTrace?: string): Stream<n
1592
1590
  return new Stream(Channel.unwrap(IO.succeedNow(Channel.write(c))));
1593
1591
  }
1594
1592
 
1593
+ /**
1594
+ * @tsplus static fncts.io.StreamOps fromReadableStream
1595
+ */
1596
+ export function fromReadableStream<A, E>(
1597
+ evaluate: Lazy<ReadableStream<A>>,
1598
+ onError: (error: unknown) => E,
1599
+ ): Stream<never, E, A> {
1600
+ return Stream.unwrapScoped(
1601
+ IO(evaluate().getReader())
1602
+ .acquireRelease((reader) => IO.fromPromiseHalt(reader.cancel()))
1603
+ .map((reader) =>
1604
+ Stream.repeatIOMaybe(
1605
+ IO.fromPromiseCatch(reader.read(), (reason) => Just(onError(reason))).flatMap(({ done, value }) =>
1606
+ done ? IO.failNow(Nothing()) : IO.succeedNow(value),
1607
+ ),
1608
+ ),
1609
+ ),
1610
+ );
1611
+ }
1612
+
1595
1613
  /**
1596
1614
  * Creates a single-valued stream from a managed resource
1597
1615
  *
@@ -3210,7 +3228,7 @@ export function toPull<R, E, A>(
3210
3228
  __tsplusTrace?: string,
3211
3229
  ): IO<R | Scope, never, IO<R, Maybe<E>, Conc<A>>> {
3212
3230
  return stream.channel.toPull.map((io) =>
3213
- io.mapError(Maybe.just).flatMap((r) => r.match({ Left: () => IO.failNow(Nothing()), Right: IO.succeedNow })),
3231
+ io.mapError(Maybe.just).flatMap((r) => r.match(() => IO.failNow(Nothing()), IO.succeedNow)),
3214
3232
  );
3215
3233
  }
3216
3234
 
@@ -3286,6 +3304,41 @@ export function toQueueUnbounded<R, E, A>(
3286
3304
  });
3287
3305
  }
3288
3306
 
3307
+ /**
3308
+ * @tsplus getter fncts.io.Stream toReadableStream
3309
+ */
3310
+ export function toReadableStream<E, A>(self: Stream<never, E, A>, __tsplusTrace?: string): ReadableStream<A> {
3311
+ let pull: UIO<void>;
3312
+ let scope: Scope.Closeable;
3313
+ return new ReadableStream<A>({
3314
+ start(controller) {
3315
+ scope = Scope.make.unsafeRun.getOrThrow;
3316
+ pull = self.toPull
3317
+ .provideScope(scope)
3318
+ .unsafeRun.getOrThrow.tap((chunk) =>
3319
+ IO(
3320
+ chunk.forEach((a) => {
3321
+ controller.enqueue(a);
3322
+ }),
3323
+ ),
3324
+ )
3325
+ .tapErrorCause(() => scope.close(Exit.unit))
3326
+ .catchAll((error) =>
3327
+ error.match(
3328
+ () => IO(controller.close()),
3329
+ (error) => IO(controller.error(error)),
3330
+ ),
3331
+ ).asUnit;
3332
+ },
3333
+ pull() {
3334
+ return pull.unsafeRunPromise();
3335
+ },
3336
+ cancel() {
3337
+ return scope.close(Exit.unit).unsafeRunPromise();
3338
+ },
3339
+ });
3340
+ }
3341
+
3289
3342
  function unfoldChunkIOLoop<S, R, E, A>(
3290
3343
  s: S,
3291
3344
  f: (s: S) => IO<R, E, Maybe<readonly [Conc<A>, S]>>,
@@ -3432,22 +3485,22 @@ export function zipWithLatest<A, R1, E1, B, C>(fb: Stream<R1, E1, B>, f: (a: A,
3432
3485
  Stream.repeatIOMaybe(left)
3433
3486
  .mergeEither(Stream.repeatIOMaybe(right))
3434
3487
  .mapIO((ab) =>
3435
- ab.match({
3436
- Left: (leftChunk) =>
3488
+ ab.match(
3489
+ (leftChunk) =>
3437
3490
  latest.modify(([_, rightLatest]) =>
3438
3491
  tuple(
3439
3492
  leftChunk.map((a) => f(a, rightLatest)),
3440
3493
  tuple(leftChunk.unsafeGet(leftChunk.length - 1), rightLatest),
3441
3494
  ),
3442
3495
  ),
3443
- Right: (rightChunk) =>
3496
+ (rightChunk) =>
3444
3497
  latest.modify(([leftLatest, _]) =>
3445
3498
  tuple(
3446
3499
  rightChunk.map((b) => f(leftLatest, b)),
3447
3500
  tuple(leftLatest, rightChunk.unsafeGet(rightChunk.length - 1)),
3448
3501
  ),
3449
3502
  ),
3450
- }),
3503
+ ),
3451
3504
  )
3452
3505
  .flatMap(Stream.fromChunkNow),
3453
3506
  ),
@@ -162,8 +162,8 @@ export class Derived<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
162
162
  (getEither, setEither, value, atomic) =>
163
163
  new Derived((f) =>
164
164
  f(
165
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
166
- (c) => ca(c).flatMap((a) => setEither(a).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
165
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
166
+ (c) => ca(c).flatMap((a) => setEither(a).match((e) => Either.left(ea(e)), Either.right)),
167
167
  value,
168
168
  atomic,
169
169
  ),
@@ -181,11 +181,11 @@ export class Derived<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
181
181
  (getEither, setEither, value, atomic) =>
182
182
  new DerivedAll((f) =>
183
183
  f(
184
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
184
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
185
185
  (c) => (s) =>
186
186
  getEither(s)
187
- .match({ Left: (e) => Either.left(ec(e)), Right: ca(c) })
188
- .flatMap((a) => setEither(a).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
187
+ .match((e) => Either.left(ec(e)), ca(c))
188
+ .flatMap((a) => setEither(a).match((e) => Either.left(ea(e)), Either.right)),
189
189
  value,
190
190
  atomic,
191
191
  ),
@@ -195,29 +195,27 @@ export class Derived<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
195
195
 
196
196
  get get(): STM<never, EB, B> {
197
197
  return this.use((getEither, _setEither, value, _atomic) =>
198
- value.get.flatMap((s) => getEither(s).match({ Left: STM.failNow, Right: STM.succeedNow })),
198
+ value.get.flatMap((s) => getEither(s).match(STM.failNow, STM.succeedNow)),
199
199
  );
200
200
  }
201
201
 
202
202
  set(a: A, __tsplusTrace?: string | undefined): STM<never, EA, void> {
203
- return this.use((_getEither, setEither, value, _atomic) =>
204
- setEither(a).match({ Left: STM.failNow, Right: (s) => value.set(s) }),
205
- );
203
+ return this.use((_getEither, setEither, value, _atomic) => setEither(a).match(STM.failNow, (s) => value.set(s)));
206
204
  }
207
205
 
208
206
  modify<C>(f: (b: B) => readonly [C, A], __tsplusTrace?: string | undefined): STM<never, EA | EB, C> {
209
207
  return this.use((getEither, setEither, value, _atomic) =>
210
208
  value.modify((s) =>
211
- getEither(s).match({
212
- Left: (e) => [Either.left<EA | EB, C>(e), s],
213
- Right: (a1) => {
209
+ getEither(s).match(
210
+ (e) => [Either.left<EA | EB, C>(e), s],
211
+ (a1) => {
214
212
  const [b, a2] = f(a1);
215
- return setEither(a2).match({
216
- Left: (e) => [Either.left(e), s],
217
- Right: (s) => [Either.right(b), s],
218
- });
213
+ return setEither(a2).match(
214
+ (e) => [Either.left(e), s],
215
+ (s) => [Either.right(b), s],
216
+ );
219
217
  },
220
- }),
218
+ ),
221
219
  ),
222
220
  ).absolve;
223
221
  }
@@ -258,9 +256,8 @@ export class DerivedAll<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
258
256
  (getEither, setEither, value, atomic) =>
259
257
  new DerivedAll((f) =>
260
258
  f(
261
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
262
- (c) => (s) =>
263
- ca(c).flatMap((a) => setEither(a)(s).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
259
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
260
+ (c) => (s) => ca(c).flatMap((a) => setEither(a)(s).match((e) => Either.left(ea(e)), Either.right)),
264
261
  value,
265
262
  atomic,
266
263
  ),
@@ -278,11 +275,11 @@ export class DerivedAll<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
278
275
  (getEither, setEither, value, atomic) =>
279
276
  new DerivedAll((f) =>
280
277
  f(
281
- (s) => getEither(s).match({ Left: (e) => Either.left(eb(e)), Right: bd }),
278
+ (s) => getEither(s).match((e) => Either.left(eb(e)), bd),
282
279
  (c) => (s) =>
283
280
  getEither(s)
284
- .match({ Left: (e) => Either.left(ec(e)), Right: ca(c) })
285
- .flatMap((a) => setEither(a)(s).match({ Left: (e) => Either.left(ea(e)), Right: Either.right })),
281
+ .match((e) => Either.left(ec(e)), ca(c))
282
+ .flatMap((a) => setEither(a)(s).match((e) => Either.left(ea(e)), Either.right)),
286
283
  value,
287
284
  atomic,
288
285
  ),
@@ -292,17 +289,17 @@ export class DerivedAll<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
292
289
 
293
290
  get get(): STM<never, EB, B> {
294
291
  return this.use((getEither, _setEither, value, _atomic) =>
295
- value.get.flatMap((s) => getEither(s).match({ Left: STM.failNow, Right: STM.succeedNow })),
292
+ value.get.flatMap((s) => getEither(s).match(STM.failNow, STM.succeedNow)),
296
293
  );
297
294
  }
298
295
 
299
296
  set(a: A, __tsplusTrace?: string | undefined): STM<never, EA, void> {
300
297
  return this.use((_getEither, setEither, value, _atomic) =>
301
298
  value.modify((s) =>
302
- setEither(a)(s).match({
303
- Left: (e) => [Either.left(e), s] as [Either<EA, void>, typeof s],
304
- Right: (s) => [Either.right(undefined), s],
305
- }),
299
+ setEither(a)(s).match(
300
+ (e) => [Either.left(e), s] as [Either<EA, void>, typeof s],
301
+ (s) => [Either.right(undefined), s],
302
+ ),
306
303
  ),
307
304
  ).absolve;
308
305
  }
@@ -310,16 +307,16 @@ export class DerivedAll<EA, EB, A, B> extends TRefInternal<EA, EB, A, B> {
310
307
  modify<C>(f: (b: B) => readonly [C, A], __tsplusTrace?: string | undefined): STM<never, EA | EB, C> {
311
308
  return this.use((getEither, setEither, value, atomic) =>
312
309
  value.modify((s) =>
313
- getEither(s).match({
314
- Left: (e) => [Either.left<EA | EB, C>(e), s],
315
- Right: (a1) => {
310
+ getEither(s).match(
311
+ (e) => [Either.left<EA | EB, C>(e), s],
312
+ (a1) => {
316
313
  const [b, a2] = f(a1);
317
- return setEither(a2)(s).match({
318
- Left: (e) => [Either.left(e), s],
319
- Right: (s) => [Either.right(b), s],
320
- });
314
+ return setEither(a2)(s).match(
315
+ (e) => [Either.left(e), s],
316
+ (s) => [Either.right(b), s],
317
+ );
321
318
  },
322
- }),
319
+ ),
323
320
  ),
324
321
  ).absolve;
325
322
  }
package/_src/global.ts CHANGED
@@ -51,6 +51,10 @@ import { FiberRefs } from "@fncts/io/FiberRefs";
51
51
  * @tsplus global
52
52
  */
53
53
  import { FiberScope } from "@fncts/io/FiberScope";
54
+ /**
55
+ * @tsplus global
56
+ */
57
+ import { FiberSet } from "@fncts/io/FiberSet";
54
58
  /**
55
59
  * @tsplus global
56
60
  */
package/_src/index.ts CHANGED
@@ -38,6 +38,7 @@ export type {} from "./IO.js";
38
38
  export type {} from "./Hub.js";
39
39
  export type {} from "./Future.js";
40
40
  export type {} from "./FiberStatus.js";
41
+ export type {} from "./FiberSet.js";
41
42
  export type {} from "./FiberScope.js";
42
43
  export type {} from "./FiberRefs.js";
43
44
  export type {} from "./FiberRef.js";
@@ -203,7 +203,6 @@ export class BackgroundScheduler implements Scheduler {
203
203
  if (this.callbacks.length === 0) {
204
204
  const channel = new MessageChannel();
205
205
  channel.port2.postMessage(undefined);
206
- // @ts-expect-error
207
206
  channel.port1.onmessage = (): void => {
208
207
  channel.port1.close();
209
208
  channel.port2.close();
package/global.d.ts CHANGED
@@ -50,6 +50,10 @@ import { FiberRefs } from "@fncts/io/FiberRefs";
50
50
  * @tsplus global
51
51
  */
52
52
  import { FiberScope } from "@fncts/io/FiberScope";
53
+ /**
54
+ * @tsplus global
55
+ */
56
+ import { FiberSet } from "@fncts/io/FiberSet";
53
57
  /**
54
58
  * @tsplus global
55
59
  */
package/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export type {} from "./IO.js";
36
36
  export type {} from "./Hub.js";
37
37
  export type {} from "./Future.js";
38
38
  export type {} from "./FiberStatus.js";
39
+ export type {} from "./FiberSet.js";
39
40
  export type {} from "./FiberScope.js";
40
41
  export type {} from "./FiberRefs.js";
41
42
  export type {} from "./FiberRef.js";
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@fncts/io",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.33",
6
- "@fncts/transformers": "0.0.7",
7
- "@fncts/typelevel": "0.0.16"
5
+ "@fncts/base": "0.0.35",
6
+ "@fncts/transformers": "0.0.9",
7
+ "@fncts/typelevel": "0.0.18"
8
8
  },
9
9
  "exports": {
10
10
  "./*": {