effect 3.0.2 → 3.0.4

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 (106) hide show
  1. package/dist/cjs/Cause.js.map +1 -1
  2. package/dist/cjs/Chunk.js +1 -1
  3. package/dist/cjs/Chunk.js.map +1 -1
  4. package/dist/cjs/Effect.js.map +1 -1
  5. package/dist/cjs/Either.js +4 -6
  6. package/dist/cjs/Either.js.map +1 -1
  7. package/dist/cjs/Match.js +6 -1
  8. package/dist/cjs/Match.js.map +1 -1
  9. package/dist/cjs/Option.js +3 -5
  10. package/dist/cjs/Option.js.map +1 -1
  11. package/dist/cjs/Order.js +15 -0
  12. package/dist/cjs/Order.js.map +1 -1
  13. package/dist/cjs/STM.js.map +1 -1
  14. package/dist/cjs/Utils.js +2 -4
  15. package/dist/cjs/Utils.js.map +1 -1
  16. package/dist/cjs/internal/core-effect.js +3 -21
  17. package/dist/cjs/internal/core-effect.js.map +1 -1
  18. package/dist/cjs/internal/core.js +10 -0
  19. package/dist/cjs/internal/core.js.map +1 -1
  20. package/dist/cjs/internal/effectable.js +4 -0
  21. package/dist/cjs/internal/effectable.js.map +1 -1
  22. package/dist/cjs/internal/fiberRuntime.js +3 -3
  23. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  24. package/dist/cjs/internal/matcher.js +8 -3
  25. package/dist/cjs/internal/matcher.js.map +1 -1
  26. package/dist/cjs/internal/rateLimiter.js +1 -1
  27. package/dist/cjs/internal/rateLimiter.js.map +1 -1
  28. package/dist/cjs/internal/stm/core.js +4 -0
  29. package/dist/cjs/internal/stm/core.js.map +1 -1
  30. package/dist/cjs/internal/stm/stm.js +3 -21
  31. package/dist/cjs/internal/stm/stm.js.map +1 -1
  32. package/dist/cjs/internal/version.js +1 -1
  33. package/dist/dts/Cause.d.ts +1 -0
  34. package/dist/dts/Cause.d.ts.map +1 -1
  35. package/dist/dts/Chunk.d.ts.map +1 -1
  36. package/dist/dts/Effect.d.ts +43 -38
  37. package/dist/dts/Effect.d.ts.map +1 -1
  38. package/dist/dts/Either.d.ts +1 -1
  39. package/dist/dts/Either.d.ts.map +1 -1
  40. package/dist/dts/Match.d.ts +35 -36
  41. package/dist/dts/Match.d.ts.map +1 -1
  42. package/dist/dts/Option.d.ts +1 -1
  43. package/dist/dts/Option.d.ts.map +1 -1
  44. package/dist/dts/Order.d.ts.map +1 -1
  45. package/dist/dts/STM.d.ts +25 -35
  46. package/dist/dts/STM.d.ts.map +1 -1
  47. package/dist/dts/Utils.d.ts +29 -25
  48. package/dist/dts/Utils.d.ts.map +1 -1
  49. package/dist/dts/index.d.ts +15 -0
  50. package/dist/dts/index.d.ts.map +1 -1
  51. package/dist/dts/internal/core.d.ts.map +1 -1
  52. package/dist/dts/internal/stm/stm.d.ts.map +1 -1
  53. package/dist/esm/Cause.js.map +1 -1
  54. package/dist/esm/Chunk.js +1 -1
  55. package/dist/esm/Chunk.js.map +1 -1
  56. package/dist/esm/Effect.js.map +1 -1
  57. package/dist/esm/Either.js +4 -6
  58. package/dist/esm/Either.js.map +1 -1
  59. package/dist/esm/Match.js +5 -0
  60. package/dist/esm/Match.js.map +1 -1
  61. package/dist/esm/Option.js +4 -6
  62. package/dist/esm/Option.js.map +1 -1
  63. package/dist/esm/Order.js +15 -0
  64. package/dist/esm/Order.js.map +1 -1
  65. package/dist/esm/STM.js.map +1 -1
  66. package/dist/esm/Utils.js +2 -4
  67. package/dist/esm/Utils.js.map +1 -1
  68. package/dist/esm/index.js +15 -0
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/internal/core-effect.js +2 -20
  71. package/dist/esm/internal/core-effect.js.map +1 -1
  72. package/dist/esm/internal/core.js +10 -0
  73. package/dist/esm/internal/core.js.map +1 -1
  74. package/dist/esm/internal/effectable.js +4 -0
  75. package/dist/esm/internal/effectable.js.map +1 -1
  76. package/dist/esm/internal/fiberRuntime.js +3 -3
  77. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  78. package/dist/esm/internal/matcher.js +6 -2
  79. package/dist/esm/internal/matcher.js.map +1 -1
  80. package/dist/esm/internal/rateLimiter.js +1 -1
  81. package/dist/esm/internal/rateLimiter.js.map +1 -1
  82. package/dist/esm/internal/stm/core.js +4 -0
  83. package/dist/esm/internal/stm/core.js.map +1 -1
  84. package/dist/esm/internal/stm/stm.js +2 -20
  85. package/dist/esm/internal/stm/stm.js.map +1 -1
  86. package/dist/esm/internal/version.js +1 -1
  87. package/package.json +1 -1
  88. package/src/Cause.ts +1 -0
  89. package/src/Chunk.ts +1 -2
  90. package/src/Effect.ts +46 -41
  91. package/src/Either.ts +5 -7
  92. package/src/Match.ts +97 -109
  93. package/src/Option.ts +5 -7
  94. package/src/Order.ts +15 -0
  95. package/src/STM.ts +25 -36
  96. package/src/Utils.ts +31 -28
  97. package/src/index.ts +15 -0
  98. package/src/internal/core-effect.ts +2 -23
  99. package/src/internal/core.ts +10 -0
  100. package/src/internal/effectable.ts +4 -0
  101. package/src/internal/fiberRuntime.ts +3 -3
  102. package/src/internal/matcher.ts +95 -68
  103. package/src/internal/rateLimiter.ts +1 -1
  104. package/src/internal/stm/core.ts +4 -0
  105. package/src/internal/stm/stm.ts +2 -22
  106. package/src/internal/version.ts +1 -1
