@typed/fx 1.30.0 → 1.32.0

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 (118) hide show
  1. package/dist/cjs/AsyncData.js +7 -7
  2. package/dist/cjs/AsyncData.js.map +1 -1
  3. package/dist/cjs/Emitter.js +5 -5
  4. package/dist/cjs/Emitter.js.map +1 -1
  5. package/dist/cjs/Form.js +7 -7
  6. package/dist/cjs/Form.js.map +1 -1
  7. package/dist/cjs/FormEntry.js +3 -3
  8. package/dist/cjs/FormEntry.js.map +1 -1
  9. package/dist/cjs/Fx.js +16 -16
  10. package/dist/cjs/Fx.js.map +1 -1
  11. package/dist/cjs/Idle.js +7 -7
  12. package/dist/cjs/Idle.js.map +1 -1
  13. package/dist/cjs/Match.js +13 -13
  14. package/dist/cjs/Match.js.map +1 -1
  15. package/dist/cjs/Pull.js +4 -4
  16. package/dist/cjs/Pull.js.map +1 -1
  17. package/dist/cjs/Push.js +2 -2
  18. package/dist/cjs/Push.js.map +1 -1
  19. package/dist/cjs/RefArray.js +3 -3
  20. package/dist/cjs/RefArray.js.map +1 -1
  21. package/dist/cjs/RefChunk.js +2 -2
  22. package/dist/cjs/RefChunk.js.map +1 -1
  23. package/dist/cjs/RefHashMap.js +4 -4
  24. package/dist/cjs/RefHashMap.js.map +1 -1
  25. package/dist/cjs/RefHashSet.js +2 -2
  26. package/dist/cjs/RefHashSet.js.map +1 -1
  27. package/dist/cjs/RefSubject.js +19 -19
  28. package/dist/cjs/RefSubject.js.map +1 -1
  29. package/dist/cjs/Sink.js +6 -6
  30. package/dist/cjs/Sink.js.map +1 -1
  31. package/dist/cjs/Stream.js +9 -9
  32. package/dist/cjs/Stream.js.map +1 -1
  33. package/dist/cjs/Subject.js +9 -9
  34. package/dist/cjs/Subject.js.map +1 -1
  35. package/dist/cjs/TypeId.js +2 -2
  36. package/dist/cjs/TypeId.js.map +1 -1
  37. package/dist/cjs/Typeclass.js +2 -2
  38. package/dist/cjs/Typeclass.js.map +1 -1
  39. package/dist/cjs/Versioned.js +5 -5
  40. package/dist/cjs/Versioned.js.map +1 -1
  41. package/dist/cjs/index.js +18 -18
  42. package/dist/cjs/index.js.map +1 -1
  43. package/dist/cjs/internal/DeferredRef.js +4 -4
  44. package/dist/cjs/internal/DeferredRef.js.map +1 -1
  45. package/dist/cjs/internal/core.js +38 -29
  46. package/dist/cjs/internal/core.js.map +1 -1
  47. package/dist/cjs/internal/diff.js +1 -1
  48. package/dist/cjs/internal/diff.js.map +1 -1
  49. package/dist/cjs/internal/effect-loop-operator.js +6 -6
  50. package/dist/cjs/internal/effect-loop-operator.js.map +1 -1
  51. package/dist/cjs/internal/effect-operator.js +6 -6
  52. package/dist/cjs/internal/effect-operator.js.map +1 -1
  53. package/dist/cjs/internal/effect-producer.js +2 -2
  54. package/dist/cjs/internal/effect-producer.js.map +1 -1
  55. package/dist/cjs/internal/helpers.js +16 -16
  56. package/dist/cjs/internal/helpers.js.map +1 -1
  57. package/dist/cjs/internal/keyed.js +8 -8
  58. package/dist/cjs/internal/keyed.js.map +1 -1
  59. package/dist/cjs/internal/loop-operator.js +3 -3
  60. package/dist/cjs/internal/loop-operator.js.map +1 -1
  61. package/dist/cjs/internal/operator.js +4 -4
  62. package/dist/cjs/internal/operator.js.map +1 -1
  63. package/dist/cjs/internal/protos.js +3 -3
  64. package/dist/cjs/internal/protos.js.map +1 -1
  65. package/dist/cjs/internal/provide.js +5 -5
  66. package/dist/cjs/internal/provide.js.map +1 -1
  67. package/dist/cjs/internal/share.js +5 -5
  68. package/dist/cjs/internal/share.js.map +1 -1
  69. package/dist/cjs/internal/sync-operator.js +5 -5
  70. package/dist/cjs/internal/sync-operator.js.map +1 -1
  71. package/dist/cjs/internal/sync-producer.js +3 -3
  72. package/dist/cjs/internal/sync-producer.js.map +1 -1
  73. package/dist/cjs/internal/withKey.js +5 -5
  74. package/dist/cjs/internal/withKey.js.map +1 -1
  75. package/dist/dts/AsyncData.d.ts.map +1 -1
  76. package/dist/dts/Fx.d.ts +2 -2
  77. package/dist/dts/Fx.d.ts.map +1 -1
  78. package/dist/dts/Idle.d.ts.map +1 -1
  79. package/dist/dts/Match.d.ts.map +1 -1
  80. package/dist/dts/RefArray.d.ts.map +1 -1
  81. package/dist/dts/RefChunk.d.ts.map +1 -1
  82. package/dist/dts/RefHashSet.d.ts.map +1 -1
  83. package/dist/dts/RefSubject.d.ts.map +1 -1
  84. package/dist/dts/TypeId.d.ts +2 -2
  85. package/dist/dts/TypeId.d.ts.map +1 -1
  86. package/dist/dts/internal/core.d.ts +1 -1
  87. package/dist/dts/internal/core.d.ts.map +1 -1
  88. package/dist/dts/internal/diff.d.ts.map +1 -1
  89. package/dist/dts/internal/effect-operator.d.ts.map +1 -1
  90. package/dist/dts/internal/helpers.d.ts.map +1 -1
  91. package/dist/dts/internal/protos.d.ts +3 -3
  92. package/dist/dts/internal/protos.d.ts.map +1 -1
  93. package/dist/dts/internal/provide.d.ts.map +1 -1
  94. package/dist/dts/internal/strategies.d.ts.map +1 -1
  95. package/dist/dts/internal/sync-operator.d.ts.map +1 -1
  96. package/dist/dts/internal/sync-producer.d.ts.map +1 -1
  97. package/dist/esm/Form.js +2 -2
  98. package/dist/esm/Form.js.map +1 -1
  99. package/dist/esm/Fx.js +2 -2
  100. package/dist/esm/Fx.js.map +1 -1
  101. package/dist/esm/RefSubject.js +2 -2
  102. package/dist/esm/RefSubject.js.map +1 -1
  103. package/dist/esm/Subject.js +3 -3
  104. package/dist/esm/Subject.js.map +1 -1
  105. package/dist/esm/TypeId.js +1 -1
  106. package/dist/esm/TypeId.js.map +1 -1
  107. package/dist/esm/internal/core.js +64 -23
  108. package/dist/esm/internal/core.js.map +1 -1
  109. package/dist/esm/internal/protos.js +3 -3
  110. package/dist/esm/internal/protos.js.map +1 -1
  111. package/package.json +11 -10
  112. package/src/Form.ts +2 -2
  113. package/src/Fx.ts +3 -3
  114. package/src/RefSubject.ts +2 -2
  115. package/src/Subject.ts +5 -5
  116. package/src/TypeId.ts +2 -2
  117. package/src/internal/core.ts +733 -413
  118. package/src/internal/protos.ts +3 -3
@@ -61,14 +61,19 @@ const UNBOUNDED = { concurrency: "unbounded" } as const
61
61
  // TODO: Slice optimizations on synchronous producers
62
62
  // TODO: Error/Cause operator fusion
63
63
  // TODO: Double-check other optimiation opportunities
64
- // TODO: expose FxBase and FxEffectBase
65
64
 
66
65
  export function make<A>(
67
66
  run: (sink: Sink.Sink<A>) => Effect.Effect<unknown>
68
67
  ): Fx<A>
69
- export function make<A, E>(run: (sink: Sink.Sink<A, E>) => Effect.Effect<unknown>): Fx<A, E>
70
- export function make<A, E, R>(run: (sink: Sink.Sink<A, E>) => Effect.Effect<unknown, never, R>): Fx<A, E, R>
71
- export function make<A, E, R>(run: (sink: Sink.Sink<A, E>) => Effect.Effect<unknown, never, R>): Fx<A, E, R> {
68
+ export function make<A, E>(
69
+ run: (sink: Sink.Sink<A, E>) => Effect.Effect<unknown>
70
+ ): Fx<A, E>
71
+ export function make<A, E, R>(
72
+ run: (sink: Sink.Sink<A, E>) => Effect.Effect<unknown, never, R>
73
+ ): Fx<A, E, R>
74
+ export function make<A, E, R>(
75
+ run: (sink: Sink.Sink<A, E>) => Effect.Effect<unknown, never, R>
76
+ ): Fx<A, E, R> {
72
77
  return new Make(run)
73
78
  }
74
79
 
@@ -82,6 +87,9 @@ class Make<A, E, R> extends FxBase<A, E, R> {
82
87
  }
83
88
  }
84
89
 