@@ -26,7 +26,8 @@ const TypeMatcherProto: Omit<TypeMatcher<any, any, any, any>, "cases"> = {
26
26
  _input: identity,
27
27
  _filters: identity,
28
28
  _remaining: identity,
29
- _result: identity
29
+ _result: identity,
30
+ _return: identity
30
31
  },
31
32
  _tag: "TypeMatcher",
32
33
  add<I, R, RA, A>(
@@ -55,7 +56,8 @@ const ValueMatcherProto: Omit<
55
56
  [TypeId]: {
56
57
  _input: identity,
57
58
  _filters: identity,
58
- _result: identity
59
+ _result: identity,
60
+ _return: identity
59
61
  },
60
62
  _tag: "ValueMatcher",
61
63
  add<I, R, RA, A, Pr>(
@@ -217,7 +219,7 @@ export const valueTags = <
217
219
  >(
218
220
  fields: P
219
221
  ) => {
220
- const match: any = tagsExhaustive(fields)(makeTypeMatcher([]))
222
+ const match: any = tagsExhaustive(fields as any)(makeTypeMatcher([]))
221
223
  return (input: I): Unify<ReturnType<P[keyof P]>> => match(input)
222
224
  }
223
225
 
@@ -232,27 +234,36 @@ export const typeTags = <I>() =>
232
234
  >(
233
235
  fields: P
234
236
  ) => {
235
- const match: any = tagsExhaustive(fields)(makeTypeMatcher([]))
237
+ const match: any = tagsExhaustive(fields as any)(makeTypeMatcher([]))
236
238
  return (input: I): Unify<ReturnType<P[keyof P]>> => match(input)
237
239
  }
238
240
 
241
+ /** @internal */
242
+ export const withReturnType =
243
+ <Ret>() =>
244
+ <I, F, R, A, Pr, _>(self: Matcher<I, F, R, A, Pr, _>): Ret extends ([A] extends [never] ? any
245
+ : A) ? Matcher<I, F, R, A, Pr, Ret>
246
+ : "withReturnType constraint does not extend Result type" => self as any
247
+
239
248
  /** @internal */
240
249
  export const when = <
241
250
  R,
242
251
  const P extends Types.PatternPrimitive<R> | Types.PatternBase<R>,
243
- Fn extends (_: Types.WhenMatch<R, P>) => unknown
252
+ Ret,
253
+ Fn extends (_: Types.WhenMatch<R, P>) => Ret
244
254
  >(
245
255
  pattern: P,
246
256
  f: Fn
247
257
  ) =>
248
258
  <I, F, A, Pr>(
249
- self: Matcher<I, F, R, A, Pr>
259
+ self: Matcher<I, F, R, A, Pr, Ret>
250
260
  ): Matcher<
251
261
  I,
252
262
  Types.AddWithout<F, Types.PForExclude<P>>,
253
263
  Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<P>>>,
254
264
  A | ReturnType<Fn>,
255
- Pr
265
+ Pr,
266
+ Ret
256
267
  > => (self as any).add(makeWhen(makePredicate(pattern), f as any))
257
268
 
258
269
  /** @internal */
@@ -261,18 +272,20 @@ export const whenOr = <
261
272
  const P extends ReadonlyArray<
262
273
  Types.PatternPrimitive<R> | Types.PatternBase<R>
263
274
  >,
264
- Fn extends (_: Types.WhenMatch<R, P[number]>) => unknown
275
+ Ret,
276
+ Fn extends (_: Types.WhenMatch<R, P[number]>) => Ret
265
277
  >(
266
278
  ...args: [...patterns: P, f: Fn]
267
279
  ) =>
268
280
  <I, F, A, Pr>(
269
- self: Matcher<I, F, R, A, Pr>
281
+ self: Matcher<I, F, R, A, Pr, Ret>
270
282
  ): Matcher<
271
283
  I,
272
284
  Types.AddWithout<F, Types.PForExclude<P[number]>>,
273
285
  Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<P[number]>>>,
274
286
  A | ReturnType<Fn>,
275
- Pr
287
+ Pr,
288
+ Ret
276
289
  > => {
277
290
  const onMatch = args[args.length - 1] as any
278
291
  const patterns = args.slice(0, -1) as unknown as P
@@ -285,12 +298,13 @@ export const whenAnd = <
285
298
  const P extends ReadonlyArray<
286
299
  Types.PatternPrimitive<R> | Types.PatternBase<R>
287
300
  >,
288
- Fn extends (_: Types.WhenMatch<R, Types.ArrayToIntersection<P>>) => unknown
301
+ Ret,
302
+ Fn extends (_: Types.WhenMatch<R, Types.ArrayToIntersection<P>>) => Ret
289
303
  >(
290
304
  ...args: [...patterns: P, f: Fn]
291
305
  ) =>
292
306
  <I, F, A, Pr>(
293
- self: Matcher<I, F, R, A, Pr>
307
+ self: Matcher<I, F, R, A, Pr, Ret>
294
308
  ): Matcher<
295
309
  I,
296
310
  Types.AddWithout<F, Types.PForExclude<Types.ArrayToIntersection<P>>>,
@@ -307,41 +321,43 @@ export const whenAnd = <
307
321
  }
308
322
 
309
323
  /** @internal */
310
- export const discriminator = <D extends string>(field: D) =>
311
- <R, P extends Types.Tags<D, R> & string, B>(
312
- ...pattern: [
313
- first: P,
314
- ...values: Array<P>,
315
- f: (_: Extract<R, Record<D, P>>) => B
316
- ]
317
- ) => {
318
- const f = pattern[pattern.length - 1]
319
- const values: Array<P> = pattern.slice(0, -1) as any
320
- const pred = values.length === 1
321
- ? (_: any) => _[field] === values[0]
322
- : (_: any) => values.includes(_[field])
323
-
324
- return <I, F, A, Pr>(
325
- self: Matcher<I, F, R, A, Pr>
326
- ): Matcher<
327
- I,
328
- Types.AddWithout<F, Extract<R, Record<D, P>>>,
329
- Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, P>>>>,
330
- A | B,
331
- Pr
332
- > => (self as any).add(makeWhen(pred, f as any)) as any
333
- }
324
+ export const discriminator =
325
+ <D extends string>(field: D) =>
326
+ <R, P extends Types.Tags<D, R> & string, Ret, B extends Ret>(
327
+ ...pattern: [
328
+ first: P,
329
+ ...values: Array<P>,
330
+ f: (_: Extract<R, Record<D, P>>) => B
331
+ ]
332
+ ) => {
333
+ const f = pattern[pattern.length - 1]
334
+ const values: Array<P> = pattern.slice(0, -1) as any
335
+ const pred = values.length === 1
336
+ ? (_: any) => _[field] === values[0]
337
+ : (_: any) => values.includes(_[field])
338
+
339
+ return <I, F, A, Pr>(
340
+ self: Matcher<I, F, R, A, Pr, Ret>
341
+ ): Matcher<
342
+ I,
343
+ Types.AddWithout<F, Extract<R, Record<D, P>>>,
344
+ Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, P>>>>,
345
+ A | B,
346
+ Pr,
347
+ Ret
348
+ > => (self as any).add(makeWhen(pred, f as any)) as any
349
+ }
334
350
 
335
351
  /** @internal */
336
352
  export const discriminatorStartsWith = <D extends string>(field: D) =>
337
- <R, P extends string, B>(
353
+ <R, P extends string, Ret, B extends Ret>(
338
354
  pattern: P,
339
355
  f: (_: Extract<R, Record<D, `${P}${string}`>>) => B
340
356
  ) => {
341
357
  const pred = (_: any) => typeof _[field] === "string" && _[field].startsWith(pattern)
342
358
 
343
359
  return <I, F, A, Pr>(
344
- self: Matcher<I, F, R, A, Pr>
360
+ self: Matcher<I, F, R, A, Pr, Ret>
345
361
  ): Matcher<
346
362
  I,
347
363
  Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>,
@@ -350,7 +366,8 @@ export const discriminatorStartsWith = <D extends string>(field: D) =>
350
366
  Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>
351
367
  >,
352
368
  A | B,
353
- Pr
369
+ Pr,
370
+ Ret
354
371
  > => (self as any).add(makeWhen(pred, f as any)) as any
355
372
  }
356
373
 
@@ -358,11 +375,14 @@ export const discriminatorStartsWith = <D extends string>(field: D) =>
358
375
  export const discriminators = <D extends string>(field: D) =>
359
376
  <
360
377
  R,
361
- P extends {
362
- readonly [Tag in Types.Tags<D, R> & string]?: (
363
- _: Extract<R, Record<D, Tag>>
364
- ) => any
365
- }
378
+ Ret,
379
+ P extends
380
+ & {
381
+ readonly [Tag in Types.Tags<D, R> & string]?:
382
+ | ((_: Extract<R, Record<D, Tag>>) => Ret)
383
+ | undefined
384
+ }
385
+ & { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
366
386
  >(
367
387
  fields: P
368
388
  ) => {
@@ -372,13 +392,14 @@ export const discriminators = <D extends string>(field: D) =>
372
392
  )
373
393
 
374
394
  return <I, F, A, Pr>(
375
- self: Matcher<I, F, R, A, Pr>
395
+ self: Matcher<I, F, R, A, Pr, Ret>
376
396
  ): Matcher<
377
397
  I,
378
398
  Types.AddWithout<F, Extract<R, Record<D, keyof P>>>,
379
399
  Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, keyof P>>>>,
380
400
  A | ReturnType<P[keyof P] & {}>,
381
- Pr
401
+ Pr,
402
+ Ret
382
403
  > => (self as any).add(predicate)
383
404
  }
384
405
 
@@ -387,15 +408,18 @@ export const discriminatorsExhaustive: <D extends string>(
387
408
  field: D
388
409
  ) => <
389
410
  R,
390
- P extends {
391
- readonly [Tag in Types.Tags<D, R> & string]: (
392
- _: Extract<R, Record<D, Tag>>
393
- ) => any
394
- }
411
+ Ret,
412
+ P extends
413
+ & {
414
+ readonly [Tag in Types.Tags<D, R> & string]: (
415
+ _: Extract<R, Record<D, Tag>>
416
+ ) => Ret
417
+ }
418
+ & { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
395
419
  >(
396
420
  fields: P
397
421
  ) => <I, F, A, Pr>(
398
- self: Matcher<I, F, R, A, Pr>
422
+ self: Matcher<I, F, R, A, Pr, Ret>
399
423
  ) => [Pr] extends [never] ? (u: I) => Unify<A | ReturnType<P[keyof P]>>
400
424
  : Unify<A | ReturnType<P[keyof P]>> = (field: string) => (fields: object) => {
401
425
  const addCases = discriminators(field)(fields)
@@ -403,20 +427,21 @@ export const discriminatorsExhaustive: <D extends string>(
403
427
  }
404
428
 
405
429
  /** @internal */
406
- export const tag: <R, P extends Types.Tags<"_tag", R> & string, B>(
430
+ export const tag: <R, P extends Types.Tags<"_tag", R> & string, Ret, B extends Ret>(
407
431
  ...pattern: [
408
432
  first: P,
409
433
  ...values: Array<P>,
410
434
  f: (_: Extract<R, Record<"_tag", P>>) => B
411
435
  ]
412
436
  ) => <I, F, A, Pr>(
413
- self: Matcher<I, F, R, A, Pr>
437
+ self: Matcher<I, F, R, A, Pr, Ret>
414
438
  ) => Matcher<
415
439
  I,
416
440
  Types.AddWithout<F, Extract<R, Record<"_tag", P>>>,
417
441
  Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<"_tag", P>>>>,
418
442
  B | A,
419
- Pr
443
+ Pr,
444
+ Ret
420
445
  > = discriminator("_tag")
421
446
 
422
447
  /** @internal */
@@ -432,19 +457,21 @@ export const tagsExhaustive = discriminatorsExhaustive("_tag")
432
457
  export const not = <
433
458
  R,
434
459
  const P extends Types.PatternPrimitive<R> | Types.PatternBase<R>,
435
- Fn extends (_: Types.NotMatch<R, P>) => unknown
460
+ Ret,
461
+ Fn extends (_: Types.NotMatch<R, P>) => Ret
436
462
  >(
437
463
  pattern: P,
438
464
  f: Fn
439
465
  ) =>
440
466
  <I, F, A, Pr>(
441
- self: Matcher<I, F, R, A, Pr>
467
+ self: Matcher<I, F, R, A, Pr, Ret>
442
468
  ): Matcher<
443
469
  I,
444
470
  Types.AddOnly<F, Types.WhenMatch<R, P>>,
445
471
  Types.ApplyFilters<I, Types.AddOnly<F, Types.WhenMatch<R, P>>>,
446
472
  A | ReturnType<Fn>,
447
- Pr
473
+ Pr,
474
+ Ret
448
475
  > => (self as any).add(makeNot(makePredicate(pattern), f as any))
449
476
 
450
477
  /** @internal */
@@ -485,9 +512,9 @@ export const instanceOfUnsafe: <A extends abstract new(...args: any) => any>(
485
512
  ) => SafeRefinement<InstanceType<A>, InstanceType<A>> = instanceOf
486
513
 
487
514
  /** @internal */
488
- export const orElse = <RA, B>(f: (b: RA) => B) =>
515
+ export const orElse = <RA, Ret, B extends Ret>(f: (b: RA) => B) =>
489
516
  <I, R, A, Pr>(
490
- self: Matcher<I, R, RA, A, Pr>
517
+ self: Matcher<I, R, RA, A, Pr, Ret>
491
518
  ): [Pr] extends [never] ? (input: I) => Unify<A | B> : Unify<A | B> => {
492
519
  const result = either(self)
493
520
 
@@ -504,16 +531,16 @@ export const orElse = <RA, B>(f: (b: RA) => B) =>
504
531
  }
505
532
 
506
533
  /** @internal */
507
- export const orElseAbsurd = <I, R, RA, A, Pr>(
508
- self: Matcher<I, R, RA, A, Pr>
534
+ export const orElseAbsurd = <I, R, RA, A, Pr, Ret>(
535
+ self: Matcher<I, R, RA, A, Pr, Ret>
509
536
  ): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A> =>
510
537
  orElse(() => {
511
538
  throw new Error("effect/Match/orElseAbsurd: absurd")
512
539
  })(self)
513
540
 
514
541
  /** @internal */
515
- export const either: <I, F, R, A, Pr>(
516
- self: Matcher<I, F, R, A, Pr>
542
+ export const either: <I, F, R, A, Pr, Ret>(
543
+ self: Matcher<I, F, R, A, Pr, Ret>
517
544
  ) => [Pr] extends [never] ? (input: I) => Either.Either<Unify<A>, R>
518
545
  : Either.Either<Unify<A>, R> = (<I, R, RA, A>(self: Matcher<I, R, RA, A, I>) => {
519
546
  if (self._tag === "ValueMatcher") {
@@ -547,8 +574,8 @@ export const either: <I, F, R, A, Pr>(
547
574
  }) as any
548
575
 
549
576
  /** @internal */
550
- export const option: <I, F, R, A, Pr>(
551
- self: Matcher<I, F, R, A, Pr>
577
+ export const option: <I, F, R, A, Pr, Ret>(
578
+ self: Matcher<I, F, R, A, Pr, Ret>
552
579
  ) => [Pr] extends [never] ? (input: I) => Option.Option<Unify<A>>
553
580
  : Option.Option<Unify<A>> = (<I, A>(self: Matcher<I, any, any, A, I>) => {
554
581
  const toEither = either(self)
@@ -568,8 +595,8 @@ export const option: <I, F, R, A, Pr>(
568
595
  const getExhaustiveAbsurdErrorMessage = "effect/Match/exhaustive: absurd"
569
596
 
570
597
  /** @internal */
571
- export const exhaustive: <I, F, A, Pr>(
572
- self: Matcher<I, F, never, A, Pr>
598
+ export const exhaustive: <I, F, A, Pr, Ret>(
599
+ self: Matcher<I, F, never, A, Pr, Ret>
573
600
  ) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A> = (<I, F, A>(
574
601
  self: Matcher<I, F, never, A, I>
575
602
  ) => {
@@ -34,7 +34,7 @@ const tokenBucket = (limit: number, window: DurationInput): Effect.Effect<
34
34
  Effect.gen(function*(_) {
35
35
  const millisPerToken = Math.ceil(Duration.toMillis(window) / limit)
36
36
  const semaphore = yield* _(Effect.makeSemaphore(limit))
37
- const latch = yield* _(Effect.makeSemaphore(0))
37
+ const latch = yield* Effect.makeSemaphore(0)
38
38
  const refill: Effect.Effect<void> = Effect.sleep(millisPerToken).pipe(
39
39
  Effect.zipRight(latch.releaseAll),
40
40
  Effect.zipRight(semaphore.release(1)),
@@ -19,6 +19,7 @@ import { ChannelTypeId } from "../core-stream.js"
19
19
  import { withFiberRuntime } from "../core.js"
20
20
  import { effectVariance } from "../effectable.js"
21
21
  import { OP_COMMIT } from "../opCodes/effect.js"
22
+ import { SingleShotGen } from "../singleShotGen.js"
22
23
  import { SinkTypeId } from "../sink.js"
23
24
  import * as OpCodes from "./opCodes/stm.js"
24
25
  import * as TExitOpCodes from "./opCodes/tExit.js"
@@ -170,6 +171,9 @@ class STMPrimitive implements STM.STM<any, any, any> {
170
171
  [Hash.symbol](this: {}) {
171
172
  return Hash.cached(this, Hash.random(this))
172
173
  }
174
+ [Symbol.iterator]() {
175
+ return new SingleShotGen(this) as any
176
+ }
173
177
  commit(this: STM.STM<any, any, any>): Effect.Effect<any, any, any> {
174
178
  return unsafeAtomically(this, constVoid, constVoid)
175
179
  }
@@ -14,7 +14,6 @@ import * as predicate from "../../Predicate.js"
14
14
  import type * as STM from "../../STM.js"
15
15
  import type { MergeRecord } from "../../Types.js"
16
16
  import * as effectCore from "../core.js"
17
- import * as SingleShotGen from "../singleShotGen.js"
18
17
  import * as core from "./core.js"
19
18
  import * as Journal from "./stm/journal.js"
20
19
  import * as STMState from "./stm/stmState.js"
@@ -614,39 +613,20 @@ export const fromOption = <A>(option: Option.Option<A>): STM.STM<A, Option.Optio
614
613
  onSome: core.succeed
615
614
  })
616
615
 
617
- /** @internal */
618
- class STMGen {
619
- constructor(readonly value: STM.STM<any, any, any>) {}
620
- [Symbol.iterator]() {
621
- return new SingleShotGen.SingleShotGen(this)
622
- }
623
- }
624
-
625
- const adapter = function() {
626
- let x = arguments[0]
627
- for (let i = 1; i < arguments.length; i++) {
628
- x = arguments[i](x)
629
- }
630
- return new STMGen(x) as any
631
- }
632
-
633
616
  /**
634
617
  * Inspired by https://github.com/tusharmath/qio/pull/22 (revised)
635
618
  * @internal
636
619
  */
637
620
  export const gen: typeof STM.gen = (f) =>
638
621
  suspend(() => {
639
- const iterator = f(adapter)
622
+ const iterator = f(pipe)
640
623
  const state = iterator.next()
641
624
  const run = (
642
625
  state: IteratorYieldResult<any> | IteratorReturnResult<any>
643
626
  ): STM.STM<any, any, any> =>
644
627
  state.done ?
645
628
  core.succeed(state.value) :
646
- core.flatMap(
647
- state.value.value as unknown as STM.STM<any, any, any>,
648
- (val: any) => run(iterator.next(val))
649
- )
629
+ core.flatMap(state.value, (val: any) => run(iterator.next(val)))
650
630
  return run(state)
651
631
  })
652
632
 
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.0.2"
1
+ let moduleVersion = "3.0.4"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4