90
+ /**
91
+ * @internal
92
+ */
85
93
  class Producer<A> extends FxBase<A, never, never> {
86
94
  constructor(readonly i0: SyncProducer.SyncProducer<A>) {
87
95
  super()
@@ -102,8 +110,9 @@ export const succeed = <A>(value: A): Fx<A> => new Producer(SyncProducer.Success
102
110
 
103
111
  export const fromSync = <A>(f: () => A): Fx<A> => new Producer(SyncProducer.FromSync(f))
104
112
 
105
- export const fromArray = <const A extends ReadonlyArray<any>>(array: A): Fx<A[number]> =>
106
- new Producer(SyncProducer.FromArray(array))
113
+ export const fromArray = <const A extends ReadonlyArray<any>>(
114
+ array: A
115
+ ): Fx<A[number]> => new Producer(SyncProducer.FromArray(array))
107
116
 
108
117
  export const fromIterable = <A>(iterable: Iterable<A>): Fx<A> => new Producer(SyncProducer.FromIterable(iterable))
109
118
 
@@ -120,11 +129,15 @@ class ProducerEffect<A, E, R> extends FxBase<A, E, R> {
120
129
  /**
121
130
  * @internal
122
131
  */
123
- export function isProducerEffect<A, E, R>(fx: Fx<A, E, R>): fx is ProducerEffect<A, E, R> {
132
+ export function isProducerEffect<A, E, R>(
133
+ fx: Fx<A, E, R>
134
+ ): fx is ProducerEffect<A, E, R> {
124
135
  return fx.constructor === ProducerEffect
125
136
  }
126
137
 
127
- export const fromEffect = <A, E, R>(effect: Effect.Effect<A, E, R>): Fx<A, E, R> =>
138
+ export const fromEffect = <A, E, R>(
139
+ effect: Effect.Effect<A, E, R>
140
+ ): Fx<A, E, R> =>
128
141
  matchEffectPrimitive<A, E, R, Fx<A, E, R>>(effect, {
129
142
  // Match over Effect primitives and return Fx primitives to allow fusion to take place
130
143
  Success: succeed,
@@ -171,7 +184,10 @@ export const fail = <E>(error: E): Fx<never, E> => failCause(Cause.fail(error))
171
184
  export const die = (error: unknown): Fx<never> => failCause(Cause.die(error))
172
185
 
173
186
  class Transformer<A, E, R> extends FxBase<A, E, R> {
174
- constructor(readonly i0: Fx<any, E, R>, readonly i1: Op.Operator) {
187
+ constructor(
188
+ readonly i0: Fx<any, E, R>,
189
+ readonly i1: Op.Operator
190
+ ) {
175
191
  super()
176
192
  }
177
193
 
@@ -179,18 +195,27 @@ class Transformer<A, E, R> extends FxBase<A, E, R> {
179
195
  return this.i0.run(Op.compileOperatorSink(this.i1, sink))
180
196
  }
181
197
 
182
- static make<A, E, R, B, E2, R2>(fx: Fx<A, E, R>, operator: Op.Operator): Fx<B, E | E2, R | R2> {
198
+ static make<A, E, R, B, E2, R2>(
199
+ fx: Fx<A, E, R>,
200
+ operator: Op.Operator
201
+ ): Fx<B, E | E2, R | R2> {
183
202
  if (isEmpty(fx) || isNever(fx)) return fx
184
203
  else if (isProducer(fx)) {
185
204
  return new ProducerSyncTransformer(fx.i0, operator)
186
205
  } else if (isTransformer(fx)) {
187
206
  return new Transformer(fx.i0, Op.fuseOperators(fx.i1, operator))
188
207
  } else if (isProducerSyncTransformer(fx)) {
189
- return new ProducerSyncTransformer(fx.i0, Op.fuseOperators(fx.i1, operator))
208
+ return new ProducerSyncTransformer(
209
+ fx.i0,
210
+ Op.fuseOperators(fx.i1, operator)
211
+ )
190
212
  } else if (isProducerEffect(fx)) {
191
213
  return new ProducerEffectTransformer(fx.i0, operator)
192
214
  } else if (isProducerEffectTransformer(fx)) {
193
- return new ProducerEffectTransformer(fx.i0, Op.fuseOperators(fx.i1, operator))
215
+ return new ProducerEffectTransformer(
216
+ fx.i0,
217
+ Op.fuseOperators(fx.i1, operator)
218
+ )
194
219
  } else if (isSuspend(fx)) {
195
220
  return new SuspendedTransformer(fx.i0, operator)
196
221
  } else if (isSuspendedTransformer(fx)) {
@@ -206,12 +231,17 @@ class Transformer<A, E, R> extends FxBase<A, E, R> {
206
231
  /**
207
232
  * @internal
208
233
  */
209
- export function isTransformer<A, E, R>(fx: Fx<A, E, R>): fx is Transformer<A, E, R> {
234
+ export function isTransformer<A, E, R>(
235
+ fx: Fx<A, E, R>
236
+ ): fx is Transformer<A, E, R> {
210
237
  return fx.constructor === Transformer
211
238
  }
212
239
 
213
240
  class ProducerSyncTransformer<A, E, R> extends FxBase<A, E, R> implements Fx<A, E, R> {
214
- constructor(readonly i0: SyncProducer.SyncProducer<any>, readonly i1: Op.Operator) {
241
+ constructor(
242
+ readonly i0: SyncProducer.SyncProducer<any>,
243
+ readonly i1: Op.Operator
244
+ ) {
215
245
  super()
216
246
  }
217
247
 
@@ -223,17 +253,23 @@ class ProducerSyncTransformer<A, E, R> extends FxBase<A, E, R> implements Fx<A,
223
253
  /**
224
254
  * @internal
225
255
  */
226
- export function isProducerSyncTransformer<A, E, R>(fx: Fx<A, E, R>): fx is ProducerSyncTransformer<A, E, R> {
256
+ export function isProducerSyncTransformer<A, E, R>(
257
+ fx: Fx<A, E, R>
258
+ ): fx is ProducerSyncTransformer<A, E, R> {
227
259
  return fx.constructor === ProducerSyncTransformer
228
260
  }
229
261
 
230
262
  export const map = <A, E, R, B>(fx: Fx<A, E, R>, f: (a: A) => B): Fx<B, E, R> => Transformer.make(fx, SyncOp.Map(f))
231
263
 
232
- export const filter = <A, E, R>(fx: Fx<A, E, R>, f: Predicate.Predicate<A>): Fx<A, E, R> =>
233
- Transformer.make(fx, SyncOp.Filter(f))
264
+ export const filter = <A, E, R>(
265
+ fx: Fx<A, E, R>,
266
+ f: Predicate.Predicate<A>
267
+ ): Fx<A, E, R> => Transformer.make(fx, SyncOp.Filter(f))
234
268
 
235
- export const filterMap = <A, E, R, B>(fx: Fx<A, E, R>, f: (a: A) => Option.Option<B>): Fx<B, E, R> =>
236
- Transformer.make(fx, SyncOp.FilterMap(f))
269
+ export const filterMap = <A, E, R, B>(
270
+ fx: Fx<A, E, R>,
271
+ f: (a: A) => Option.Option<B>
272
+ ): Fx<B, E, R> => Transformer.make(fx, SyncOp.FilterMap(f))
237
273
 
238
274
  export const mapEffect = <A, E, R, B, E2, R2>(
239
275
  fx: Fx<A, E, R>,
@@ -255,10 +291,15 @@ export const tapEffect = <A, E, R, R2, E2>(
255
291
  f: (a: A) => Effect.Effect<unknown, E2, R2>
256
292
  ): Fx<A, E | E2, R | R2> => Transformer.make(fx, EffectOp.TapEffect(f))
257
293
 
258
- export const loop = <A, E, R, B, C>(fx: Fx<A, E, R>, seed: B, f: (acc: B, a: A) => readonly [C, B]): Fx<C, E, R> =>
259
- Transformer.make(fx, SyncLoopOp.LoopOperator(seed, f))
294
+ export const loop = <A, E, R, B, C>(
295
+ fx: Fx<A, E, R>,
296
+ seed: B,
297
+ f: (acc: B, a: A) => readonly [C, B]
298
+ ): Fx<C, E, R> => Transformer.make(fx, SyncLoopOp.LoopOperator(seed, f))
260
299
 
261
- export const withPrevious = <A, E, R>(fx: Fx<A, E, R>): Fx<readonly [Option.Option<A>, A], E, R> =>
300
+ export const withPrevious = <A, E, R>(
301
+ fx: Fx<A, E, R>
302
+ ): Fx<readonly [Option.Option<A>, A], E, R> =>
262
303
  loop(fx, Option.none<A>(), (acc, a) => [[acc, a], Option.some(a)] as const)
263
304
 
264
305
  export const filterMapLoop = <A, E, R, B, C>(
@@ -302,7 +343,9 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
302
343
  const onFailure = (cause: Cause.Cause<E | E2>) => Effect.sync(() => resume(Effect.failCause(cause)))
303
344
 
304
345
  return Effect.zipRight(
305
- fx.run(Sink.make(onFailure, (a) => Effect.catchAllCause(f(a), onFailure))),
346
+ fx.run(
347
+ Sink.make(onFailure, (a) => Effect.catchAllCause(f(a), onFailure))
348
+ ),
306
349
  Effect.sync(() => resume(Effect.void))
307
350
  )
308
351
  })
@@ -326,13 +369,21 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
326
369
  SyncProducer.effectOnce(() => SyncProducer.runEffect(fx.i0, (a) => f(op.f(a)))),
327
370
  Filter: (op) =>
328
371
  SyncProducer.effectOnce(() =>
329
- SyncProducer.runEffect(fx.i0, Unify.unify((a) => op.f(a) ? f(a) : Effect.void))
372
+ SyncProducer.runEffect(
373
+ fx.i0,
374
+ Unify.unify((a) => (op.f(a) ? f(a) : Effect.void))
375
+ )
330
376
  ),
331
377
  FilterMap: (op) =>
332
378
  SyncProducer.effectOnce(() =>
333
379
  SyncProducer.runEffect(
334
380
  fx.i0,
335
- Unify.unify((a) => Option.match(op.f(a), { onNone: () => Effect.void, onSome: f }))
381
+ Unify.unify((a) =>
382
+ Option.match(op.f(a), {
383
+ onNone: () => Effect.void,
384
+ onSome: f
385
+ })
386
+ )
336
387
  )
337
388
  )
338
389
  }),
@@ -342,12 +393,20 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
342
393
  SyncProducer.runEffect(fx.i0, (a) => Effect.flatMap(op.f(a), f)),
343
394
  FilterMapEffect: (op) =>
344
395
  SyncProducer.runEffect(fx.i0, (a) =>
345
- Effect.flatMap(op.f(a), Unify.unify(Option.match({ onNone: () => Effect.void, onSome: f })))),
396
+ Effect.flatMap(
397
+ op.f(a),
398
+ Unify.unify(
399
+ Option.match({ onNone: () => Effect.void, onSome: f })
400
+ )
401
+ )),
346
402
  FilterEffect: (op) =>
347
403
  SyncProducer.runEffect(
348
404
  fx.i0,
349
405
  Unify.unify((a) =>
350
- Effect.flatMap(op.f(a), Unify.unify((b) => b ? f(a) : Effect.void))
406
+ Effect.flatMap(
407
+ op.f(a),
408
+ Unify.unify((b) => (b ? f(a) : Effect.void))
409
+ )
351
410
  )
352
411
  ),
353
412
  TapEffect: (op) => SyncProducer.runEffect(fx.i0, (a) => Effect.flatMap(op.f(a), () => f(a)))
@@ -365,29 +424,28 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
365
424
  SyncProducer.effectOnce(() =>
366
425
  SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => {
367
426
  const [c, b] = op.f(acc, a)
368
- return Option.match(c, { onNone: () => Effect.succeed(acc), onSome: (c) => Effect.as(f(c), b) })
427
+ return Option.match(c, {
428
+ onNone: () => Effect.succeed(acc),
429
+ onSome: (c) => Effect.as(f(c), b)
430
+ })
369
431
  })
370
432
  )
371
433
  }),
372
434
  EffectLoopOperator: (op) =>
373
435
  EffectLoopOp.matchEffectLoopOperator(op, {
374
436
  LoopEffect: (op) =>
375
- SyncProducer.runReduceEffect(
376
- fx.i0,
377
- op.seed,
378
- (acc, a) => Effect.flatMap(op.f(acc, a), ([c, b]) => Effect.as(f(c), b))
379
- ),
437
+ SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) =>
438
+ Effect.flatMap(op.f(acc, a), ([c, b]) =>
439
+ Effect.as(f(c), b))),
380
440
  FilterMapLoopEffect: (op) =>
381
- SyncProducer.runReduceEffect(
382
- fx.i0,
383
- op.seed,
384
- (acc, a) =>
385
- Effect.flatMap(op.f(acc, a), ([c, b]) =>
386
- Option.match(c, {
387
- onNone: () => Effect.succeed(b),
388
- onSome: (c) => Effect.as(f(c), b)
389
- }))
390
- )
441
+ SyncProducer.runReduceEffect(fx.i0, op.seed, (acc, a) =>
442
+ Effect.flatMap(op.f(acc, a), ([c, b]) =>
443
+ Option.match(c, {
444
+ onNone: () =>
445
+ Effect.succeed(b),
446
+ onSome: (c) =>
447
+ Effect.as(f(c), b)
448
+ })))
391
449
  })
392
450
  })
393
451
  } else if (isProducerEffect(fx)) {
@@ -400,13 +458,21 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
400
458
  SyncProducer.effectOnce(() => EffectProducer.runEffect(fx.i0, (a) => f(op.f(a)))),
401
459
  Filter: (op) =>
402
460
  SyncProducer.effectOnce(() =>
403
- EffectProducer.runEffect(fx.i0, Unify.unify((a) => op.f(a) ? f(a) : Effect.void))
461
+ EffectProducer.runEffect(
462
+ fx.i0,
463
+ Unify.unify((a) => (op.f(a) ? f(a) : Effect.void))
464
+ )
404
465
  ),
405
466
  FilterMap: (op) =>
406
467
  SyncProducer.effectOnce(() =>
407
468
  EffectProducer.runEffect(
408
469
  fx.i0,
409
- Unify.unify((a) => Option.match(op.f(a), { onNone: () => Effect.void, onSome: f }))
470
+ Unify.unify((a) =>
471
+ Option.match(op.f(a), {
472
+ onNone: () => Effect.void,
473
+ onSome: f
474
+ })
475
+ )
410
476
  )
411
477
  )
412
478
  }),
@@ -416,12 +482,20 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
416
482
  EffectProducer.runEffect(fx.i0, (a) => Effect.flatMap(op.f(a), f)),
417
483
  FilterMapEffect: (op) =>
418
484
  EffectProducer.runEffect(fx.i0, (a) =>
419
- Effect.flatMap(op.f(a), Unify.unify(Option.match({ onNone: () => Effect.void, onSome: f })))),
485
+ Effect.flatMap(
486
+ op.f(a),
487
+ Unify.unify(
488
+ Option.match({ onNone: () => Effect.void, onSome: f })
489
+ )
490
+ )),
420
491
  FilterEffect: (op) =>
421
492
  EffectProducer.runEffect(
422
493
  fx.i0,
423
494
  Unify.unify((a) =>
424
- Effect.flatMap(op.f(a), Unify.unify((b) => b ? f(a) : Effect.void))
495
+ Effect.flatMap(
496
+ op.f(a),
497
+ Unify.unify((b) => (b ? f(a) : Effect.void))
498
+ )
425
499
  )
426
500
  ),
427
501
  TapEffect: (op) => EffectProducer.runEffect(fx.i0, (a) => Effect.flatMap(op.f(a), () => f(a)))
@@ -439,29 +513,28 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
439
513
  SyncProducer.effectOnce(() =>
440
514
  EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) => {
441
515
  const [c, b] = op.f(acc, a)
442
- return Option.match(c, { onNone: () => Effect.succeed(acc), onSome: (c) => Effect.as(f(c), b) })
516
+ return Option.match(c, {
517
+ onNone: () => Effect.succeed(acc),
518
+ onSome: (c) => Effect.as(f(c), b)
519
+ })
443
520
  })
444
521
  )
445
522
  }),
446
523
  EffectLoopOperator: (op) =>
447
524
  EffectLoopOp.matchEffectLoopOperator(op, {
448
525
  LoopEffect: (op) =>
449
- EffectProducer.runReduceEffect(
450
- fx.i0,
451
- op.seed,
452
- (acc, a) => Effect.flatMap(op.f(acc, a), ([c, b]) => Effect.as(f(c), b))
453
- ),
526
+ EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) =>
527
+ Effect.flatMap(op.f(acc, a), ([c, b]) =>
528
+ Effect.as(f(c), b))),
454
529
  FilterMapLoopEffect: (op) =>
455
- EffectProducer.runReduceEffect(
456
- fx.i0,
457
- op.seed,
458
- (acc, a) =>
459
- Effect.flatMap(op.f(acc, a), ([c, b]) =>
460
- Option.match(c, {
461
- onNone: () => Effect.succeed(b),
462
- onSome: (c) => Effect.as(f(c), b)
463
- }))
464
- )
530
+ EffectProducer.runReduceEffect(fx.i0, op.seed, (acc, a) =>
531
+ Effect.flatMap(op.f(acc, a), ([c, b]) =>
532
+ Option.match(c, {
533
+ onNone: () =>
534
+ Effect.succeed(b),
535
+ onSome: (c) =>
536
+ Effect.as(f(c), b)
537
+ })))
465
538
  })
466
539
  })
467
540
  } else if (isFailCause(fx)) {
@@ -472,11 +545,18 @@ class Observe<A, E, R, B, E2, R2> extends EffectBase<void, E | E2, R | R2> {
472
545
  }
473
546
  }
474
547
 
475
- export const reduce = <A, E, R, B>(fx: Fx<A, E, R>, seed: B, f: (acc: B, a: A) => B): Effect.Effect<B, E, R> =>
476
- Reduce.make(fx, seed, f)
548
+ export const reduce = <A, E, R, B>(
549
+ fx: Fx<A, E, R>,
550
+ seed: B,
551
+ f: (acc: B, a: A) => B
552
+ ): Effect.Effect<B, E, R> => Reduce.make(fx, seed, f)
477
553
 
478
554
  class Reduce<A, E, R, B> extends EffectBase<B, E, R> {
479
- constructor(readonly i0: Fx<A, E, R>, readonly i1: B, readonly i2: (acc: B, a: A) => B) {
555
+ constructor(
556
+ readonly i0: Fx<A, E, R>,
557
+ readonly i1: B,
558
+ readonly i2: (acc: B, a: A) => B
559
+ ) {
480
560
  super()
481
561
  }
482
562
 
@@ -485,7 +565,7 @@ class Reduce<A, E, R, B> extends EffectBase<B, E, R> {
485
565
  let acc = this.i1
486
566
 
487
567
  return Effect.map(
488
- observe(this.i0, (a) => Effect.sync(() => acc = this.i2(acc, a))),
568
+ observe(this.i0, (a) => Effect.sync(() => (acc = this.i2(acc, a)))),
489
569
  () => acc
490
570
  )
491
571
  })
@@ -505,21 +585,32 @@ class Reduce<A, E, R, B> extends EffectBase<B, E, R> {
505
585
  SyncLoopOp.matchSyncLoopOperator(op, {
506
586
  Loop: (op) =>
507
587
  Effect.map(
508
- SyncProducer.runReduce(fx.i0, [op.seed, seed] as const, ([opAcc, acc], a) => {
509
- const [c, b] = op.f(opAcc, a)
510
- const newAcc = f(acc, c)
511
- return [b, newAcc] as const
512
- }),
588
+ SyncProducer.runReduce(
589
+ fx.i0,
590
+ [op.seed, seed] as const,
591
+ ([opAcc, acc], a) => {
592
+ const [c, b] = op.f(opAcc, a)
593
+ const newAcc = f(acc, c)
594
+ return [b, newAcc] as const
595
+ }
596
+ ),
513
597
  (x) => x[1]
514
598
  ),
515
599
  FilterMapLoop: (op) =>
516
600
  Effect.map(
517
- SyncProducer.runReduce(fx.i0, [op.seed, seed] as const, ([opAcc, acc], a) => {
518
- const [c, b] = op.f(opAcc, a)
519
- const newAcc = Option.match(c, { onNone: () => acc, onSome: (c) => f(acc, c) })
601
+ SyncProducer.runReduce(
602
+ fx.i0,
603
+ [op.seed, seed] as const,
604
+ ([opAcc, acc], a) => {
605
+ const [c, b] = op.f(opAcc, a)
606
+ const newAcc = Option.match(c, {
607
+ onNone: () => acc,
608
+ onSome: (c) => f(acc, c)
609
+ })
520
610
 
521
- return [b, newAcc] as const
522
- }),
611
+ return [b, newAcc] as const
612
+ }
613
+ ),
523
614
  (x) => x[1]
524
615
  )
525
616
  }),
@@ -527,22 +618,33 @@ class Reduce<A, E, R, B> extends EffectBase<B, E, R> {
527
618
  EffectLoopOp.matchEffectLoopOperator(op, {
528
619
  LoopEffect: (op) =>
529
620
  Effect.map(
530
- SyncProducer.runReduceEffect(fx.i0, [op.seed, seed] as const, ([opAcc, acc], a) => {
531
- return Effect.flatMap(op.f(opAcc, a), ([c, b]) => {
532
- const newAcc = f(acc, c)
533
- return Effect.succeed([b, newAcc] as const)
534
- })
535
- }),
621
+ SyncProducer.runReduceEffect(
622
+ fx.i0,
623
+ [op.seed, seed] as const,
624
+ ([opAcc, acc], a) => {
625
+ return Effect.flatMap(op.f(opAcc, a), ([c, b]) => {
626
+ const newAcc = f(acc, c)
627
+ return Effect.succeed([b, newAcc] as const)
628
+ })
629
+ }
630
+ ),
536
631
  (x) => x[1]
537
632
  ),
538
633
  FilterMapLoopEffect: (op) =>
539
634
  Effect.map(
540
- SyncProducer.runReduceEffect(fx.i0, [op.seed, seed] as const, ([opAcc, acc], a) => {
541
- return Effect.map(op.f(opAcc, a), ([c, b]) => {
542
- const newAcc = Option.match(c, { onNone: () => acc, onSome: () => f(acc, b) })
543
- return [b, newAcc] as const
544
- })
545
- }),
635
+ SyncProducer.runReduceEffect(
636
+ fx.i0,
637
+ [op.seed, seed] as const,
638
+ ([opAcc, acc], a) => {
639
+ return Effect.map(op.f(opAcc, a), ([c, b]) => {
640
+ const newAcc = Option.match(c, {
641
+ onNone: () => acc,
642
+ onSome: () => f(acc, b)
643
+ })
644
+ return [b, newAcc] as const
645
+ })
646
+ }
647
+ ),
546
648
  (x) => x[1]
547
649
  )
548
650
  })
@@ -557,7 +659,9 @@ class Reduce<A, E, R, B> extends EffectBase<B, E, R> {
557
659
  }
558
660
  }
559
661
 
560
- export const toReadonlyArray = <A, E, R>(fx: Fx<A, E, R>): Effect.Effect<ReadonlyArray<A>, E, R> =>
662
+ export const toReadonlyArray = <A, E, R>(
663
+ fx: Fx<A, E, R>
664
+ ): Effect.Effect<ReadonlyArray<A>, E, R> =>
561
665
  Effect.suspend(() => {
562
666
  const init = [] as Array<A>
563
667
  return Reduce.make(fx, init, (acc, a) => {
@@ -566,15 +670,21 @@ export const toReadonlyArray = <A, E, R>(fx: Fx<A, E, R>): Effect.Effect<Readonl
566
670
  })
567
671
  })
568
672
 
569
- export const slice = <A, E, R>(fx: Fx<A, E, R>, drop: number, take: number): Fx<A, E, R> =>
570
- Slice.make(fx, boundsFrom(drop, take))
673
+ export const slice = <A, E, R>(
674
+ fx: Fx<A, E, R>,
675
+ drop: number,
676
+ take: number
677
+ ): Fx<A, E, R> => Slice.make(fx, boundsFrom(drop, take))
571
678
 
572
679
  export const take = <A, E, R>(fx: Fx<A, E, R>, n: number): Fx<A, E, R> => slice(fx, 0, n)
573
680
 
574
681
  export const drop = <A, E, R>(fx: Fx<A, E, R>, n: number): Fx<A, E, R> => slice(fx, n, Infinity)
575
682
 
576
683
  class Slice<A, E, R> extends FxBase<A, E, R> {
577
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Bounds) {
684
+ constructor(
685
+ readonly i0: Fx<A, E, R>,
686
+ readonly i1: Bounds
687
+ ) {
578
688
  super()
579
689
  }
580
690
 
@@ -629,9 +739,13 @@ const toDeepEquals = (u: unknown): unknown => {
629
739
  } else if (u instanceof Set) {
630
740
  return Data.tuple(Array.from(u, toDeepEquals))
631
741
  } else if (u instanceof Map) {
632
- return Data.tuple(Array.from(u, ([k, v]) => Data.tuple([toDeepEquals(k), toDeepEquals(v)])))
742
+ return Data.tuple(
743
+ Array.from(u, ([k, v]) => Data.tuple([toDeepEquals(k), toDeepEquals(v)]))
744
+ )
633
745
  } else if (u instanceof URLSearchParams) {
634
- return Data.tuple(Array.from(u.keys()).map((key) => Data.tuple([key, toDeepEquals(u.getAll(key))])))
746
+ return Data.tuple(
747
+ Array.from(u.keys()).map((key) => Data.tuple([key, toDeepEquals(u.getAll(key))]))
748
+ )
635
749
  } else if (Symbol.iterator in u) {
636
750
  return Data.tuple(Array.from(u as any, toDeepEquals))
637
751
  } else {
@@ -652,19 +766,29 @@ export const deepEquals = (a: unknown, b: unknown) => {
652
766
  return Equal.equals(toDeepEquals(a), toDeepEquals(b))
653
767
  }
654
768
 
655
- export function skipRepeats<A, E, R>(
656
- fx: Fx<A, E, R>
657
- ): Fx<A, E, R> {
769
+ export function skipRepeats<A, E, R>(fx: Fx<A, E, R>): Fx<A, E, R> {
658
770
  return skipRepeatsWith(fx, deepEquals)
659
771
  }
660
772
 
661
- class ProducerEffectTransformer<A, E, R, B, E2, R2> extends FxBase<B, E | E2, R | R2> {
662
- constructor(readonly i0: EffectProducer.EffectProducer<A, E, R>, readonly i1: Op.Operator) {
773
+ class ProducerEffectTransformer<A, E, R, B, E2, R2> extends FxBase<
774
+ B,
775
+ E | E2,
776
+ R | R2
777
+ > {
778
+ constructor(
779
+ readonly i0: EffectProducer.EffectProducer<A, E, R>,
780
+ readonly i1: Op.Operator
781
+ ) {
663
782
  super()
664
783
  }
665
784
 
666
- run<R3>(sink: Sink.Sink<B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
667
- return EffectProducer.runSink(this.i0, Op.compileOperatorSink(this.i1, sink))
785
+ run<R3>(
786
+ sink: Sink.Sink<B, E | E2, R3>
787
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
788
+ return EffectProducer.runSink(
789
+ this.i0,
790
+ Op.compileOperatorSink(this.i1, sink)
791
+ )
668
792
  }
669
793
  }
670
794
 
@@ -729,7 +853,10 @@ export function appendAll<A, E, R, C>(
729
853
  return new PadWith(fx, [], end)
730
854
  }
731
855
 
732
- export function prepend<A, E, R, B>(fx: Fx<A, E, R>, start: B): Fx<A | B, E, R> {
856
+ export function prepend<A, E, R, B>(
857
+ fx: Fx<A, E, R>,
858
+ start: B
859
+ ): Fx<A | B, E, R> {
733
860
  return new PadWith(fx, [start], [])
734
861
  }
735
862
 
@@ -737,7 +864,11 @@ export function append<A, E, R, C>(fx: Fx<A, E, R>, end: C): Fx<A | C, E, R> {
737
864
  return new PadWith<A, E, R, never, C>(fx, [], [end])
738
865
  }
739
866
 
740
- export function scan<A, E, R, B>(fx: Fx<A, E, R>, seed: B, f: (b: B, a: A) => B): Fx<B, E, R> {
867
+ export function scan<A, E, R, B>(
868
+ fx: Fx<A, E, R>,
869
+ seed: B,
870
+ f: (b: B, a: A) => B
871
+ ): Fx<B, E, R> {
741
872
  return prepend(
742
873
  loop(fx, seed, (b, a) => {
743
874
  const b2 = f(b, a)
@@ -747,18 +878,18 @@ export function scan<A, E, R, B>(fx: Fx<A, E, R>, seed: B, f: (b: B, a: A) => B)
747
878
  )
748
879
  }
749
880
 
750
- class PadWith<
751
- A,
752
- E,
753
- R,
754
- B,
755
- C
756
- > extends FxBase<A | B | C, E, R> {
757
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Iterable<B>, readonly i2: Iterable<C>) {
881
+ class PadWith<A, E, R, B, C> extends FxBase<A | B | C, E, R> {
882
+ constructor(
883
+ readonly i0: Fx<A, E, R>,
884
+ readonly i1: Iterable<B>,
885
+ readonly i2: Iterable<C>
886
+ ) {
758
887
  super()
759
888
  }
760
889
 
761
- run<R2>(sink: Sink.Sink<A | B | C, E, R2>): Effect.Effect<unknown, never, R | R2> {
890
+ run<R2>(
891
+ sink: Sink.Sink<A | B | C, E, R2>
892
+ ): Effect.Effect<unknown, never, R | R2> {
762
893
  const onSuccess = (a: A | B | C) => sink.onSuccess(a)
763
894
 
764
895
  return Effect.forEach(this.i1, onSuccess, DISCARD).pipe(
@@ -861,14 +992,20 @@ export function exhaustFilterMapLatestEffect<A, E, R, B, E2, R2>(
861
992
  f: (a: A) => Effect.Effect<Option.Option<B>, E2, R2>,
862
993
  executionStrategy?: ExecutionStrategy.ExecutionStrategy
863
994
  ): Fx<B, E | E2, R | R2 | Scope.Scope> {
864
- return exhaustMapLatest(fx, (a) =>
865
- fromFxEffect(Effect.map(
866
- f(a),
867
- Option.match({
868
- onNone: () => empty,
869
- onSome: succeed
870
- })
871
- )), executionStrategy)
995
+ return exhaustMapLatest(
996
+ fx,
997
+ (a) =>
998
+ fromFxEffect(
999
+ Effect.map(
1000
+ f(a),
1001
+ Option.match({
1002
+ onNone: () => empty,
1003
+ onSome: succeed
1004
+ })
1005
+ )
1006
+ ),
1007
+ executionStrategy
1008
+ )
872
1009
  }
873
1010
 
874
1011
  export function flatMapConcurrently<A, E, R, B, E2, R2>(
@@ -894,7 +1031,12 @@ export function flatMapConcurrentlyEffect<A, E, R, B, E2, R2>(
894
1031
  capacity: number,
895
1032
  executionStrategy?: ExecutionStrategy.ExecutionStrategy
896
1033
  ): Fx<B, E | E2, R | R2 | Scope.Scope> {
897
- return flatMapConcurrently(fx, (a) => fromEffect(f(a)), capacity, executionStrategy)
1034
+ return flatMapConcurrently(
1035
+ fx,
1036
+ (a) => fromEffect(f(a)),
1037
+ capacity,
1038
+ executionStrategy
1039
+ )
898
1040
  }
899
1041
 
900
1042
  export function flatMap<A, E, R, B, E2, R2>(
@@ -913,19 +1055,13 @@ export function flatMapEffect<A, E, R, B, E2, R2>(
913
1055
  return flatMap(fx, (a) => fromEffect(f(a)), executionStrategy)
914
1056
  }
915
1057
 
916
- class FlatMapWithStrategy<
917
- A,
918
- E,
919
- R,
920
- R2,
921
- E2,
922
- B
923
- > extends FxBase<B, E | E2, R | R2 | Scope.Scope> {
1058
+ class FlatMapWithStrategy<A, E, R, R2, E2, B> extends FxBase<
1059
+ B,
1060
+ E | E2,
1061
+ R | R2 | Scope.Scope
1062
+ > {
924
1063
  private withFork: <A, E, R>(
925
- f: (
926
- fork: FxFork,
927
- scope: Scope.Scope
928
- ) => Effect.Effect<A, E, R>,
1064
+ f: (fork: FxFork, scope: Scope.Scope) => Effect.Effect<A, E, R>,
929
1065
  executionStrategy: ExecutionStrategy.ExecutionStrategy
930
1066
  ) => Effect.Effect<void, E, Scope.Scope | R>
931
1067
 
@@ -940,13 +1076,18 @@ class FlatMapWithStrategy<
940
1076
  this.withFork = withFlattenStrategy(i2)
941
1077
  }
942
1078
 
943
- run<R3>(sink: Sink.Sink<B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3 | Scope.Scope> {
1079
+ run<R3>(
1080
+ sink: Sink.Sink<B, E | E2, R3>
1081
+ ): Effect.Effect<unknown, never, R | R2 | R3 | Scope.Scope> {
944
1082
  return this.withFork(
945
1083
  (fork) =>
946
1084
  Sink.withEarlyExit(sink, (sink) =>
947
1085
  this.i0.run(
948
1086
  Sink.make(
949
- (cause) => Cause.isInterruptedOnly(cause) ? sink.earlyExit : sink.onFailure(cause),
1087
+ (cause) =>
1088
+ Cause.isInterruptedOnly(cause)
1089
+ ? sink.earlyExit
1090
+ : sink.onFailure(cause),
950
1091
  (a) => fork(this.i1(a).run(sink))
951
1092
  )
952
1093
  )),
@@ -968,7 +1109,9 @@ class FlatMapWithStrategy<
968
1109
  return suspend(() => f(producer.source()))
969
1110
  }
970
1111
 
971
- const arr = Array.isArray(fx.i0.source) ? fx.i0.source : Array.from(fx.i0.source)
1112
+ const arr = Array.isArray(fx.i0.source)
1113
+ ? fx.i0.source
1114
+ : Array.from(fx.i0.source)
972
1115
  if (arr.length === 0) return empty
973
1116
  if (arr.length === 1) return f(arr[0])
974
1117
 
@@ -978,7 +1121,9 @@ class FlatMapWithStrategy<
978
1121
  case "Exhaust":
979
1122
  return f(arr[0])
980
1123
  case "ExhaustLatest":
981
- return arr.length > 1 ? continueWith(f(arr[0]), () => f(arr[arr.length - 1])) : f(arr[0])
1124
+ return arr.length > 1
1125
+ ? continueWith(f(arr[0]), () => f(arr[arr.length - 1]))
1126
+ : f(arr[0])
982
1127
  default:
983
1128
  return new FlatMapWithStrategy(fx, f, strategy, executionStrategy)
984
1129
  }
@@ -986,7 +1131,12 @@ class FlatMapWithStrategy<
986
1131
  return fromFxEffect(Effect.map(fx.i0.source, f))
987
1132
  } else if (isTransformer(fx) && fx.i1._tag === "Map") {
988
1133
  const { f: op } = fx.i1
989
- return new FlatMapWithStrategy(fx.i0, (a) => f(op(a)), strategy, executionStrategy)
1134
+ return new FlatMapWithStrategy(
1135
+ fx.i0,
1136
+ (a) => f(op(a)),
1137
+ strategy,
1138
+ executionStrategy
1139
+ )
990
1140
  } else {
991
1141
  return new FlatMapWithStrategy(fx, f, strategy, executionStrategy)
992
1142
  }
@@ -999,18 +1149,14 @@ export function fromFxEffect<B, E, R, E2, R2>(
999
1149
  return new FromFxEffect(effect)
1000
1150
  }
1001
1151
 
1002
- class FromFxEffect<
1003
- R,
1004
- E,
1005
- R2,
1006
- E2,
1007
- B
1008
- > extends FxBase<B, E | E2, R | R2> {
1152
+ class FromFxEffect<R, E, R2, E2, B> extends FxBase<B, E | E2, R | R2> {
1009
1153
  constructor(readonly i0: Effect.Effect<Fx<B, E2, R2>, E, R>) {
1010
1154
  super()
1011
1155
  }
1012
1156
 
1013
- run<R3>(sink: Sink.Sink<B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1157
+ run<R3>(
1158
+ sink: Sink.Sink<B, E | E2, R3>
1159
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1014
1160
  return Effect.matchCauseEffect(this.i0, {
1015
1161
  onFailure: (cause) => sink.onFailure(cause),
1016
1162
  onSuccess: (fx) => fx.run(sink)
@@ -1018,7 +1164,10 @@ class FromFxEffect<
1018
1164
  }
1019
1165
  }
1020
1166
 
1021
- export function gen<Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>, FX extends Fx<any, any, any>>(
1167
+ export function gen<
1168
+ Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>,
1169
+ FX extends Fx<any, any, any>
1170
+ >(
1022
1171
  f: (_: Effect.Adapter) => Generator<Y, FX, any>
1023
1172
  ): Fx<
1024
1173
  Fx.Success<FX>,
@@ -1031,7 +1180,10 @@ export function gen<Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>, FX
1031
1180
  type YieldWrapError<T> = T extends Utils.YieldWrap<Effect.Effect<infer _, infer E, any>> ? E : never
1032
1181
  type YieldWrapContext<T> = T extends Utils.YieldWrap<Effect.Effect<any, any, infer R>> ? R : never
1033
1182
 
1034
- export function genScoped<Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>, FX extends Fx<any, any, any>>(
1183
+ export function genScoped<
1184
+ Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>,
1185
+ FX extends Fx<any, any, any>
1186
+ >(
1035
1187
  f: (_: Effect.Adapter) => Generator<Y, FX, any>
1036
1188
  ): Fx<
1037
1189
  Fx.Success<FX>,
@@ -1048,19 +1200,17 @@ export function continueWith<A, E, R, B, E2, R2>(
1048
1200
  return ContinueWith.make(fx, f)
1049
1201
  }
1050
1202
 
1051
- class ContinueWith<
1052
- A,
1053
- E,
1054
- R,
1055
- R2,
1056
- E2,
1057
- B
1058
- > extends FxBase<A | B, E | E2, R | R2> {
1059
- constructor(readonly i0: Fx<A, E, R>, readonly i1: () => Fx<B, E2, R2>) {
1203
+ class ContinueWith<A, E, R, R2, E2, B> extends FxBase<A | B, E | E2, R | R2> {
1204
+ constructor(
1205
+ readonly i0: Fx<A, E, R>,
1206
+ readonly i1: () => Fx<B, E2, R2>
1207
+ ) {
1060
1208
  super()
1061
1209
  }
1062
1210
 
1063
- run<R3>(sink: Sink.Sink<A | B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1211
+ run<R3>(
1212
+ sink: Sink.Sink<A | B, E | E2, R3>
1213
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1064
1214
  return Effect.flatMap(this.i0.run(sink), () => this.i1().run(sink))
1065
1215
  }
1066
1216
 
@@ -1090,19 +1240,17 @@ export function orElseCause<A, E, R, B, E2, R2>(
1090
1240
  return OrElseCause.make(fx, f)
1091
1241
  }
1092
1242
 
1093
- class OrElseCause<
1094
- A,
1095
- E,
1096
- R,
1097
- R2,
1098
- E2,
1099
- B
1100
- > extends FxBase<A | B, E2, R | R2> {
1101
- constructor(readonly i0: Fx<A, E, R>, readonly i1: (cause: Cause.Cause<E>) => Fx<B, E2, R2>) {
1243
+ class OrElseCause<A, E, R, R2, E2, B> extends FxBase<A | B, E2, R | R2> {
1244
+ constructor(
1245
+ readonly i0: Fx<A, E, R>,
1246
+ readonly i1: (cause: Cause.Cause<E>) => Fx<B, E2, R2>
1247
+ ) {
1102
1248
  super()
1103
1249
  }
1104
1250
 
1105
- run<R3>(sink: Sink.Sink<A | B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1251
+ run<R3>(
1252
+ sink: Sink.Sink<A | B, E | E2, R3>
1253
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1106
1254
  return Effect.catchAllCause(observe(this.i0, sink.onSuccess), (cause) => this.i1(cause).run(sink))
1107
1255
  }
1108
1256
 
@@ -1125,34 +1273,35 @@ export function orElse<A, E, R, B, E2, R2>(
1125
1273
  return OrElse.make(fx, f)
1126
1274
  }
1127
1275
 
1128
- class OrElse<
1129
- A,
1130
- E,
1131
- R,
1132
- R2,
1133
- E2,
1134
- B
1135
- > extends FxBase<A | B, E2, R | R2> {
1136
- constructor(readonly i0: Fx<A, E, R>, readonly i1: (error: E) => Fx<B, E2, R2>) {
1276
+ class OrElse<A, E, R, R2, E2, B> extends FxBase<A | B, E2, R | R2> {
1277
+ constructor(
1278
+ readonly i0: Fx<A, E, R>,
1279
+ readonly i1: (error: E) => Fx<B, E2, R2>
1280
+ ) {
1137
1281
  super()
1138
1282
  }
1139
1283
 
1140
- run<R3>(sink: Sink.Sink<A | B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1284
+ run<R3>(
1285
+ sink: Sink.Sink<A | B, E | E2, R3>
1286
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1141
1287
  return Effect.catchAll(
1142
- Effect.asyncEffect<unknown, E, never, never, never, R | R2 | R3>((resume) =>
1143
- Effect.asVoid(Effect.zipRight(
1144
- this.i0.run(
1145
- Sink.make(
1146
- (cause) =>
1147
- Either.match(Cause.failureOrCause(cause), {
1148
- onLeft: (e) => Effect.succeed(resume(Effect.fail(e))),
1149
- onRight: (cause) => sink.onFailure(cause)
1150
- }),
1151
- sink.onSuccess
1288
+ Effect.asyncEffect<unknown, E, never, never, never, R | R2 | R3>(
1289
+ (resume) =>
1290
+ Effect.asVoid(
1291
+ Effect.zipRight(
1292
+ this.i0.run(
1293
+ Sink.make(
1294
+ (cause) =>
1295
+ Either.match(Cause.failureOrCause(cause), {
1296
+ onLeft: (e) => Effect.succeed(resume(Effect.fail(e))),
1297
+ onRight: (cause) => sink.onFailure(cause)
1298
+ }),
1299
+ sink.onSuccess
1300
+ )
1301
+ ),
1302
+ Effect.sync(() => resume(Effect.void))
1152
1303
  )
1153
- ),
1154
- Effect.sync(() => resume(Effect.void))
1155
- ))
1304
+ )
1156
1305
  ),
1157
1306
  (error: E) => this.i1(error).run(sink)
1158
1307
  )
@@ -1189,27 +1338,32 @@ function isSuspend<A, E, R>(fx: Fx<A, E, R>): fx is Suspend<A, E, R> {
1189
1338
  }
1190
1339
 
1191
1340
  class SuspendedTransformer<A, E, R, B, E2, R2> extends FxBase<B, E2, R | R2> {
1192
- constructor(readonly i0: () => Fx<A, E, R>, readonly i1: Op.Operator) {
1341
+ constructor(
1342
+ readonly i0: () => Fx<A, E, R>,
1343
+ readonly i1: Op.Operator
1344
+ ) {
1193
1345
  super()
1194
1346
  }
1195
1347
 
1196
- run<R3>(sink: Sink.Sink<B, E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1348
+ run<R3>(
1349
+ sink: Sink.Sink<B, E2, R3>
1350
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1197
1351
  return this.i0().run(Op.compileOperatorSink(this.i1, sink))
1198
1352
  }
1199
1353
  }
1200
1354
 
1201
- function isSuspendedTransformer<A, E, R>(fx: Fx<A, E, R>): fx is SuspendedTransformer<A, E, R, any, any, any> {
1355
+ function isSuspendedTransformer<A, E, R>(
1356
+ fx: Fx<A, E, R>
1357
+ ): fx is SuspendedTransformer<A, E, R, any, any, any> {
1202
1358
  return fx.constructor === SuspendedTransformer
1203
1359
  }
1204
1360
 
1205
- export function mergeWithStrategy<const FX extends ReadonlyArray<Fx<any, any, any>>>(
1361
+ export function mergeWithStrategy<
1362
+ const FX extends ReadonlyArray<Fx<any, any, any>>
1363
+ >(
1206
1364
  fx: FX,
1207
1365
  stategy: MergeStrategy
1208
- ): Fx<
1209
- Fx.Success<FX[number]>,
1210
- Fx.Error<FX[number]>,
1211
- Fx.Context<FX[number]>
1212
- > {
1366
+ ): Fx<Fx.Success<FX[number]>, Fx.Error<FX[number]>, Fx.Context<FX[number]>> {
1213
1367
  return MergeWithStrategy.make(fx, stategy)
1214
1368
  }
1215
1369
 
@@ -1232,7 +1386,9 @@ export function mergeOrdered<FX extends ReadonlyArray<Fx<any, any, any>>>(
1232
1386
  return mergeOrderedConcurrently(fx, Infinity)
1233
1387
  }
1234
1388
 
1235
- export function mergeOrderedConcurrently<FX extends ReadonlyArray<Fx<any, any, any>>>(
1389
+ export function mergeOrderedConcurrently<
1390
+ FX extends ReadonlyArray<Fx<any, any, any>>
1391
+ >(
1236
1392
  fx: FX,
1237
1393
  concurrency: number
1238
1394
  ): Fx<Fx.Success<FX[number]>, Fx.Error<FX[number]>, Fx.Context<FX[number]>> {
@@ -1252,7 +1408,10 @@ class MergeWithStrategy<
1252
1408
  Fx.Error<FX[number]>,
1253
1409
  Fx.Context<FX[number]>
1254
1410
  > {
1255
- constructor(readonly i0: FX, readonly i1: MergeStrategy) {
1411
+ constructor(
1412
+ readonly i0: FX,
1413
+ readonly i1: MergeStrategy
1414
+ ) {
1256
1415
  super()
1257
1416
  }
1258
1417
 
@@ -1261,9 +1420,17 @@ class MergeWithStrategy<
1261
1420
  ): Effect.Effect<unknown, never, Fx.Context<FX[number]> | R2> {
1262
1421
  switch (this.i1._tag) {
1263
1422
  case "Unordered":
1264
- return runUnordered(this.i0, sink, this.i1.concurrency === Infinity ? "unbounded" : this.i1.concurrency)
1423
+ return runUnordered(
1424
+ this.i0,
1425
+ sink,
1426
+ this.i1.concurrency === Infinity ? "unbounded" : this.i1.concurrency
1427
+ )
1265
1428
  case "Ordered":
1266
- return runOrdered(this.i0, sink, this.i1.concurrency === Infinity ? "unbounded" : this.i1.concurrency)
1429
+ return runOrdered(
1430
+ this.i0,
1431
+ sink,
1432
+ this.i1.concurrency === Infinity ? "unbounded" : this.i1.concurrency
1433
+ )
1267
1434
  case "Switch":
1268
1435
  return runSwitch(this.i0, sink)
1269
1436
  }
@@ -1272,68 +1439,64 @@ class MergeWithStrategy<
1272
1439
  static make<const FX extends ReadonlyArray<Fx<any, any, any>>>(
1273
1440
  fx: FX,
1274
1441
  strategy: MergeStrategy
1275
- ): Fx<
1276
- Fx.Success<FX[number]>,
1277
- Fx.Error<FX[number]>,
1278
- Fx.Context<FX[number]>
1279
- > {
1442
+ ): Fx<Fx.Success<FX[number]>, Fx.Error<FX[number]>, Fx.Context<FX[number]>> {
1280
1443
  if (fx.length === 0) return empty
1281
1444
  else if (fx.length === 1) return fx[0]
1282
- else return new MergeWithStrategy(fx.filter(Predicate.not(isEmpty)), strategy)
1445
+ else {
1446
+ return new MergeWithStrategy(fx.filter(Predicate.not(isEmpty)), strategy)
1447
+ }
1283
1448
  }
1284
1449
  }
1285
1450
 
1286
- function runUnordered<
1287
- const FX extends ReadonlyArray<Fx<any, any, any>>,
1288
- R2
1289
- >(
1451
+ function runUnordered<const FX extends ReadonlyArray<Fx<any, any, any>>, R2>(
1290
1452
  fx: FX,
1291
1453
  sink: Sink.Sink<any, any, R2>,
1292
1454
  concurrency: number | "unbounded"
1293
1455
  ): Effect.Effect<unknown, never, R2 | Fx.Context<FX[number]>> {
1294
- return Effect.forEach(fx, (fx) => fx.run(sink), { concurrency, discard: true })
1456
+ return Effect.forEach(fx, (fx) => fx.run(sink), {
1457
+ concurrency,
1458
+ discard: true
1459
+ })
1295
1460
  }
1296
1461
 
1297
- function runOrdered<
1298
- const FX extends ReadonlyArray<Fx<any, any, any>>,
1299
- R2
1300
- >(
1462
+ function runOrdered<const FX extends ReadonlyArray<Fx<any, any, any>>, R2>(
1301
1463
  fx: FX,
1302
1464
  sink: Sink.Sink<any, any, R2>,
1303
1465
  concurrency: number | "unbounded"
1304
1466
  ): Effect.Effect<unknown, never, R2 | Fx.Context<FX[number]>> {
1305
- return Effect.fiberIdWith(
1306
- (id) => {
1307
- const buffers = withBuffers(fx.length, sink, id)
1308
- return Effect.forEach(
1309
- fx,
1310
- (fx, i) =>
1311
- Effect.flatMap(
1312
- fx.run(
1313
- Sink.make(
1314
- (cause) => Cause.isInterruptedOnly(cause) ? buffers.onEnd(i) : sink.onFailure(cause),
1315
- (a) => buffers.onSuccess(i, a)
1316
- )
1317
- ),
1318
- () => buffers.onEnd(i)
1467
+ return Effect.fiberIdWith((id) => {
1468
+ const buffers = withBuffers(fx.length, sink, id)
1469
+ return Effect.forEach(
1470
+ fx,
1471
+ (fx, i) =>
1472
+ Effect.flatMap(
1473
+ fx.run(
1474
+ Sink.make(
1475
+ (cause) =>
1476
+ Cause.isInterruptedOnly(cause)
1477
+ ? buffers.onEnd(i)
1478
+ : sink.onFailure(cause),
1479
+ (a) => buffers.onSuccess(i, a)
1480
+ )
1319
1481
  ),
1320
- {
1321
- concurrency,
1322
- discard: true
1323
- }
1324
- )
1325
- }
1326
- )
1482
+ () => buffers.onEnd(i)
1483
+ ),
1484
+ {
1485
+ concurrency,
1486
+ discard: true
1487
+ }
1488
+ )
1489
+ })
1327
1490
  }
1328
1491
 
1329
- function runSwitch<
1330
- const FX extends ReadonlyArray<Fx<any, any, any>>,
1331
- R2
1332
- >(
1492
+ function runSwitch<const FX extends ReadonlyArray<Fx<any, any, any>>, R2>(
1333
1493
  fx: FX,
1334
1494
  sink: Sink.Sink<any, any, R2>
1335
1495
  ): Effect.Effect<unknown, never, R2 | Fx.Context<FX[number]>> {
1336
- return Effect.forEach(fx, (fx) => fx.run(sink), { concurrency: 1, discard: true })
1496
+ return Effect.forEach(fx, (fx) => fx.run(sink), {
1497
+ concurrency: 1,
1498
+ discard: true
1499
+ })
1337
1500
  }
1338
1501
 
1339
1502
  export function takeWhile<A, E, R>(
@@ -1351,7 +1514,10 @@ export function takeUntil<A, E, R>(
1351
1514
  }
1352
1515
 
1353
1516
  class TakeWhile<A, E, R> extends FxBase<A, E, R> {
1354
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Predicate.Predicate<A>) {
1517
+ constructor(
1518
+ readonly i0: Fx<A, E, R>,
1519
+ readonly i1: Predicate.Predicate<A>
1520
+ ) {
1355
1521
  super()
1356
1522
  }
1357
1523
 
@@ -1359,7 +1525,10 @@ class TakeWhile<A, E, R> extends FxBase<A, E, R> {
1359
1525
  return Sink.takeWhile(sink, this.i1, (s) => this.i0.run(s))
1360
1526
  }
1361
1527
 
1362
- static make<A, E, R>(fx: Fx<A, E, R>, predicate: Predicate.Predicate<A>): Fx<A, E, R> {
1528
+ static make<A, E, R>(
1529
+ fx: Fx<A, E, R>,
1530
+ predicate: Predicate.Predicate<A>
1531
+ ): Fx<A, E, R> {
1363
1532
  if (isEmpty(fx) || isNever(fx)) return fx
1364
1533
  else {
1365
1534
  return new TakeWhile(fx, predicate)
@@ -1382,7 +1551,10 @@ export function dropUntil<A, E, R>(
1382
1551
  }
1383
1552
 
1384
1553
  class DropUntil<A, E, R> extends FxBase<A, E, R> {
1385
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Predicate.Predicate<A>) {
1554
+ constructor(
1555
+ readonly i0: Fx<A, E, R>,
1556
+ readonly i1: Predicate.Predicate<A>
1557
+ ) {
1386
1558
  super()
1387
1559
  }
1388
1560
 
@@ -1390,7 +1562,10 @@ class DropUntil<A, E, R> extends FxBase<A, E, R> {
1390
1562
  return this.i0.run(Sink.dropWhile(sink, this.i1))
1391
1563
  }
1392
1564
 
1393
- static make<A, E, R>(fx: Fx<A, E, R>, predicate: Predicate.Predicate<A>): Fx<A, E, R> {
1565
+ static make<A, E, R>(
1566
+ fx: Fx<A, E, R>,
1567
+ predicate: Predicate.Predicate<A>
1568
+ ): Fx<A, E, R> {
1394
1569
  if (isEmpty(fx) || isNever(fx)) return fx
1395
1570
  else {
1396
1571
  return new DropUntil(fx, predicate)
@@ -1406,7 +1581,10 @@ export function dropAfter<A, E, R>(
1406
1581
  }
1407
1582
 
1408
1583
  class DropAfter<A, E, R> extends FxBase<A, E, R> {
1409
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Predicate.Predicate<A>) {
1584
+ constructor(
1585
+ readonly i0: Fx<A, E, R>,
1586
+ readonly i1: Predicate.Predicate<A>
1587
+ ) {
1410
1588
  super()
1411
1589
  }
1412
1590
 
@@ -1414,7 +1592,10 @@ class DropAfter<A, E, R> extends FxBase<A, E, R> {
1414
1592
  return Sink.dropAfter(sink, this.i1, (s) => this.i0.run(s))
1415
1593
  }
1416
1594
 
1417
- static make<A, E, R>(fx: Fx<A, E, R>, predicate: Predicate.Predicate<A>): Fx<A, E, R> {
1595
+ static make<A, E, R>(
1596
+ fx: Fx<A, E, R>,
1597
+ predicate: Predicate.Predicate<A>
1598
+ ): Fx<A, E, R> {
1418
1599
  if (isEmpty(fx) || isNever(fx)) return fx
1419
1600
  else {
1420
1601
  return new DropAfter(fx, predicate)
@@ -1437,11 +1618,16 @@ export function takeUntilEffect<A, E, R, R2, E2>(
1437
1618
  }
1438
1619
 
1439
1620
  class TakeWhileEffect<A, E, R, R2, E2> extends FxBase<A, E | E2, R | R2> {
1440
- constructor(readonly i0: Fx<A, E, R>, readonly i1: (a: A) => Effect.Effect<boolean, E2, R2>) {
1621
+ constructor(
1622
+ readonly i0: Fx<A, E, R>,
1623
+ readonly i1: (a: A) => Effect.Effect<boolean, E2, R2>
1624
+ ) {
1441
1625
  super()
1442
1626
  }
1443
1627
 
1444
- run<R3>(sink: Sink.Sink<A, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1628
+ run<R3>(
1629
+ sink: Sink.Sink<A, E | E2, R3>
1630
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1445
1631
  return Sink.takeWhileEffect(sink, this.i1, (s) => this.i0.run(s))
1446
1632
  }
1447
1633
 
@@ -1471,7 +1657,10 @@ export function dropUntilEffect<A, E, R>(
1471
1657
  }
1472
1658
 
1473
1659
  class DropWhileEffect<A, E, R> extends FxBase<A, E, R> {
1474
- constructor(readonly i0: Fx<A, E, R>, readonly i1: (a: A) => Effect.Effect<boolean, E, R>) {
1660
+ constructor(
1661
+ readonly i0: Fx<A, E, R>,
1662
+ readonly i1: (a: A) => Effect.Effect<boolean, E, R>
1663
+ ) {
1475
1664
  super()
1476
1665
  }
1477
1666
 
@@ -1498,11 +1687,16 @@ export function dropAfterEffect<A, E, R, R2, E2>(
1498
1687
  }
1499
1688
 
1500
1689
  class DropAfterEffect<A, E, R, R2, E2> extends FxBase<A, E | E2, R | R2> {
1501
- constructor(readonly i0: Fx<A, E, R>, readonly i1: (a: A) => Effect.Effect<boolean, E2, R2>) {
1690
+ constructor(
1691
+ readonly i0: Fx<A, E, R>,
1692
+ readonly i1: (a: A) => Effect.Effect<boolean, E2, R2>
1693
+ ) {
1502
1694
  super()
1503
1695
  }
1504
1696
 
1505
- run<R3>(sink: Sink.Sink<A, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
1697
+ run<R3>(
1698
+ sink: Sink.Sink<A, E | E2, R3>
1699
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
1506
1700
  return this.i0.run(Sink.dropAfterEffect(sink, this.i1))
1507
1701
  }
1508
1702
 
@@ -1528,7 +1722,10 @@ export function since<A, E, R, B, E2, R2>(
1528
1722
  fx: Fx<A, E, R>,
1529
1723
  window: Fx<B, E2, R2>
1530
1724
  ): Fx<A, E | E2, R | R2 | Scope.Scope> {
1531
- return During.make(fx, map(window, () => never))
1725
+ return During.make(
1726
+ fx,
1727
+ map(window, () => never)
1728
+ )
1532
1729
  }
1533
1730
 
1534
1731
  export function until<A, E, R, B, E2, R2>(
@@ -1538,12 +1735,21 @@ export function until<A, E, R, B, E2, R2>(
1538
1735
  return During.make(fx, succeed(window))
1539
1736
  }
1540
1737
 
1541
- class During<A, E, R, B, E2, R2, E3, R3> extends FxBase<A, E | E2 | E3, R | R2 | R3 | Scope.Scope> {
1542
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Fx<Fx<B, E3, R3>, E2, R2>) {
1738
+ class During<A, E, R, B, E2, R2, E3, R3> extends FxBase<
1739
+ A,
1740
+ E | E2 | E3,
1741
+ R | R2 | R3 | Scope.Scope
1742
+ > {
1743
+ constructor(
1744
+ readonly i0: Fx<A, E, R>,
1745
+ readonly i1: Fx<Fx<B, E3, R3>, E2, R2>
1746
+ ) {
1543
1747
  super()
1544
1748
  }
1545
1749
 
1546
- run<R4>(sink: Sink.Sink<A, E | E2 | E3, R4>): Effect.Effect<unknown, never, R | R2 | R3 | R4 | Scope.Scope> {
1750
+ run<R4>(
1751
+ sink: Sink.Sink<A, E | E2 | E3, R4>
1752
+ ): Effect.Effect<unknown, never, R | R2 | R3 | R4 | Scope.Scope> {
1547
1753
  return withScopedFork(
1548
1754
  (fork) =>
1549
1755
  Sink.withEarlyExit(sink, (s) => {
@@ -1556,7 +1762,9 @@ class During<A, E, R, B, E2, R2, E3, R3> extends FxBase<A, E | E2 | E3, R | R2 |
1556
1762
  take(this.i1, 1).run(
1557
1763
  Sink.make(onFailure, (nested) => {
1558
1764
  taking = true
1559
- return take(nested, 1).run(Sink.make(onFailure, () => s.earlyExit))
1765
+ return take(nested, 1).run(
1766
+ Sink.make(onFailure, () => s.earlyExit)
1767
+ )
1560
1768
  })
1561
1769
  )
1562
1770
  ),
@@ -1565,10 +1773,7 @@ class During<A, E, R, B, E2, R2, E3, R3> extends FxBase<A, E | E2 | E3, R | R2 |
1565
1773
  // Allow fibers to start
1566
1774
  adjustTime(1),
1567
1775
  this.i0.run(
1568
- Sink.make(
1569
- onFailure,
1570
- (a) => taking ? s.onSuccess(a) : Effect.void
1571
- )
1776
+ Sink.make(onFailure, (a) => taking ? s.onSuccess(a) : Effect.void)
1572
1777
  )
1573
1778
  )
1574
1779
  )
@@ -1590,7 +1795,9 @@ class During<A, E, R, B, E2, R2, E3, R3> extends FxBase<A, E | E2 | E3, R | R2 |
1590
1795
 
1591
1796
  export function middleware<A, E, R, R3>(
1592
1797
  fx: Fx<A, E, R>,
1593
- effect: (effect: Effect.Effect<unknown, never, R>) => Effect.Effect<unknown, never, R3>,
1798
+ effect: (
1799
+ effect: Effect.Effect<unknown, never, R>
1800
+ ) => Effect.Effect<unknown, never, R3>,
1594
1801
  sink?: (sink: Sink.Sink<A, E>) => Sink.Sink<A, E, R>
1595
1802
  ): Fx<A, E, R3> {
1596
1803
  return new Middleware(fx, effect, sink)
@@ -1605,7 +1812,9 @@ export function onExit<A, E, R, R2>(
1605
1812
 
1606
1813
  export function onInterrupt<A, E, R, R2>(
1607
1814
  fx: Fx<A, E, R>,
1608
- f: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<unknown, never, R2>
1815
+ f: (
1816
+ interruptors: HashSet.HashSet<FiberId.FiberId>
1817
+ ) => Effect.Effect<unknown, never, R2>
1609
1818
  ): Fx<A, E, R | R2> {
1610
1819
  return middleware(fx, Effect.onInterrupt(f))
1611
1820
  }
@@ -1617,7 +1826,9 @@ export function onError<A, E, R, R2>(
1617
1826
  return middleware(fx, Effect.onError(f))
1618
1827
  }
1619
1828
 
1620
- export const scoped = <A, E, R>(fx: Fx<A, E, R>): Fx<A, E, Exclude<R, Scope.Scope>> => middleware(fx, Effect.scoped)
1829
+ export const scoped = <A, E, R>(
1830
+ fx: Fx<A, E, R>
1831
+ ): Fx<A, E, Exclude<R, Scope.Scope>> => middleware(fx, Effect.scoped)
1621
1832
 
1622
1833
  export function annotateLogs<A, E, R>(
1623
1834
  fx: Fx<A, E, R>,
@@ -1735,7 +1946,9 @@ export function withTracer<A, E, R>(
1735
1946
  class Middleware<A, E, R, R2> extends FxBase<A, E, R2> {
1736
1947
  constructor(
1737
1948
  readonly i0: Fx<A, E, R>,
1738
- readonly i1: (effect: Effect.Effect<unknown, never, R>) => Effect.Effect<unknown, never, R2>,
1949
+ readonly i1: (
1950
+ effect: Effect.Effect<unknown, never, R>
1951
+ ) => Effect.Effect<unknown, never, R2>,
1739
1952
  readonly i2?: (sink: Sink.Sink<A, E>) => Sink.Sink<A, E, R>
1740
1953
  ) {
1741
1954
  super()
@@ -1758,16 +1971,25 @@ export function acquireUseRelease<A, E, R, B, E2, R2, C, E3, R3>(
1758
1971
  return new AcquireUseRelease(acquire, use, release)
1759
1972
  }
1760
1973
 
1761
- class AcquireUseRelease<A, E, R, B, E2, R2, C, E3, R3> extends FxBase<B, E | E2 | E3, R | R2 | R3> {
1974
+ class AcquireUseRelease<A, E, R, B, E2, R2, C, E3, R3> extends FxBase<
1975
+ B,
1976
+ E | E2 | E3,
1977
+ R | R2 | R3
1978
+ > {
1762
1979
  constructor(
1763
1980
  readonly acquire: Effect.Effect<A, E, R>,
1764
1981
  readonly use: (a: A) => Fx<B, E2, R2>,
1765
- readonly release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<C, E3, R3>
1982
+ readonly release: (
1983
+ a: A,
1984
+ exit: Exit.Exit<unknown, unknown>
1985
+ ) => Effect.Effect<C, E3, R3>
1766
1986
  ) {
1767
1987
  super()
1768
1988
  }
1769
1989
 
1770
- run<R4>(sink: Sink.Sink<B, E | E2 | E3, R4>): Effect.Effect<unknown, never, R | R2 | R3 | R4> {
1990
+ run<R4>(
1991
+ sink: Sink.Sink<B, E | E2 | E3, R4>
1992
+ ): Effect.Effect<unknown, never, R | R2 | R3 | R4> {
1771
1993
  return Effect.catchAllCause(
1772
1994
  Effect.acquireUseRelease(
1773
1995
  this.acquire,
@@ -1791,10 +2013,11 @@ export function withSpan<A, E, R>(
1791
2013
  } = {}
1792
2014
  ): Fx<A, E, R> {
1793
2015
  return acquireUseRelease(
1794
- Effect.flatMap(
1795
- Effect.optionFromOptional(Effect.currentSpan),
1796
- (parent) => Effect.makeSpan(name, { ...options, parent: options?.parent || Option.getOrUndefined(parent) } as any)
1797
- ),
2016
+ Effect.flatMap(Effect.optionFromOptional(Effect.currentSpan), (parent) =>
2017
+ Effect.makeSpan(name, {
2018
+ ...options,
2019
+ parent: options?.parent || Option.getOrUndefined(parent)
2020
+ } as any)),
1798
2021
  (span) =>
1799
2022
  middleware(
1800
2023
  self,
@@ -1846,17 +2069,28 @@ export function provide<A, E, R, R2 = never, E2 = never, S = never>(
1846
2069
  fx: Fx<A, E, R>,
1847
2070
  provide: Layer.Layer<S, E2, R2> | Context.Context<S> | Runtime.Runtime<S>
1848
2071
  ): Fx<A, E | E2, Exclude<R, S> | R2> {
1849
- if (Layer.isLayer(provide)) return provideLayer(fx, provide as Layer.Layer<S, E2, R2>)
1850
- else if (Context.isContext(provide)) return provideContext(fx, provide as Context.Context<S>)
1851
- else return provideRuntime(fx, provide as Runtime.Runtime<S>)
2072
+ if (Layer.isLayer(provide)) {
2073
+ return provideLayer(fx, provide as Layer.Layer<S, E2, R2>)
2074
+ } else if (Context.isContext(provide)) {
2075
+ return provideContext(fx, provide as Context.Context<S>)
2076
+ } else return provideRuntime(fx, provide as Runtime.Runtime<S>)
1852
2077
  }
1853
2078
 
1854
- class ProvideFx<A, E, R, S, E2, R2> extends FxBase<A, E | E2, R2 | Exclude<R, S>> {
1855
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Provide.Provide<S, E2, R2>) {
2079
+ class ProvideFx<A, E, R, S, E2, R2> extends FxBase<
2080
+ A,
2081
+ E | E2,
2082
+ R2 | Exclude<R, S>
2083
+ > {
2084
+ constructor(
2085
+ readonly i0: Fx<A, E, R>,
2086
+ readonly i1: Provide.Provide<S, E2, R2>
2087
+ ) {
1856
2088
  super()
1857
2089
  }
1858
2090
 
1859
- run<R3>(sink: Sink.Sink<A, E | E2, R3>): Effect.Effect<unknown, never, R2 | R3 | Exclude<R, S>> {
2091
+ run<R3>(
2092
+ sink: Sink.Sink<A, E | E2, R3>
2093
+ ): Effect.Effect<unknown, never, R2 | R3 | Exclude<R, S>> {
1860
2094
  return Effect.acquireUseRelease(
1861
2095
  Scope.make(),
1862
2096
  (scope) =>
@@ -1881,7 +2115,9 @@ class ProvideFx<A, E, R, S, E2, R2> extends FxBase<A, E | E2, R2 | Exclude<R, S>
1881
2115
  }
1882
2116
  }
1883
2117
 
1884
- function isProvideFx<A, E, R>(u: Fx<A, E, R>): u is ProvideFx<A, E, R, R, E, never> {
2118
+ function isProvideFx<A, E, R>(
2119
+ u: Fx<A, E, R>
2120
+ ): u is ProvideFx<A, E, R, R, E, never> {
1885
2121
  return u.constructor === ProvideFx
1886
2122
  }
1887
2123
 
@@ -1973,7 +2209,9 @@ export function filterErrorEffect<A, E, R, R2, E2>(
1973
2209
 
1974
2210
  export function filterMapCauseEffect<A, E, R, R2, E2, E3>(
1975
2211
  fx: Fx<A, E, R>,
1976
- f: (cause: Cause.Cause<E>) => Effect.Effect<Option.Option<Cause.Cause<E3>>, E2, R2>
2212
+ f: (
2213
+ cause: Cause.Cause<E>
2214
+ ) => Effect.Effect<Option.Option<Cause.Cause<E3>>, E2, R2>
1977
2215
  ): Fx<A, E2 | E3, R | R2> {
1978
2216
  return new TransformerCause(fx, EffectOp.FilterMapEffect(f))
1979
2217
  }
@@ -2015,7 +2253,10 @@ export function loopError<A, E, R, B, C>(
2015
2253
  export function loopCauseEffect<A, E, R, B, E2, R2, C>(
2016
2254
  fx: Fx<A, E, R>,
2017
2255
  seed: B,
2018
- f: (b: B, cause: Cause.Cause<E>) => Effect.Effect<readonly [Cause.Cause<C>, B], E2, R2>
2256
+ f: (
2257
+ b: B,
2258
+ cause: Cause.Cause<E>
2259
+ ) => Effect.Effect<readonly [Cause.Cause<C>, B], E2, R2>
2019
2260
  ): Fx<A, E2 | C, R | R2> {
2020
2261
  return new TransformerCause(fx, EffectLoopOp.LoopEffectOperator(seed, f))
2021
2262
  }
@@ -2035,7 +2276,10 @@ export function loopErrorEffect<A, E, R, B, E2, R2, C>(
2035
2276
  export function filterMapLoopCause<A, E, R, B, C>(
2036
2277
  fx: Fx<A, E, R>,
2037
2278
  seed: B,
2038
- f: (b: B, cause: Cause.Cause<E>) => readonly [Option.Option<Cause.Cause<C>>, B]
2279
+ f: (
2280
+ b: B,
2281
+ cause: Cause.Cause<E>
2282
+ ) => readonly [Option.Option<Cause.Cause<C>>, B]
2039
2283
  ): Fx<A, C, R> {
2040
2284
  return new TransformerCause(fx, SyncLoopOp.FilterMapLoopOperator(seed, f))
2041
2285
  }
@@ -2058,9 +2302,15 @@ export function filterMapLoopError<A, E, R, B, C>(
2058
2302
  export function filterMapLoopCauseEffect<A, E, R, B, E2, R2, C>(
2059
2303
  fx: Fx<A, E, R>,
2060
2304
  seed: B,
2061
- f: (b: B, cause: Cause.Cause<E>) => Effect.Effect<readonly [Option.Option<Cause.Cause<C>>, B], E2, R2>
2305
+ f: (
2306
+ b: B,
2307
+ cause: Cause.Cause<E>
2308
+ ) => Effect.Effect<readonly [Option.Option<Cause.Cause<C>>, B], E2, R2>
2062
2309
  ): Fx<A, E2 | C, R | R2> {
2063
- return new TransformerCause(fx, EffectLoopOp.FilterMapLoopEffectOperator(seed, f))
2310
+ return new TransformerCause(
2311
+ fx,
2312
+ EffectLoopOp.FilterMapLoopEffectOperator(seed, f)
2313
+ )
2064
2314
  }
2065
2315
 
2066
2316
  export function filterMapLoopErrorEffect<A, E, R, B, E2, R2, C>(
@@ -2076,7 +2326,10 @@ export function filterMapLoopErrorEffect<A, E, R, B, E2, R2, C>(
2076
2326
  }
2077
2327
 
2078
2328
  class TransformerCause<A, E, R, R2, E2> extends FxBase<A, E2, R | R2> {
2079
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Op.Operator) {
2329
+ constructor(
2330
+ readonly i0: Fx<A, E, R>,
2331
+ readonly i1: Op.Operator
2332
+ ) {
2080
2333
  super()
2081
2334
  }
2082
2335
 
@@ -2091,7 +2344,12 @@ export function flatMapCauseWithStrategy<A, E, R, B, E2, R2>(
2091
2344
  flattenStrategy: FlattenStrategy,
2092
2345
  executionStrategy: ExecutionStrategy.ExecutionStrategy = ExecutionStrategy.sequential
2093
2346
  ): Fx<A | B, E2, R | R2 | Scope.Scope> {
2094
- return new FlatMapCauseWithStrategy(fx, f, flattenStrategy, executionStrategy)
2347
+ return new FlatMapCauseWithStrategy(
2348
+ fx,
2349
+ f,
2350
+ flattenStrategy,
2351
+ executionStrategy
2352
+ )
2095
2353
  }
2096
2354
 
2097
2355
  export function flatMapErrorWithStrategy<A, E, R, B, E2, R2>(
@@ -2150,7 +2408,12 @@ export function flatMapCauseConcurrently<A, E, R, B, E2, R2>(
2150
2408
  concurrency: number,
2151
2409
  executionStrategy?: ExecutionStrategy.ExecutionStrategy
2152
2410
  ): Fx<A | B, E2, R | R2 | Scope.Scope> {
2153
- return flatMapCauseWithStrategy(fx, f, Bounded(concurrency), executionStrategy)
2411
+ return flatMapCauseWithStrategy(
2412
+ fx,
2413
+ f,
2414
+ Bounded(concurrency),
2415
+ executionStrategy
2416
+ )
2154
2417
  }
2155
2418
 
2156
2419
  export function flatMapErrorConcurrently<A, E, R, B, E2, R2>(
@@ -2159,7 +2422,12 @@ export function flatMapErrorConcurrently<A, E, R, B, E2, R2>(
2159
2422
  concurrency: number,
2160
2423
  executionStrategy?: ExecutionStrategy.ExecutionStrategy
2161
2424
  ): Fx<A | B, E2, R | R2 | Scope.Scope> {
2162
- return flatMapErrorWithStrategy(fx, f, Bounded(concurrency), executionStrategy)
2425
+ return flatMapErrorWithStrategy(
2426
+ fx,
2427
+ f,
2428
+ Bounded(concurrency),
2429
+ executionStrategy
2430
+ )
2163
2431
  }
2164
2432
 
2165
2433
  export function exhaustMapCause<A, E, R, B, E2, R2>(
@@ -2194,19 +2462,13 @@ export function exhaustMapLatestError<A, E, R, B, E2, R2>(
2194
2462
  return flatMapErrorWithStrategy(fx, f, ExhaustLatest, executionStrategy)
2195
2463
  }
2196
2464
 
2197
- class FlatMapCauseWithStrategy<
2198
- A,
2199
- E,
2200
- R,
2201
- R2,
2465
+ class FlatMapCauseWithStrategy<A, E, R, R2, E2, B> extends FxBase<
2466
+ A | B,
2202
2467
  E2,
2203
- B
2204
- > extends FxBase<A | B, E2, R | R2 | Scope.Scope> {
2468
+ R | R2 | Scope.Scope
2469
+ > {
2205
2470
  private withFork: <A, E, R>(
2206
- f: (
2207
- fork: FxFork,
2208
- scope: Scope.Scope
2209
- ) => Effect.Effect<A, E, R>,
2471
+ f: (fork: FxFork, scope: Scope.Scope) => Effect.Effect<A, E, R>,
2210
2472
  executionStrategy: ExecutionStrategy.ExecutionStrategy
2211
2473
  ) => Effect.Effect<void, E, Scope.Scope | R>
2212
2474
 
@@ -2221,30 +2483,29 @@ class FlatMapCauseWithStrategy<
2221
2483
  this.withFork = withFlattenStrategy(this.i2)
2222
2484
  }
2223
2485
 
2224
- run<R3>(sink: Sink.Sink<A | B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3 | Scope.Scope> {
2486
+ run<R3>(
2487
+ sink: Sink.Sink<A | B, E | E2, R3>
2488
+ ): Effect.Effect<unknown, never, R | R2 | R3 | Scope.Scope> {
2225
2489
  return this.withFork(
2226
- (fork) => this.i0.run(Sink.make((cause) => fork(this.i1(cause).run(sink)), (a) => sink.onSuccess(a))),
2490
+ (fork) =>
2491
+ this.i0.run(
2492
+ Sink.make(
2493
+ (cause) => fork(this.i1(cause).run(sink)),
2494
+ (a) => sink.onSuccess(a)
2495
+ )
2496
+ ),
2227
2497
  this.i3
2228
2498
  )
2229
2499
  }
2230
2500
  }
2231
2501
 
2232
- class MatchWithStrategy<
2233
- A,
2234
- E,
2235
- R,
2236
- R2,
2237
- E2,
2238
- B,
2239
- R3,
2240
- E3,
2241
- C
2242
- > extends FxBase<B | C, E2 | E3, R | R2 | R3 | Scope.Scope> {
2502
+ class MatchWithStrategy<A, E, R, R2, E2, B, R3, E3, C> extends FxBase<
2503
+ B | C,
2504
+ E2 | E3,
2505
+ R | R2 | R3 | Scope.Scope
2506
+ > {
2243
2507
  private withFork: <A, E, R>(
2244
- f: (
2245
- fork: FxFork,
2246
- scope: Scope.Scope
2247
- ) => Effect.Effect<A, E, R>,
2508
+ f: (fork: FxFork, scope: Scope.Scope) => Effect.Effect<A, E, R>,
2248
2509
  executionStrategy: ExecutionStrategy.ExecutionStrategy
2249
2510
  ) => Effect.Effect<void, E, Scope.Scope | R>
2250
2511
 
@@ -2260,13 +2521,17 @@ class MatchWithStrategy<
2260
2521
  this.withFork = withFlattenStrategy(this.i3)
2261
2522
  }
2262
2523
 
2263
- run<R4>(sink: Sink.Sink<B | C, E2 | E3, R4>): Effect.Effect<unknown, never, R | R2 | R3 | R4 | Scope.Scope> {
2524
+ run<R4>(
2525
+ sink: Sink.Sink<B | C, E2 | E3, R4>
2526
+ ): Effect.Effect<unknown, never, R | R2 | R3 | R4 | Scope.Scope> {
2264
2527
  return this.withFork(
2265
2528
  (fork) =>
2266
- this.i0.run(Sink.make(
2267
- (cause) => fork(this.i1(cause).run(sink)),
2268
- (a) => fork(this.i2(a).run(sink))
2269
- )),
2529
+ this.i0.run(
2530
+ Sink.make(
2531
+ (cause) => fork(this.i1(cause).run(sink)),
2532
+ (a) => fork(this.i2(a).run(sink))
2533
+ )
2534
+ ),
2270
2535
  this.i4
2271
2536
  )
2272
2537
  }
@@ -2301,7 +2566,11 @@ export type MatchErrorOptions<E, A, B, E2, R2, C, E3, R3> = {
2301
2566
  export function matchErrorWithStrategy<A, E, R, B, E2, R2, C, E3, R3>(
2302
2567
  fx: Fx<A, E, R>,
2303
2568
  flattenStrategy: FlattenStrategy,
2304
- { executionStrategy, onFailure, onSuccess }: MatchErrorOptions<E, A, B, E2, R2, C, E3, R3>
2569
+ {
2570
+ executionStrategy,
2571
+ onFailure,
2572
+ onSuccess
2573
+ }: MatchErrorOptions<E, A, B, E2, R2, C, E3, R3>
2305
2574
  ): Fx<B | C, E2 | E3, R | R2 | R3 | Scope.Scope> {
2306
2575
  return new MatchWithStrategy(
2307
2576
  fx,
@@ -2412,20 +2681,18 @@ class Tuple<const FX extends ReadonlyArray<Fx<any, any, any>>> extends FxBase<
2412
2681
  }
2413
2682
 
2414
2683
  run<R2>(
2415
- sink: Sink.Sink<{ readonly [K in keyof FX]: Fx.Success<FX[K]> }, Fx.Error<FX[number]>, R2>
2684
+ sink: Sink.Sink<
2685
+ { readonly [K in keyof FX]: Fx.Success<FX[K]> },
2686
+ Fx.Error<FX[number]>,
2687
+ R2
2688
+ >
2416
2689
  ): Effect.Effect<unknown, never, Fx.Context<FX[number]> | R2> {
2417
2690
  return tupleSink(
2418
2691
  sink,
2419
2692
  (onSuccess) =>
2420
2693
  Effect.forEach(
2421
2694
  this.i0,
2422
- (fx, i) =>
2423
- fx.run(
2424
- Sink.make(
2425
- sink.onFailure,
2426
- (a) => onSuccess(i, a)
2427
- )
2428
- ),
2695
+ (fx, i) => fx.run(Sink.make(sink.onFailure, (a) => onSuccess(i, a))),
2429
2696
  UNBOUNDED
2430
2697
  ),
2431
2698
  this.i0.length
@@ -2433,7 +2700,9 @@ class Tuple<const FX extends ReadonlyArray<Fx<any, any, any>>> extends FxBase<
2433
2700
  }
2434
2701
  }
2435
2702
 
2436
- export function struct<const FX extends Readonly<Record<string, Fx<any, any, any>>>>(
2703
+ export function struct<
2704
+ const FX extends Readonly<Record<string, Fx<any, any, any>>>
2705
+ >(
2437
2706
  fx: FX
2438
2707
  ): Fx<
2439
2708
  {
@@ -2444,27 +2713,40 @@ export function struct<const FX extends Readonly<Record<string, Fx<any, any, any
2444
2713
  > {
2445
2714
  const entries: ReadonlyArray<readonly [keyof FX, FX[keyof FX]]> = Object.entries(fx) as any
2446
2715
 
2447
- return map(tuple(entries.map(([key, fx]) => map(fx, (a) => [key, a] as const))), Object.fromEntries)
2716
+ return map(
2717
+ tuple(entries.map(([key, fx]) => map(fx, (a) => [key, a] as const))),
2718
+ Object.fromEntries
2719
+ )
2448
2720
  }
2449
2721
 
2450
2722
  export function all<const FX extends ReadonlyArray<Fx<any, any, any>>>(
2451
2723
  fx: FX
2452
- ): Fx<{ readonly [K in keyof FX]: Fx.Success<FX[K]> }, Fx.Error<FX[number]>, Fx.Context<FX[number]>>
2724
+ ): Fx<
2725
+ { readonly [K in keyof FX]: Fx.Success<FX[K]> },
2726
+ Fx.Error<FX[number]>,
2727
+ Fx.Context<FX[number]>
2728
+ >
2453
2729
 
2454
- export function all<const FX extends Readonly<Record<string, Fx<any, any, any>>>>(
2730
+ export function all<
2731
+ const FX extends Readonly<Record<string, Fx<any, any, any>>>
2732
+ >(
2455
2733
  fx: FX
2456
- ): Fx<{ readonly [K in keyof FX]: Fx.Success<FX[K]> }, Fx.Error<FX[string]>, Fx.Context<FX[string]>>
2734
+ ): Fx<
2735
+ { readonly [K in keyof FX]: Fx.Success<FX[K]> },
2736
+ Fx.Error<FX[string]>,
2737
+ Fx.Context<FX[string]>
2738
+ >
2457
2739
 
2458
- export function all<const FX extends ReadonlyArray<Fx<any, any, any> | Readonly<Record<string, Fx<any, any, any>>>>>(
2459
- fx: FX
2460
- ): Fx<any, Fx.Error<FX[keyof FX]>, Fx.Context<FX[keyof FX]>> {
2740
+ export function all<
2741
+ const FX extends ReadonlyArray<
2742
+ Fx<any, any, any> | Readonly<Record<string, Fx<any, any, any>>>
2743
+ >
2744
+ >(fx: FX): Fx<any, Fx.Error<FX[keyof FX]>, Fx.Context<FX[keyof FX]>> {
2461
2745
  if (Array.isArray(fx)) return tuple(fx)
2462
2746
  else return struct(fx as any) as any
2463
2747
  }
2464
2748
 
2465
- export function exit<A, E, R>(
2466
- fx: Fx<A, E, R>
2467
- ): Fx<Exit.Exit<A, E>, never, R> {
2749
+ export function exit<A, E, R>(fx: Fx<A, E, R>): Fx<Exit.Exit<A, E>, never, R> {
2468
2750
  return new ExitFx(fx)
2469
2751
  }
2470
2752
 
@@ -2473,9 +2755,14 @@ class ExitFx<A, E, R> extends FxBase<Exit.Exit<A, E>, never, R> {
2473
2755
  super()
2474
2756
  }
2475
2757
 
2476
- run<R2>(sink: Sink.Sink<Exit.Exit<A, E>, never, R2>): Effect.Effect<unknown, never, R | R2> {
2758
+ run<R2>(
2759
+ sink: Sink.Sink<Exit.Exit<A, E>, never, R2>
2760
+ ): Effect.Effect<unknown, never, R | R2> {
2477
2761
  return this.i0.run(
2478
- Sink.make((cause) => sink.onSuccess(Exit.failCause(cause)), (a) => sink.onSuccess(Exit.succeed(a)))
2762
+ Sink.make(
2763
+ (cause) => sink.onSuccess(Exit.failCause(cause)),
2764
+ (a) => sink.onSuccess(Exit.succeed(a))
2765
+ )
2479
2766
  )
2480
2767
  }
2481
2768
  }
@@ -2487,7 +2774,10 @@ export function toEnqueue<A, E, R, R2 = never>(
2487
2774
  return observe(fx, (a) => queue.offer(a))
2488
2775
  }
2489
2776
 
2490
- export function debounce<A, E, R>(fx: Fx<A, E, R>, delay: Duration.DurationInput): Fx<A, E, R | Scope.Scope> {
2777
+ export function debounce<A, E, R>(
2778
+ fx: Fx<A, E, R>,
2779
+ delay: Duration.DurationInput
2780
+ ): Fx<A, E, R | Scope.Scope> {
2491
2781
  return switchMapEffect(fx, (a) => Effect.as(Effect.sleep(delay), a))
2492
2782
  }
2493
2783
 
@@ -2495,11 +2785,17 @@ function emitAndSleep<A>(value: A, delay: Duration.DurationInput) {
2495
2785
  return make<A>((sink) => Effect.zipRight(sink.onSuccess(value), Effect.sleep(delay)))
2496
2786
  }
2497
2787
 
2498
- export function throttle<A, E, R>(fx: Fx<A, E, R>, delay: Duration.DurationInput): Fx<A, E, R | Scope.Scope> {
2788
+ export function throttle<A, E, R>(
2789
+ fx: Fx<A, E, R>,
2790
+ delay: Duration.DurationInput
2791
+ ): Fx<A, E, R | Scope.Scope> {
2499
2792
  return exhaustMap(fx, (a) => emitAndSleep(a, delay))
2500
2793
  }
2501
2794
 
2502
- export function throttleLatest<A, E, R>(fx: Fx<A, E, R>, delay: Duration.DurationInput): Fx<A, E, R | Scope.Scope> {
2795
+ export function throttleLatest<A, E, R>(
2796
+ fx: Fx<A, E, R>,
2797
+ delay: Duration.DurationInput
2798
+ ): Fx<A, E, R | Scope.Scope> {
2503
2799
  return exhaustMapLatest(fx, (a) => emitAndSleep(a, delay))
2504
2800
  }
2505
2801
 
@@ -2515,20 +2811,33 @@ class FromAsyncIterable<A> extends FxBase<A, never, never> {
2515
2811
  run<R>(sink: Sink.Sink<A, never, R>): Effect.Effect<unknown, never, R> {
2516
2812
  return Effect.asyncEffect<unknown, never, R, R, never, R>((cb) => {
2517
2813
  const iterator = this.i0[Symbol.asyncIterator]()
2518
- const loop = (result: IteratorResult<A>): Effect.Effect<unknown, never, R> =>
2814
+ const loop = (
2815
+ result: IteratorResult<A>
2816
+ ): Effect.Effect<unknown, never, R> =>
2519
2817
  result.done
2520
2818
  ? Effect.sync(() => cb(Effect.void))
2521
- : Effect.zipRight(sink.onSuccess(result.value), Effect.flatMap(Effect.promise(() => iterator.next()), loop))
2819
+ : Effect.zipRight(
2820
+ sink.onSuccess(result.value),
2821
+ Effect.flatMap(
2822
+ Effect.promise(() => iterator.next()),
2823
+ loop
2824
+ )
2825
+ )
2522
2826
 
2523
- return Effect.asVoid(Effect.flatMap(
2524
- Effect.promise(() => iterator.next()),
2525
- loop
2526
- ))
2827
+ return Effect.asVoid(
2828
+ Effect.flatMap(
2829
+ Effect.promise(() => iterator.next()),
2830
+ loop
2831
+ )
2832
+ )
2527
2833
  })
2528
2834
  }
2529
2835
  }
2530
2836
 
2531
- export function findFirst<A, E, R>(fx: Fx<A, E, R>, predicate: Predicate.Predicate<A>): Effect.Effect<A, E, R> {
2837
+ export function findFirst<A, E, R>(
2838
+ fx: Fx<A, E, R>,
2839
+ predicate: Predicate.Predicate<A>
2840
+ ): Effect.Effect<A, E, R> {
2532
2841
  return Effect.asyncEffect((cb) =>
2533
2842
  observe(fx, (a) => predicate(a) ? Effect.sync(() => cb(Effect.succeed(a))) : Effect.void)
2534
2843
  )
@@ -2538,7 +2847,9 @@ export function first<A, E, R>(fx: Fx<A, E, R>): Effect.Effect<A, E, R> {
2538
2847
  return findFirst(fx, constTrue)
2539
2848
  }
2540
2849
 
2541
- export function either<A, E, R>(fx: Fx<A, E, R>): Fx<Either.Either<A, E>, never, R> {
2850
+ export function either<A, E, R>(
2851
+ fx: Fx<A, E, R>
2852
+ ): Fx<Either.Either<A, E>, never, R> {
2542
2853
  return new EitherFx(fx)
2543
2854
  }
2544
2855
 
@@ -2547,7 +2858,9 @@ class EitherFx<A, E, R> extends FxBase<Either.Either<A, E>, never, R> {
2547
2858
  super()
2548
2859
  }
2549
2860
 
2550
- run<R2>(sink: Sink.Sink<Either.Either<A, E>, never, R2>): Effect.Effect<unknown, never, R | R2> {
2861
+ run<R2>(
2862
+ sink: Sink.Sink<Either.Either<A, E>, never, R2>
2863
+ ): Effect.Effect<unknown, never, R | R2> {
2551
2864
  return this.i0.run(
2552
2865
  Sink.make(
2553
2866
  (cause) =>
@@ -2576,16 +2889,22 @@ export function mergeRace<A, E, R, B, E2, R2>(
2576
2889
  }
2577
2890
 
2578
2891
  class MergeRace<A, E, R, B, E2, R2> extends FxBase<A | B, E | E2, R | R2> {
2579
- constructor(readonly i0: Fx<A, E, R>, readonly i1: Fx<B, E2, R2>) {
2892
+ constructor(
2893
+ readonly i0: Fx<A, E, R>,
2894
+ readonly i1: Fx<B, E2, R2>
2895
+ ) {
2580
2896
  super()
2581
2897
  }
2582
2898
 
2583
- run<R3>(sink: Sink.Sink<A | B, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
2899
+ run<R3>(
2900
+ sink: Sink.Sink<A | B, E | E2, R3>
2901
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
2584
2902
  return Effect.gen(this, function*(_) {
2585
- const fiber1 = yield* Effect.fork(this.i0.run(Sink.make(
2586
- sink.onFailure,
2587
- (a) => Effect.flatMap(sink.onSuccess(a), () => Fiber.interrupt(fiber2))
2588
- )))
2903
+ const fiber1 = yield* Effect.fork(
2904
+ this.i0.run(
2905
+ Sink.make(sink.onFailure, (a) => Effect.flatMap(sink.onSuccess(a), () => Fiber.interrupt(fiber2)))
2906
+ )
2907
+ )
2589
2908
  const fiber2 = yield* Effect.fork(this.i1.run(sink))
2590
2909
 
2591
2910
  return yield* Fiber.joinAll([fiber1, fiber2])
@@ -2595,11 +2914,7 @@ class MergeRace<A, E, R, B, E2, R2> extends FxBase<A | B, E | E2, R | R2> {
2595
2914
 
2596
2915
  export function raceAll<const FX extends ReadonlyArray<Fx<any, any, any>>>(
2597
2916
  fx: FX
2598
- ): Fx<
2599
- Fx.Success<FX[number]>,
2600
- Fx.Error<FX[number]>,
2601
- Fx.Context<FX[number]>
2602
- > {
2917
+ ): Fx<Fx.Success<FX[number]>, Fx.Error<FX[number]>, Fx.Context<FX[number]>> {
2603
2918
  return new RaceAll(fx)
2604
2919
  }
2605
2920
 
@@ -2627,10 +2942,11 @@ class RaceAll<const FX extends ReadonlyArray<Fx<any, any, any>>> extends FxBase<
2627
2942
  const fibers: Array<Fiber.RuntimeFiber<unknown>> = []
2628
2943
 
2629
2944
  for (const fx of this.i0) {
2630
- const fiber: Fiber.RuntimeFiber<unknown> = yield* Effect.fork(fx.run(Sink.make(
2631
- sink.onFailure,
2632
- (a) => Effect.flatMap(Deferred.succeed(winner, fiber), () => sink.onSuccess(a))
2633
- )))
2945
+ const fiber: Fiber.RuntimeFiber<unknown> = yield* Effect.fork(
2946
+ fx.run(
2947
+ Sink.make(sink.onFailure, (a) => Effect.flatMap(Deferred.succeed(winner, fiber), () => sink.onSuccess(a)))
2948
+ )
2949
+ )
2634
2950
  fibers.push(fiber)
2635
2951
  }
2636
2952
 
@@ -2667,28 +2983,28 @@ class Snapshot<A, E, R, B, E2, R2, C> extends FxBase<C, E | E2, R | R2> {
2667
2983
  super()
2668
2984
  }
2669
2985
 
2670
- run<R3>(sink: Sink.Sink<C, E | E2, R3>): Effect.Effect<unknown, never, R | R2 | R3> {
2671
- return Effect.flatMap(
2672
- Ref.make(Option.none<B>()),
2673
- (ref) =>
2674
- Effect.all([
2675
- this.i1.run(Sink.make(
2676
- sink.onFailure,
2677
- (b) => Ref.set(ref, Option.some(b))
2678
- )),
2679
- this.i0.run(Sink.make(
2680
- sink.onFailure,
2681
- (a) =>
2986
+ run<R3>(
2987
+ sink: Sink.Sink<C, E | E2, R3>
2988
+ ): Effect.Effect<unknown, never, R | R2 | R3> {
2989
+ return Effect.flatMap(Ref.make(Option.none<B>()), (ref) =>
2990
+ Effect.all(
2991
+ [
2992
+ this.i1.run(
2993
+ Sink.make(sink.onFailure, (b) => Ref.set(ref, Option.some(b)))
2994
+ ),
2995
+ this.i0.run(
2996
+ Sink.make(sink.onFailure, (a) =>
2682
2997
  Effect.flatMap(
2683
2998
  Ref.get(ref),
2684
2999
  Option.match({
2685
3000
  onNone: () => Effect.void,
2686
3001
  onSome: (b) => sink.onSuccess(this.i2(a, b))
2687
3002
  })
2688
- )
2689
- ))
2690
- ], UNBOUNDED)
2691
- )
3003
+ ))
3004
+ )
3005
+ ],
3006
+ UNBOUNDED
3007
+ ))
2692
3008
  }
2693
3009
  }
2694
3010
 
@@ -2700,7 +3016,11 @@ export function snapshotEffect<A, E, R, B, E2, R2, C, E3, R3>(
2700
3016
  return new SnapshotEffect(fx, sampled, f)
2701
3017
  }
2702
3018
 
2703
- class SnapshotEffect<A, E, R, B, E2, R2, C, E3, R3> extends FxBase<C, E | E2 | E3, R | R2 | R3> {
3019
+ class SnapshotEffect<A, E, R, B, E2, R2, C, E3, R3> extends FxBase<
3020
+ C,
3021
+ E | E2 | E3,
3022
+ R | R2 | R3
3023
+ > {
2704
3024
  constructor(
2705
3025
  readonly i0: Fx<A, E, R>,
2706
3026
  readonly i1: Fx<B, E2, R2>,
@@ -2709,31 +3029,31 @@ class SnapshotEffect<A, E, R, B, E2, R2, C, E3, R3> extends FxBase<C, E | E2 | E
2709
3029
  super()
2710
3030
  }
2711
3031
 
2712
- run<R4>(sink: Sink.Sink<C, E | E2 | E3, R4>): Effect.Effect<unknown, never, R | R2 | R3 | R4> {
2713
- return Effect.flatMap(
2714
- Ref.make(Option.none<B>()),
2715
- (ref) =>
2716
- Effect.flatMap(
2717
- Effect.tap(
2718
- Effect.fork(
2719
- this.i1.run(Sink.make(
2720
- sink.onFailure,
2721
- (b) => Ref.set(ref, Option.some(b))
2722
- ))
2723
- ),
2724
- () =>
2725
- this.i0.run(Sink.make(sink.onFailure, (a) =>
3032
+ run<R4>(
3033
+ sink: Sink.Sink<C, E | E2 | E3, R4>
3034
+ ): Effect.Effect<unknown, never, R | R2 | R3 | R4> {
3035
+ return Effect.flatMap(Ref.make(Option.none<B>()), (ref) =>
3036
+ Effect.flatMap(
3037
+ Effect.tap(
3038
+ Effect.fork(
3039
+ this.i1.run(
3040
+ Sink.make(sink.onFailure, (b) => Ref.set(ref, Option.some(b)))
3041
+ )
3042
+ ),
3043
+ () =>
3044
+ this.i0.run(
3045
+ Sink.make(sink.onFailure, (a) =>
2726
3046
  Effect.flatMap(
2727
3047
  Ref.get(ref),
2728
3048
  Option.match({
2729
3049
  onNone: () => Effect.void,
2730
3050
  onSome: (b) => Effect.matchCauseEffect(this.i2(a, b), sink)
2731
3051
  })
2732
- )))
2733
- ),
2734
- Fiber.interrupt
2735
- )
2736
- )
3052
+ ))
3053
+ )
3054
+ ),
3055
+ Fiber.interrupt
3056
+ ))
2737
3057
  }
2738
3058
  }
2739
3059
 
@@ -2746,7 +3066,7 @@ function if_<B, E, R, E2, R2, C, E3, R3>(
2746
3066
  ): Fx<B | C, E | E2 | E3, R | R2 | R3 | Scope.Scope> {
2747
3067
  return switchMap(
2748
3068
  skipRepeatsWith(bool, boolean),
2749
- (b): Fx<B | C, E2 | E3, R2 | R3> => b ? options.onTrue : options.onFalse
3069
+ (b): Fx<B | C, E2 | E3, R2 | R3> => (b ? options.onTrue : options.onFalse)
2750
3070
  )
2751
3071
  }
2752
3072
 
@@ -2759,7 +3079,7 @@ export function when<B, E, R, C>(
2759
3079
  readonly onFalse: C
2760
3080
  }
2761
3081
  ): Fx<B | C, E, R> {
2762
- return map(skipRepeatsWith(bool, boolean), (b) => (b ? options.onTrue : options.onFalse))
3082
+ return map(skipRepeatsWith(bool, boolean), (b) => b ? options.onTrue : options.onFalse)
2763
3083
  }
2764
3084
 
2765
3085
  export function mapBoth<A, E, R, B, C>(