effect 4.0.0-beta.17 → 4.0.0-beta.19

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 (164) hide show
  1. package/dist/Array.d.ts +127 -299
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +102 -62
  4. package/dist/Array.js.map +1 -1
  5. package/dist/Cache.d.ts.map +1 -1
  6. package/dist/Cache.js +5 -4
  7. package/dist/Cache.js.map +1 -1
  8. package/dist/Channel.d.ts +97 -11
  9. package/dist/Channel.d.ts.map +1 -1
  10. package/dist/Channel.js +72 -29
  11. package/dist/Channel.js.map +1 -1
  12. package/dist/Chunk.d.ts +54 -247
  13. package/dist/Chunk.d.ts.map +1 -1
  14. package/dist/Chunk.js +36 -67
  15. package/dist/Chunk.js.map +1 -1
  16. package/dist/Effect.d.ts +337 -437
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +118 -134
  19. package/dist/Effect.js.map +1 -1
  20. package/dist/Filter.d.ts +0 -33
  21. package/dist/Filter.d.ts.map +1 -1
  22. package/dist/Filter.js +0 -13
  23. package/dist/Filter.js.map +1 -1
  24. package/dist/HashMap.d.ts +15 -14
  25. package/dist/HashMap.d.ts.map +1 -1
  26. package/dist/HashMap.js +4 -4
  27. package/dist/HashMap.js.map +1 -1
  28. package/dist/Iterable.d.ts +40 -39
  29. package/dist/Iterable.d.ts.map +1 -1
  30. package/dist/Iterable.js +94 -22
  31. package/dist/Iterable.js.map +1 -1
  32. package/dist/Option.d.ts +22 -15
  33. package/dist/Option.d.ts.map +1 -1
  34. package/dist/Option.js +14 -7
  35. package/dist/Option.js.map +1 -1
  36. package/dist/Pull.d.ts.map +1 -1
  37. package/dist/Pull.js +1 -1
  38. package/dist/Pull.js.map +1 -1
  39. package/dist/Record.d.ts +24 -120
  40. package/dist/Record.d.ts.map +1 -1
  41. package/dist/Record.js +21 -41
  42. package/dist/Record.js.map +1 -1
  43. package/dist/Sink.d.ts +11 -11
  44. package/dist/Sink.d.ts.map +1 -1
  45. package/dist/Sink.js +53 -6
  46. package/dist/Sink.js.map +1 -1
  47. package/dist/Stream.d.ts +198 -386
  48. package/dist/Stream.d.ts.map +1 -1
  49. package/dist/Stream.js +103 -59
  50. package/dist/Stream.js.map +1 -1
  51. package/dist/Trie.d.ts +18 -17
  52. package/dist/Trie.d.ts.map +1 -1
  53. package/dist/Trie.js +5 -5
  54. package/dist/Trie.js.map +1 -1
  55. package/dist/TxChunk.d.ts +37 -37
  56. package/dist/TxChunk.d.ts.map +1 -1
  57. package/dist/TxChunk.js +3 -3
  58. package/dist/TxChunk.js.map +1 -1
  59. package/dist/TxDeferred.d.ts +328 -0
  60. package/dist/TxDeferred.d.ts.map +1 -0
  61. package/dist/TxDeferred.js +196 -0
  62. package/dist/TxDeferred.js.map +1 -0
  63. package/dist/TxHashMap.d.ts +84 -83
  64. package/dist/TxHashMap.d.ts.map +1 -1
  65. package/dist/TxHashMap.js +24 -24
  66. package/dist/TxHashMap.js.map +1 -1
  67. package/dist/TxHashSet.d.ts +35 -35
  68. package/dist/TxHashSet.d.ts.map +1 -1
  69. package/dist/TxHashSet.js +14 -14
  70. package/dist/TxHashSet.js.map +1 -1
  71. package/dist/TxPriorityQueue.d.ts +609 -0
  72. package/dist/TxPriorityQueue.d.ts.map +1 -0
  73. package/dist/TxPriorityQueue.js +415 -0
  74. package/dist/TxPriorityQueue.js.map +1 -0
  75. package/dist/TxPubSub.d.ts +585 -0
  76. package/dist/TxPubSub.d.ts.map +1 -0
  77. package/dist/TxPubSub.js +521 -0
  78. package/dist/TxPubSub.js.map +1 -0
  79. package/dist/TxQueue.d.ts +32 -32
  80. package/dist/TxQueue.d.ts.map +1 -1
  81. package/dist/TxQueue.js +26 -26
  82. package/dist/TxQueue.js.map +1 -1
  83. package/dist/TxReentrantLock.d.ts +523 -0
  84. package/dist/TxReentrantLock.d.ts.map +1 -0
  85. package/dist/TxReentrantLock.js +504 -0
  86. package/dist/TxReentrantLock.js.map +1 -0
  87. package/dist/TxRef.d.ts +34 -34
  88. package/dist/TxRef.d.ts.map +1 -1
  89. package/dist/TxRef.js +21 -14
  90. package/dist/TxRef.js.map +1 -1
  91. package/dist/TxSemaphore.d.ts +8 -8
  92. package/dist/TxSemaphore.d.ts.map +1 -1
  93. package/dist/TxSemaphore.js +7 -7
  94. package/dist/TxSemaphore.js.map +1 -1
  95. package/dist/TxSubscriptionRef.d.ts +508 -0
  96. package/dist/TxSubscriptionRef.d.ts.map +1 -0
  97. package/dist/TxSubscriptionRef.js +293 -0
  98. package/dist/TxSubscriptionRef.js.map +1 -0
  99. package/dist/index.d.ts +40 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +40 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/internal/effect.js +99 -42
  104. package/dist/internal/effect.js.map +1 -1
  105. package/dist/internal/hashMap.js +3 -2
  106. package/dist/internal/hashMap.js.map +1 -1
  107. package/dist/internal/trie.js +5 -4
  108. package/dist/internal/trie.js.map +1 -1
  109. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  110. package/dist/unstable/ai/Tool.js +0 -9
  111. package/dist/unstable/ai/Tool.js.map +1 -1
  112. package/dist/unstable/cli/Command.d.ts +1 -1
  113. package/dist/unstable/cli/Command.d.ts.map +1 -1
  114. package/dist/unstable/cli/Command.js +1 -1
  115. package/dist/unstable/cli/Command.js.map +1 -1
  116. package/dist/unstable/cluster/K8sHttpClient.js +4 -4
  117. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  118. package/dist/unstable/cluster/Sharding.js +1 -1
  119. package/dist/unstable/cluster/Sharding.js.map +1 -1
  120. package/dist/unstable/encoding/Sse.js +1 -1
  121. package/dist/unstable/encoding/Sse.js.map +1 -1
  122. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  123. package/dist/unstable/rpc/RpcServer.js +1 -2
  124. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  125. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  126. package/dist/unstable/socket/Socket.js +3 -3
  127. package/dist/unstable/socket/Socket.js.map +1 -1
  128. package/package.json +1 -1
  129. package/src/Array.ts +190 -342
  130. package/src/Cache.ts +6 -5
  131. package/src/Channel.ts +506 -102
  132. package/src/Chunk.ts +81 -268
  133. package/src/Effect.ts +437 -518
  134. package/src/Filter.ts +0 -57
  135. package/src/HashMap.ts +15 -14
  136. package/src/Iterable.ts +105 -50
  137. package/src/Option.ts +30 -20
  138. package/src/Pull.ts +1 -1
  139. package/src/Record.ts +43 -152
  140. package/src/Sink.ts +75 -23
  141. package/src/Stream.ts +442 -502
  142. package/src/Trie.ts +18 -17
  143. package/src/TxChunk.ts +72 -53
  144. package/src/TxDeferred.ts +394 -0
  145. package/src/TxHashMap.ts +332 -285
  146. package/src/TxHashSet.ts +111 -116
  147. package/src/TxPriorityQueue.ts +767 -0
  148. package/src/TxPubSub.ts +789 -0
  149. package/src/TxQueue.ts +241 -251
  150. package/src/TxReentrantLock.ts +753 -0
  151. package/src/TxRef.ts +50 -38
  152. package/src/TxSemaphore.ts +29 -32
  153. package/src/TxSubscriptionRef.ts +639 -0
  154. package/src/index.ts +45 -0
  155. package/src/internal/effect.ts +368 -163
  156. package/src/internal/hashMap.ts +7 -5
  157. package/src/internal/trie.ts +16 -9
  158. package/src/unstable/ai/Tool.ts +0 -9
  159. package/src/unstable/cli/Command.ts +6 -4
  160. package/src/unstable/cluster/K8sHttpClient.ts +4 -4
  161. package/src/unstable/cluster/Sharding.ts +1 -1
  162. package/src/unstable/encoding/Sse.ts +1 -1
  163. package/src/unstable/rpc/RpcServer.ts +1 -7
  164. package/src/unstable/socket/Socket.ts +9 -11
package/src/Effect.ts CHANGED
@@ -763,7 +763,7 @@ export const all: <
763
763
  ) => All.Return<Arg, O> = internal.all
764
764
 
765
765
  /**
766
- * Applies an effectful function to each element and partitions failures and
766
+ * Applies an effectful `Filter` to each element and partitions failures and
767
767
  * successes.
768
768
  *
769
769
  * The returned tuple is `[excluded, satisfying]`, where:
@@ -776,10 +776,10 @@ export const all: <
776
776
  *
777
777
  * @example
778
778
  * ```ts
779
- * import { Effect } from "effect"
779
+ * import { Effect, Result } from "effect"
780
780
  *
781
781
  * const program = Effect.partition([0, 1, 2, 3], (n) =>
782
- * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
782
+ * Effect.succeed(n % 2 === 0 ? Result.fail(`${n} is even`) : Result.succeed(n))
783
783
  * )
784
784
  *
785
785
  * Effect.runPromise(program).then(console.log)
@@ -791,7 +791,7 @@ export const all: <
791
791
  */
792
792
  export const partition: {
793
793
  /**
794
- * Applies an effectful function to each element and partitions failures and
794
+ * Applies an effectful `Filter` to each element and partitions failures and
795
795
  * successes.
796
796
  *
797
797
  * The returned tuple is `[excluded, satisfying]`, where:
@@ -804,10 +804,10 @@ export const partition: {
804
804
  *
805
805
  * @example
806
806
  * ```ts
807
- * import { Effect } from "effect"
807
+ * import { Effect, Result } from "effect"
808
808
  *
809
809
  * const program = Effect.partition([0, 1, 2, 3], (n) =>
810
- * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
810
+ * Effect.succeed(n % 2 === 0 ? Result.fail(`${n} is even`) : Result.succeed(n))
811
811
  * )
812
812
  *
813
813
  * Effect.runPromise(program).then(console.log)
@@ -817,12 +817,12 @@ export const partition: {
817
817
  * @since 3.0.0
818
818
  * @category Collecting
819
819
  */
820
- <A, B, E, R>(
821
- f: (a: A, i: number) => Effect<B, E, R>,
820
+ <A, Pass, Fail, E, R>(
821
+ filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, E, R, [i: number]>,
822
822
  options?: { readonly concurrency?: Concurrency | undefined }
823
- ): (elements: Iterable<A>) => Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>
823
+ ): (elements: Iterable<A>) => Effect<[excluded: Array<Fail>, satisfying: Array<Pass>], E, R>
824
824
  /**
825
- * Applies an effectful function to each element and partitions failures and
825
+ * Applies an effectful `Filter` to each element and partitions failures and
826
826
  * successes.
827
827
  *
828
828
  * The returned tuple is `[excluded, satisfying]`, where:
@@ -835,10 +835,10 @@ export const partition: {
835
835
  *
836
836
  * @example
837
837
  * ```ts
838
- * import { Effect } from "effect"
838
+ * import { Effect, Result } from "effect"
839
839
  *
840
840
  * const program = Effect.partition([0, 1, 2, 3], (n) =>
841
- * n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
841
+ * Effect.succeed(n % 2 === 0 ? Result.fail(`${n} is even`) : Result.succeed(n))
842
842
  * )
843
843
  *
844
844
  * Effect.runPromise(program).then(console.log)
@@ -848,11 +848,11 @@ export const partition: {
848
848
  * @since 3.0.0
849
849
  * @category Collecting
850
850
  */
851
- <A, B, E, R>(
851
+ <A, Pass, Fail, E, R>(
852
852
  elements: Iterable<A>,
853
- f: (a: A, i: number) => Effect<B, E, R>,
853
+ filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, E, R, [i: number]>,
854
854
  options?: { readonly concurrency?: Concurrency | undefined }
855
- ): Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>
855
+ ): Effect<[excluded: Array<Fail>, satisfying: Array<Pass>], E, R>
856
856
  } = internal.partition
857
857
 
858
858
  /**
@@ -5198,15 +5198,14 @@ export const catchDefect: {
5198
5198
  } = internal.catchDefect
5199
5199
 
5200
5200
  /**
5201
- * Recovers from specific errors using a `Filter`, `Predicate`, or
5202
- * `Refinement`.
5201
+ * Recovers from specific errors using a `Predicate` or `Refinement`.
5203
5202
  *
5204
5203
  * **When to Use**
5205
5204
  *
5206
- * `catchIf` lets you recover from errors that match a condition. Pass a
5207
- * `Filter` for transformation, a `Refinement` for type narrowing, or a
5208
- * `Predicate` for simple boolean matching. Non-matching errors re-fail with
5209
- * the original cause. Defects and interrupts are not caught.
5205
+ * `catchIf` lets you recover from errors that match a condition. Use a
5206
+ * `Refinement` for type narrowing or a `Predicate` for simple boolean
5207
+ * matching. Non-matching errors re-fail with the original cause. Defects and
5208
+ * interrupts are not caught.
5210
5209
  *
5211
5210
  * **Previously Known As**
5212
5211
  *
@@ -5233,7 +5232,7 @@ export const catchDefect: {
5233
5232
  *
5234
5233
  * // With a Filter
5235
5234
  * const recovered2 = program.pipe(
5236
- * Effect.catchIf(
5235
+ * Effect.catchFilter(
5237
5236
  * Filter.tagged("NotFound"),
5238
5237
  * (error) => Effect.succeed(`missing:${error.id}`)
5239
5238
  * )
@@ -5245,15 +5244,14 @@ export const catchDefect: {
5245
5244
  */
5246
5245
  export const catchIf: {
5247
5246
  /**
5248
- * Recovers from specific errors using a `Filter`, `Predicate`, or
5249
- * `Refinement`.
5247
+ * Recovers from specific errors using a `Predicate` or `Refinement`.
5250
5248
  *
5251
5249
  * **When to Use**
5252
5250
  *
5253
- * `catchIf` lets you recover from errors that match a condition. Pass a
5254
- * `Filter` for transformation, a `Refinement` for type narrowing, or a
5255
- * `Predicate` for simple boolean matching. Non-matching errors re-fail with
5256
- * the original cause. Defects and interrupts are not caught.
5251
+ * `catchIf` lets you recover from errors that match a condition. Use a
5252
+ * `Refinement` for type narrowing or a `Predicate` for simple boolean
5253
+ * matching. Non-matching errors re-fail with the original cause. Defects and
5254
+ * interrupts are not caught.
5257
5255
  *
5258
5256
  * **Previously Known As**
5259
5257
  *
@@ -5280,7 +5278,7 @@ export const catchIf: {
5280
5278
  *
5281
5279
  * // With a Filter
5282
5280
  * const recovered2 = program.pipe(
5283
- * Effect.catchIf(
5281
+ * Effect.catchFilter(
5284
5282
  * Filter.tagged("NotFound"),
5285
5283
  * (error) => Effect.succeed(`missing:${error.id}`)
5286
5284
  * )
@@ -5296,15 +5294,14 @@ export const catchIf: {
5296
5294
  orElse?: ((e: Exclude<E, EB>) => Effect<A3, E3, R3>) | undefined
5297
5295
  ): <A, R>(self: Effect<A, E, R>) => Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
5298
5296
  /**
5299
- * Recovers from specific errors using a `Filter`, `Predicate`, or
5300
- * `Refinement`.
5297
+ * Recovers from specific errors using a `Predicate` or `Refinement`.
5301
5298
  *
5302
5299
  * **When to Use**
5303
5300
  *
5304
- * `catchIf` lets you recover from errors that match a condition. Pass a
5305
- * `Filter` for transformation, a `Refinement` for type narrowing, or a
5306
- * `Predicate` for simple boolean matching. Non-matching errors re-fail with
5307
- * the original cause. Defects and interrupts are not caught.
5301
+ * `catchIf` lets you recover from errors that match a condition. Use a
5302
+ * `Refinement` for type narrowing or a `Predicate` for simple boolean
5303
+ * matching. Non-matching errors re-fail with the original cause. Defects and
5304
+ * interrupts are not caught.
5308
5305
  *
5309
5306
  * **Previously Known As**
5310
5307
  *
@@ -5331,7 +5328,7 @@ export const catchIf: {
5331
5328
  *
5332
5329
  * // With a Filter
5333
5330
  * const recovered2 = program.pipe(
5334
- * Effect.catchIf(
5331
+ * Effect.catchFilter(
5335
5332
  * Filter.tagged("NotFound"),
5336
5333
  * (error) => Effect.succeed(`missing:${error.id}`)
5337
5334
  * )
@@ -5341,21 +5338,20 @@ export const catchIf: {
5341
5338
  * @since 2.0.0
5342
5339
  * @category Error Handling
5343
5340
  */
5344
- <E, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(
5345
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
5346
- f: (e: Filter.Pass<E, Result>) => Effect<A2, E2, R2>,
5347
- orElse?: ((e: Filter.Fail<E, Result>) => Effect<A3, E3, R3>) | undefined
5341
+ <E, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
5342
+ predicate: Predicate.Predicate<NoInfer<E>>,
5343
+ f: (e: NoInfer<E>) => Effect<A2, E2, R2>,
5344
+ orElse?: ((e: NoInfer<E>) => Effect<A3, E3, R3>) | undefined
5348
5345
  ): <A, R>(self: Effect<A, E, R>) => Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
5349
5346
  /**
5350
- * Recovers from specific errors using a `Filter`, `Predicate`, or
5351
- * `Refinement`.
5347
+ * Recovers from specific errors using a `Predicate` or `Refinement`.
5352
5348
  *
5353
5349
  * **When to Use**
5354
5350
  *
5355
- * `catchIf` lets you recover from errors that match a condition. Pass a
5356
- * `Filter` for transformation, a `Refinement` for type narrowing, or a
5357
- * `Predicate` for simple boolean matching. Non-matching errors re-fail with
5358
- * the original cause. Defects and interrupts are not caught.
5351
+ * `catchIf` lets you recover from errors that match a condition. Use a
5352
+ * `Refinement` for type narrowing or a `Predicate` for simple boolean
5353
+ * matching. Non-matching errors re-fail with the original cause. Defects and
5354
+ * interrupts are not caught.
5359
5355
  *
5360
5356
  * **Previously Known As**
5361
5357
  *
@@ -5382,7 +5378,7 @@ export const catchIf: {
5382
5378
  *
5383
5379
  * // With a Filter
5384
5380
  * const recovered2 = program.pipe(
5385
- * Effect.catchIf(
5381
+ * Effect.catchFilter(
5386
5382
  * Filter.tagged("NotFound"),
5387
5383
  * (error) => Effect.succeed(`missing:${error.id}`)
5388
5384
  * )
@@ -5399,15 +5395,14 @@ export const catchIf: {
5399
5395
  orElse?: ((e: Exclude<E, EB>) => Effect<A3, E3, R3>) | undefined
5400
5396
  ): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
5401
5397
  /**
5402
- * Recovers from specific errors using a `Filter`, `Predicate`, or
5403
- * `Refinement`.
5398
+ * Recovers from specific errors using a `Predicate` or `Refinement`.
5404
5399
  *
5405
5400
  * **When to Use**
5406
5401
  *
5407
- * `catchIf` lets you recover from errors that match a condition. Pass a
5408
- * `Filter` for transformation, a `Refinement` for type narrowing, or a
5409
- * `Predicate` for simple boolean matching. Non-matching errors re-fail with
5410
- * the original cause. Defects and interrupts are not caught.
5402
+ * `catchIf` lets you recover from errors that match a condition. Use a
5403
+ * `Refinement` for type narrowing or a `Predicate` for simple boolean
5404
+ * matching. Non-matching errors re-fail with the original cause. Defects and
5405
+ * interrupts are not caught.
5411
5406
  *
5412
5407
  * **Previously Known As**
5413
5408
  *
@@ -5434,7 +5429,7 @@ export const catchIf: {
5434
5429
  *
5435
5430
  * // With a Filter
5436
5431
  * const recovered2 = program.pipe(
5437
- * Effect.catchIf(
5432
+ * Effect.catchFilter(
5438
5433
  * Filter.tagged("NotFound"),
5439
5434
  * (error) => Effect.succeed(`missing:${error.id}`)
5440
5435
  * )
@@ -5444,14 +5439,46 @@ export const catchIf: {
5444
5439
  * @since 2.0.0
5445
5440
  * @category Error Handling
5446
5441
  */
5447
- <A, E, R, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(
5442
+ <A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
5448
5443
  self: Effect<A, E, R>,
5449
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
5450
- f: (e: Filter.Pass<E, Result>) => Effect<A2, E2, R2>,
5451
- orElse?: ((e: Filter.Fail<E, Result>) => Effect<A3, E3, R3>) | undefined
5444
+ predicate: Predicate.Predicate<E>,
5445
+ f: (e: E) => Effect<A2, E2, R2>,
5446
+ orElse?: ((e: E) => Effect<A3, E3, R3>) | undefined
5452
5447
  ): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
5453
5448
  } = internal.catchIf
5454
5449
 
5450
+ /**
5451
+ * Recovers from specific errors using a `Filter`.
5452
+ *
5453
+ * @since 4.0.0
5454
+ * @category Error Handling
5455
+ */
5456
+ export const catchFilter: {
5457
+ /**
5458
+ * Recovers from specific errors using a `Filter`.
5459
+ *
5460
+ * @since 4.0.0
5461
+ * @category Error Handling
5462
+ */
5463
+ <E, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
5464
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
5465
+ f: (e: EB) => Effect<A2, E2, R2>,
5466
+ orElse?: ((e: X) => Effect<A3, E3, R3>) | undefined
5467
+ ): <A, R>(self: Effect<A, E, R>) => Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
5468
+ /**
5469
+ * Recovers from specific errors using a `Filter`.
5470
+ *
5471
+ * @since 4.0.0
5472
+ * @category Error Handling
5473
+ */
5474
+ <A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
5475
+ self: Effect<A, E, R>,
5476
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
5477
+ f: (e: EB) => Effect<A2, E2, R2>,
5478
+ orElse?: ((e: X) => Effect<A3, E3, R3>) | undefined
5479
+ ): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
5480
+ } = internal.catchFilter
5481
+
5455
5482
  /**
5456
5483
  * Catches `NoSuchElementError` failures and converts them to `Option.none`.
5457
5484
  *
@@ -5559,10 +5586,10 @@ export const catchCauseIf: {
5559
5586
  * @since 4.0.0
5560
5587
  * @category Error Handling
5561
5588
  */
5562
- <E, Result extends Filter.ResultOrBool<Cause.Cause<any>>, B, E2, R2>(
5563
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
5564
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect<B, E2, R2>
5565
- ): <A, R>(self: Effect<A, E, R>) => Effect<A | B, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2>
5589
+ <E, B, E2, R2>(
5590
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
5591
+ f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
5592
+ ): <A, R>(self: Effect<A, E, R>) => Effect<A | B, E | E2, R | R2>
5566
5593
  /**
5567
5594
  * Recovers from specific failures based on a predicate.
5568
5595
  *
@@ -5601,13 +5628,43 @@ export const catchCauseIf: {
5601
5628
  * @since 4.0.0
5602
5629
  * @category Error Handling
5603
5630
  */
5604
- <A, E, R, B, E2, R2, Result extends Filter.ResultOrBool<Cause.Cause<any>>>(
5631
+ <A, E, R, B, E2, R2>(
5605
5632
  self: Effect<A, E, R>,
5606
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
5607
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect<B, E2, R2>
5608
- ): Effect<A | B, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2>
5633
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
5634
+ f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
5635
+ ): Effect<A | B, E | E2, R | R2>
5609
5636
  } = internal.catchCauseIf
5610
5637
 
5638
+ /**
5639
+ * Recovers from specific failures based on a `Filter`.
5640
+ *
5641
+ * @since 4.0.0
5642
+ * @category Error Handling
5643
+ */
5644
+ export const catchCauseFilter: {
5645
+ /**
5646
+ * Recovers from specific failures based on a `Filter`.
5647
+ *
5648
+ * @since 4.0.0
5649
+ * @category Error Handling
5650
+ */
5651
+ <E, B, E2, R2, EB, X extends Cause.Cause<any>>(
5652
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
5653
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
5654
+ ): <A, R>(self: Effect<A, E, R>) => Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
5655
+ /**
5656
+ * Recovers from specific failures based on a `Filter`.
5657
+ *
5658
+ * @since 4.0.0
5659
+ * @category Error Handling
5660
+ */
5661
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
5662
+ self: Effect<A, E, R>,
5663
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
5664
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
5665
+ ): Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
5666
+ } = internal.catchCauseFilter
5667
+
5611
5668
  /**
5612
5669
  * The `mapError` function is used to transform or modify the error
5613
5670
  * produced by an effect, without affecting its success value.
@@ -6233,9 +6290,9 @@ export const tapCauseIf: {
6233
6290
  * @since 4.0.0
6234
6291
  * @category Sequencing
6235
6292
  */
6236
- <E, Result extends Filter.ResultOrBool, B, E2, R2>(
6237
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
6238
- f: (a: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect<B, E2, R2>
6293
+ <E, B, E2, R2>(
6294
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
6295
+ f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
6239
6296
  ): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E2, R | R2>
6240
6297
  /**
6241
6298
  * Conditionally executes a side effect based on the cause of a failed effect.
@@ -6265,13 +6322,43 @@ export const tapCauseIf: {
6265
6322
  * @since 4.0.0
6266
6323
  * @category Sequencing
6267
6324
  */
6268
- <A, E, R, Result extends Filter.ResultOrBool, B, E2, R2>(
6325
+ <A, E, R, B, E2, R2>(
6269
6326
  self: Effect<A, E, R>,
6270
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
6271
- f: (a: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect<B, E2, R2>
6327
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
6328
+ f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
6272
6329
  ): Effect<A, E | E2, R | R2>
6273
6330
  } = internal.tapCauseIf
6274
6331
 
6332
+ /**
6333
+ * Conditionally executes a side effect based on the cause of a failed effect.
6334
+ *
6335
+ * @since 4.0.0
6336
+ * @category Sequencing
6337
+ */
6338
+ export const tapCauseFilter: {
6339
+ /**
6340
+ * Conditionally executes a side effect based on the cause of a failed effect.
6341
+ *
6342
+ * @since 4.0.0
6343
+ * @category Sequencing
6344
+ */
6345
+ <E, B, E2, R2, EB, X extends Cause.Cause<any>>(
6346
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
6347
+ f: (a: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
6348
+ ): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E2, R | R2>
6349
+ /**
6350
+ * Conditionally executes a side effect based on the cause of a failed effect.
6351
+ *
6352
+ * @since 4.0.0
6353
+ * @category Sequencing
6354
+ */
6355
+ <A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
6356
+ self: Effect<A, E, R>,
6357
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
6358
+ f: (a: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
6359
+ ): Effect<A, E | E2, R | R2>
6360
+ } = internal.tapCauseFilter
6361
+
6275
6362
  /**
6276
6363
  * Inspect severe errors or defects (non-recoverable failures) in an effect.
6277
6364
  *
@@ -8308,12 +8395,12 @@ export const raceFirst: {
8308
8395
  // -----------------------------------------------------------------------------
8309
8396
 
8310
8397
  /**
8311
- * Filters elements of an iterable using a predicate, refinement, effectful
8312
- * predicate, or `Filter.FilterEffect`.
8398
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8399
+ * predicate.
8313
8400
  *
8314
8401
  * @example
8315
8402
  * ```ts
8316
- * import { Effect, Filter, Result } from "effect"
8403
+ * import { Effect } from "effect"
8317
8404
  *
8318
8405
  * // Sync predicate
8319
8406
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8321,10 +8408,7 @@ export const raceFirst: {
8321
8408
  * // Effectful predicate
8322
8409
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8323
8410
  *
8324
- * // FilterEffect
8325
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8326
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8327
- * )
8411
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8328
8412
  * ```
8329
8413
  *
8330
8414
  * @since 2.0.0
@@ -8336,12 +8420,12 @@ export const filter: {
8336
8420
  // -----------------------------------------------------------------------------
8337
8421
 
8338
8422
  /**
8339
- * Filters elements of an iterable using a predicate, refinement, effectful
8340
- * predicate, or `Filter.FilterEffect`.
8423
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8424
+ * predicate.
8341
8425
  *
8342
8426
  * @example
8343
8427
  * ```ts
8344
- * import { Effect, Filter, Result } from "effect"
8428
+ * import { Effect } from "effect"
8345
8429
  *
8346
8430
  * // Sync predicate
8347
8431
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8349,10 +8433,7 @@ export const filter: {
8349
8433
  * // Effectful predicate
8350
8434
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8351
8435
  *
8352
- * // FilterEffect
8353
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8354
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8355
- * )
8436
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8356
8437
  * ```
8357
8438
  *
8358
8439
  * @since 2.0.0
@@ -8364,12 +8445,12 @@ export const filter: {
8364
8445
  // -----------------------------------------------------------------------------
8365
8446
 
8366
8447
  /**
8367
- * Filters elements of an iterable using a predicate, refinement, effectful
8368
- * predicate, or `Filter.FilterEffect`.
8448
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8449
+ * predicate.
8369
8450
  *
8370
8451
  * @example
8371
8452
  * ```ts
8372
- * import { Effect, Filter, Result } from "effect"
8453
+ * import { Effect } from "effect"
8373
8454
  *
8374
8455
  * // Sync predicate
8375
8456
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8377,10 +8458,7 @@ export const filter: {
8377
8458
  * // Effectful predicate
8378
8459
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8379
8460
  *
8380
- * // FilterEffect
8381
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8382
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8383
- * )
8461
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8384
8462
  * ```
8385
8463
  *
8386
8464
  * @since 2.0.0
@@ -8392,12 +8470,12 @@ export const filter: {
8392
8470
  // -----------------------------------------------------------------------------
8393
8471
 
8394
8472
  /**
8395
- * Filters elements of an iterable using a predicate, refinement, effectful
8396
- * predicate, or `Filter.FilterEffect`.
8473
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8474
+ * predicate.
8397
8475
  *
8398
8476
  * @example
8399
8477
  * ```ts
8400
- * import { Effect, Filter, Result } from "effect"
8478
+ * import { Effect } from "effect"
8401
8479
  *
8402
8480
  * // Sync predicate
8403
8481
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8405,30 +8483,27 @@ export const filter: {
8405
8483
  * // Effectful predicate
8406
8484
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8407
8485
  *
8408
- * // FilterEffect
8409
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8410
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8411
- * )
8486
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8412
8487
  * ```
8413
8488
  *
8414
8489
  * @since 2.0.0
8415
8490
  * @category Filtering
8416
8491
  */
8417
- <A, B, X>(
8418
- filter: Filter.Filter<NoInfer<A>, B, X>,
8492
+ <A, E, R>(
8493
+ predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
8419
8494
  options?: { readonly concurrency?: Concurrency | undefined }
8420
- ): (elements: Iterable<A>) => Effect<Array<B>>
8495
+ ): (iterable: Iterable<A>) => Effect<Array<A>, E, R>
8421
8496
  // -----------------------------------------------------------------------------
8422
8497
  // Filtering
8423
8498
  // -----------------------------------------------------------------------------
8424
8499
 
8425
8500
  /**
8426
- * Filters elements of an iterable using a predicate, refinement, effectful
8427
- * predicate, or `Filter.FilterEffect`.
8501
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8502
+ * predicate.
8428
8503
  *
8429
8504
  * @example
8430
8505
  * ```ts
8431
- * import { Effect, Filter, Result } from "effect"
8506
+ * import { Effect } from "effect"
8432
8507
  *
8433
8508
  * // Sync predicate
8434
8509
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8436,30 +8511,24 @@ export const filter: {
8436
8511
  * // Effectful predicate
8437
8512
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8438
8513
  *
8439
- * // FilterEffect
8440
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8441
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8442
- * )
8514
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8443
8515
  * ```
8444
8516
  *
8445
8517
  * @since 2.0.0
8446
8518
  * @category Filtering
8447
8519
  */
8448
- <A, B, X, E, R>(
8449
- filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
8450
- options?: { readonly concurrency?: Concurrency | undefined }
8451
- ): (elements: Iterable<A>) => Effect<Array<B>, E, R>
8520
+ <A, B extends A>(elements: Iterable<A>, refinement: Predicate.Refinement<A, B>): Effect<Array<B>>
8452
8521
  // -----------------------------------------------------------------------------
8453
8522
  // Filtering
8454
8523
  // -----------------------------------------------------------------------------
8455
8524
 
8456
8525
  /**
8457
- * Filters elements of an iterable using a predicate, refinement, effectful
8458
- * predicate, or `Filter.FilterEffect`.
8526
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8527
+ * predicate.
8459
8528
  *
8460
8529
  * @example
8461
8530
  * ```ts
8462
- * import { Effect, Filter, Result } from "effect"
8531
+ * import { Effect } from "effect"
8463
8532
  *
8464
8533
  * // Sync predicate
8465
8534
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8467,30 +8536,24 @@ export const filter: {
8467
8536
  * // Effectful predicate
8468
8537
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8469
8538
  *
8470
- * // FilterEffect
8471
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8472
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8473
- * )
8539
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8474
8540
  * ```
8475
8541
  *
8476
8542
  * @since 2.0.0
8477
8543
  * @category Filtering
8478
8544
  */
8479
- <A, E, R>(
8480
- predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
8481
- options?: { readonly concurrency?: Concurrency | undefined }
8482
- ): (iterable: Iterable<A>) => Effect<Array<A>, E, R>
8545
+ <A>(elements: Iterable<A>, predicate: Predicate.Predicate<A>): Effect<Array<A>>
8483
8546
  // -----------------------------------------------------------------------------
8484
8547
  // Filtering
8485
8548
  // -----------------------------------------------------------------------------
8486
8549
 
8487
8550
  /**
8488
- * Filters elements of an iterable using a predicate, refinement, effectful
8489
- * predicate, or `Filter.FilterEffect`.
8551
+ * Filters elements of an iterable using a predicate, refinement, or effectful
8552
+ * predicate.
8490
8553
  *
8491
8554
  * @example
8492
8555
  * ```ts
8493
- * import { Effect, Filter, Result } from "effect"
8556
+ * import { Effect } from "effect"
8494
8557
  *
8495
8558
  * // Sync predicate
8496
8559
  * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
@@ -8498,137 +8561,71 @@ export const filter: {
8498
8561
  * // Effectful predicate
8499
8562
  * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8500
8563
  *
8501
- * // FilterEffect
8502
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8503
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8504
- * )
8564
+ * // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
8505
8565
  * ```
8506
8566
  *
8507
8567
  * @since 2.0.0
8508
8568
  * @category Filtering
8509
8569
  */
8510
- <A, B extends A>(elements: Iterable<A>, refinement: Predicate.Refinement<A, B>): Effect<Array<B>>
8511
- // -----------------------------------------------------------------------------
8512
- // Filtering
8513
- // -----------------------------------------------------------------------------
8570
+ <A, E, R>(
8571
+ iterable: Iterable<A>,
8572
+ predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
8573
+ options?: { readonly concurrency?: Concurrency | undefined }
8574
+ ): Effect<Array<A>, E, R>
8575
+ } = internal.filter
8514
8576
 
8577
+ /**
8578
+ * Filters and maps elements of an iterable with a `Filter`.
8579
+ *
8580
+ * @since 4.0.0
8581
+ * @category Filtering
8582
+ */
8583
+ export const filterMap: {
8515
8584
  /**
8516
- * Filters elements of an iterable using a predicate, refinement, effectful
8517
- * predicate, or `Filter.FilterEffect`.
8518
- *
8519
- * @example
8520
- * ```ts
8521
- * import { Effect, Filter, Result } from "effect"
8585
+ * Filters and maps elements of an iterable with a `Filter`.
8522
8586
  *
8523
- * // Sync predicate
8524
- * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
8525
- *
8526
- * // Effectful predicate
8527
- * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8528
- *
8529
- * // FilterEffect
8530
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8531
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8532
- * )
8533
- * ```
8534
- *
8535
- * @since 2.0.0
8587
+ * @since 4.0.0
8536
8588
  * @category Filtering
8537
8589
  */
8538
- <A>(elements: Iterable<A>, predicate: Predicate.Predicate<A>): Effect<Array<A>>
8539
- // -----------------------------------------------------------------------------
8540
- // Filtering
8541
- // -----------------------------------------------------------------------------
8542
-
8590
+ <A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): (elements: Iterable<A>) => Effect<Array<B>>
8543
8591
  /**
8544
- * Filters elements of an iterable using a predicate, refinement, effectful
8545
- * predicate, or `Filter.FilterEffect`.
8592
+ * Filters and maps elements of an iterable with a `Filter`.
8546
8593
  *
8547
- * @example
8548
- * ```ts
8549
- * import { Effect, Filter, Result } from "effect"
8550
- *
8551
- * // Sync predicate
8552
- * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
8553
- *
8554
- * // Effectful predicate
8555
- * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8556
- *
8557
- * // FilterEffect
8558
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8559
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8560
- * )
8561
- * ```
8562
- *
8563
- * @since 2.0.0
8594
+ * @since 4.0.0
8564
8595
  * @category Filtering
8565
8596
  */
8566
8597
  <A, B, X>(elements: Iterable<A>, filter: Filter.Filter<NoInfer<A>, B, X>): Effect<Array<B>>
8567
- // -----------------------------------------------------------------------------
8568
- // Filtering
8569
- // -----------------------------------------------------------------------------
8598
+ } = internal.filterMap
8570
8599
 
8600
+ /**
8601
+ * Effectfully filters and maps elements of an iterable with a `FilterEffect`.
8602
+ *
8603
+ * @since 4.0.0
8604
+ * @category Filtering
8605
+ */
8606
+ export const filterMapEffect: {
8571
8607
  /**
8572
- * Filters elements of an iterable using a predicate, refinement, effectful
8573
- * predicate, or `Filter.FilterEffect`.
8574
- *
8575
- * @example
8576
- * ```ts
8577
- * import { Effect, Filter, Result } from "effect"
8578
- *
8579
- * // Sync predicate
8580
- * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
8581
- *
8582
- * // Effectful predicate
8583
- * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8584
- *
8585
- * // FilterEffect
8586
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8587
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8588
- * )
8589
- * ```
8608
+ * Effectfully filters and maps elements of an iterable with a `FilterEffect`.
8590
8609
  *
8591
- * @since 2.0.0
8610
+ * @since 4.0.0
8592
8611
  * @category Filtering
8593
8612
  */
8594
8613
  <A, B, X, E, R>(
8595
- elements: Iterable<A>,
8596
8614
  filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
8597
8615
  options?: { readonly concurrency?: Concurrency | undefined }
8598
- ): Effect<Array<B>, E, R>
8599
- // -----------------------------------------------------------------------------
8600
- // Filtering
8601
- // -----------------------------------------------------------------------------
8602
-
8616
+ ): (elements: Iterable<A>) => Effect<Array<B>, E, R>
8603
8617
  /**
8604
- * Filters elements of an iterable using a predicate, refinement, effectful
8605
- * predicate, or `Filter.FilterEffect`.
8618
+ * Effectfully filters and maps elements of an iterable with a `FilterEffect`.
8606
8619
  *
8607
- * @example
8608
- * ```ts
8609
- * import { Effect, Filter, Result } from "effect"
8610
- *
8611
- * // Sync predicate
8612
- * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
8613
- *
8614
- * // Effectful predicate
8615
- * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
8616
- *
8617
- * // FilterEffect
8618
- * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
8619
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
8620
- * )
8621
- * ```
8622
- *
8623
- * @since 2.0.0
8620
+ * @since 4.0.0
8624
8621
  * @category Filtering
8625
8622
  */
8626
- <A, E, R>(
8627
- iterable: Iterable<A>,
8628
- predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
8623
+ <A, B, X, E, R>(
8624
+ elements: Iterable<A>,
8625
+ filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
8629
8626
  options?: { readonly concurrency?: Concurrency | undefined }
8630
- ): Effect<Array<A>, E, R>
8631
- } = internal.filter
8627
+ ): Effect<Array<B>, E, R>
8628
+ } = internal.filterMapEffect
8632
8629
 
8633
8630
  /**
8634
8631
  * Filters an effect, providing an alternative effect if the predicate fails.
@@ -8725,10 +8722,10 @@ export const filterOrElse: {
8725
8722
  * @since 2.0.0
8726
8723
  * @category Filtering
8727
8724
  */
8728
- <A, Result extends Filter.ResultOrBool, C, E2, R2>(
8729
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
8730
- orElse: (a: Filter.Fail<A, Result>) => Effect<C, E2, R2>
8731
- ): <E, R>(self: Effect<A, E, R>) => Effect<Filter.Pass<A, Result> | C, E2 | E, R2 | R>
8725
+ <A, C, E2, R2>(
8726
+ predicate: Predicate.Predicate<NoInfer<A>>,
8727
+ orElse: (a: NoInfer<A>) => Effect<C, E2, R2>
8728
+ ): <E, R>(self: Effect<A, E, R>) => Effect<A | C, E2 | E, R2 | R>
8732
8729
  /**
8733
8730
  * Filters an effect, providing an alternative effect if the predicate fails.
8734
8731
  *
@@ -8794,13 +8791,43 @@ export const filterOrElse: {
8794
8791
  * @since 2.0.0
8795
8792
  * @category Filtering
8796
8793
  */
8797
- <A, E, R, Result extends Filter.ResultOrBool, C, E2, R2>(
8794
+ <A, E, R, C, E2, R2>(
8798
8795
  self: Effect<A, E, R>,
8799
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
8800
- orElse: (a: Filter.Fail<A, Result>) => Effect<C, E2, R2>
8801
- ): Effect<Filter.Pass<A, Result> | C, E | E2, R | R2>
8796
+ predicate: Predicate.Predicate<NoInfer<A>>,
8797
+ orElse: (a: NoInfer<A>) => Effect<C, E2, R2>
8798
+ ): Effect<A | C, E | E2, R | R2>
8802
8799
  } = internal.filterOrElse
8803
8800
 
8801
+ /**
8802
+ * Filters an effect with a `Filter`, providing an alternative effect on failure.
8803
+ *
8804
+ * @since 4.0.0
8805
+ * @category Filtering
8806
+ */
8807
+ export const filterMapOrElse: {
8808
+ /**
8809
+ * Filters an effect with a `Filter`, providing an alternative effect on failure.
8810
+ *
8811
+ * @since 4.0.0
8812
+ * @category Filtering
8813
+ */
8814
+ <A, B, X, C, E2, R2>(
8815
+ filter: Filter.Filter<NoInfer<A>, B, X>,
8816
+ orElse: (x: X) => Effect<C, E2, R2>
8817
+ ): <E, R>(self: Effect<A, E, R>) => Effect<B | C, E2 | E, R2 | R>
8818
+ /**
8819
+ * Filters an effect with a `Filter`, providing an alternative effect on failure.
8820
+ *
8821
+ * @since 4.0.0
8822
+ * @category Filtering
8823
+ */
8824
+ <A, E, R, B, X, C, E2, R2>(
8825
+ self: Effect<A, E, R>,
8826
+ filter: Filter.Filter<NoInfer<A>, B, X>,
8827
+ orElse: (x: X) => Effect<C, E2, R2>
8828
+ ): Effect<B | C, E | E2, R | R2>
8829
+ } = internal.filterMapOrElse
8830
+
8804
8831
  /**
8805
8832
  * Filters an effect, failing with a custom error if the predicate fails.
8806
8833
  *
@@ -8897,36 +8924,6 @@ export const filterOrFail: {
8897
8924
  predicate: Predicate.Predicate<NoInfer<A>>,
8898
8925
  orFailWith: (a: NoInfer<A>) => E2
8899
8926
  ): <E, R>(self: Effect<A, E, R>) => Effect<A, E2 | E, R>
8900
- /**
8901
- * Filters an effect, failing with a custom error if the predicate fails.
8902
- *
8903
- * **Details**
8904
- *
8905
- * This function applies a predicate to the result of an effect. If the
8906
- * predicate evaluates to `false`, the effect fails with either a custom
8907
- * error (if `orFailWith` is provided) or a `NoSuchElementError`.
8908
- *
8909
- * @example
8910
- * ```ts
8911
- * import { Effect } from "effect"
8912
- *
8913
- * // An effect that produces a number
8914
- * const program = Effect.succeed(5)
8915
- *
8916
- * // Filter for even numbers, fail for odd numbers
8917
- * const filtered = Effect.filterOrFail(
8918
- * program,
8919
- * (n) => n % 2 === 0,
8920
- * (n) => `Expected even number, got ${n}`
8921
- * )
8922
- *
8923
- * // Result: Effect.fail("Expected even number, got 5")
8924
- * ```
8925
- *
8926
- * @since 2.0.0
8927
- * @category Filtering
8928
- */
8929
- <A, B, X, E2>(filter: Filter.Filter<NoInfer<A>, B, X>, orFailWith: (x: X) => E2): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>
8930
8927
  /**
8931
8928
  * Filters an effect, failing with a custom error if the predicate fails.
8932
8929
  *
@@ -8987,36 +8984,6 @@ export const filterOrFail: {
8987
8984
  * @category Filtering
8988
8985
  */
8989
8986
  <A>(predicate: Predicate.Predicate<NoInfer<A>>): <E, R>(self: Effect<A, E, R>) => Effect<A, Cause.NoSuchElementError | E, R>
8990
- /**
8991
- * Filters an effect, failing with a custom error if the predicate fails.
8992
- *
8993
- * **Details**
8994
- *
8995
- * This function applies a predicate to the result of an effect. If the
8996
- * predicate evaluates to `false`, the effect fails with either a custom
8997
- * error (if `orFailWith` is provided) or a `NoSuchElementError`.
8998
- *
8999
- * @example
9000
- * ```ts
9001
- * import { Effect } from "effect"
9002
- *
9003
- * // An effect that produces a number
9004
- * const program = Effect.succeed(5)
9005
- *
9006
- * // Filter for even numbers, fail for odd numbers
9007
- * const filtered = Effect.filterOrFail(
9008
- * program,
9009
- * (n) => n % 2 === 0,
9010
- * (n) => `Expected even number, got ${n}`
9011
- * )
9012
- *
9013
- * // Result: Effect.fail("Expected even number, got 5")
9014
- * ```
9015
- *
9016
- * @since 2.0.0
9017
- * @category Filtering
9018
- */
9019
- <A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementError | E, R>
9020
8987
  /**
9021
8988
  * Filters an effect, failing with a custom error if the predicate fails.
9022
8989
  *
@@ -9114,11 +9081,7 @@ export const filterOrFail: {
9114
9081
  * @since 2.0.0
9115
9082
  * @category Filtering
9116
9083
  */
9117
- <A, E, R, B, X, E2>(
9118
- self: Effect<A, E, R>,
9119
- filter: Filter.Filter<A, B, X>,
9120
- orFailWith: (x: X) => E2
9121
- ): Effect<B, E2 | E, R>
9084
+ <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Predicate.Refinement<NoInfer<A>, B>): Effect<B, E | Cause.NoSuchElementError, R>
9122
9085
  /**
9123
9086
  * Filters an effect, failing with a custom error if the predicate fails.
9124
9087
  *
@@ -9148,68 +9111,49 @@ export const filterOrFail: {
9148
9111
  * @since 2.0.0
9149
9112
  * @category Filtering
9150
9113
  */
9151
- <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Predicate.Refinement<NoInfer<A>, B>): Effect<B, E | Cause.NoSuchElementError, R>
9114
+ <A, E, R>(self: Effect<A, E, R>, predicate: Predicate.Predicate<NoInfer<A>>): Effect<A, E | Cause.NoSuchElementError, R>
9115
+ } = internal.filterOrFail
9116
+
9117
+ /**
9118
+ * Filters an effect with a `Filter`, failing when the filter fails.
9119
+ *
9120
+ * @since 4.0.0
9121
+ * @category Filtering
9122
+ */
9123
+ export const filterMapOrFail: {
9152
9124
  /**
9153
- * Filters an effect, failing with a custom error if the predicate fails.
9154
- *
9155
- * **Details**
9156
- *
9157
- * This function applies a predicate to the result of an effect. If the
9158
- * predicate evaluates to `false`, the effect fails with either a custom
9159
- * error (if `orFailWith` is provided) or a `NoSuchElementError`.
9160
- *
9161
- * @example
9162
- * ```ts
9163
- * import { Effect } from "effect"
9164
- *
9165
- * // An effect that produces a number
9166
- * const program = Effect.succeed(5)
9125
+ * Filters an effect with a `Filter`, failing when the filter fails.
9167
9126
  *
9168
- * // Filter for even numbers, fail for odd numbers
9169
- * const filtered = Effect.filterOrFail(
9170
- * program,
9171
- * (n) => n % 2 === 0,
9172
- * (n) => `Expected even number, got ${n}`
9173
- * )
9174
- *
9175
- * // Result: Effect.fail("Expected even number, got 5")
9176
- * ```
9177
- *
9178
- * @since 2.0.0
9127
+ * @since 4.0.0
9179
9128
  * @category Filtering
9180
9129
  */
9181
- <A, E, R>(self: Effect<A, E, R>, predicate: Predicate.Predicate<NoInfer<A>>): Effect<A, E | Cause.NoSuchElementError, R>
9130
+ <A, B, X, E2>(filter: Filter.Filter<NoInfer<A>, B, X>, orFailWith: (x: X) => E2): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>
9182
9131
  /**
9183
- * Filters an effect, failing with a custom error if the predicate fails.
9132
+ * Filters an effect with a `Filter`, failing when the filter fails.
9184
9133
  *
9185
- * **Details**
9186
- *
9187
- * This function applies a predicate to the result of an effect. If the
9188
- * predicate evaluates to `false`, the effect fails with either a custom
9189
- * error (if `orFailWith` is provided) or a `NoSuchElementError`.
9190
- *
9191
- * @example
9192
- * ```ts
9193
- * import { Effect } from "effect"
9194
- *
9195
- * // An effect that produces a number
9196
- * const program = Effect.succeed(5)
9197
- *
9198
- * // Filter for even numbers, fail for odd numbers
9199
- * const filtered = Effect.filterOrFail(
9200
- * program,
9201
- * (n) => n % 2 === 0,
9202
- * (n) => `Expected even number, got ${n}`
9203
- * )
9134
+ * @since 4.0.0
9135
+ * @category Filtering
9136
+ */
9137
+ <A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementError | E, R>
9138
+ /**
9139
+ * Filters an effect with a `Filter`, failing when the filter fails.
9204
9140
  *
9205
- * // Result: Effect.fail("Expected even number, got 5")
9206
- * ```
9141
+ * @since 4.0.0
9142
+ * @category Filtering
9143
+ */
9144
+ <A, E, R, B, X, E2>(
9145
+ self: Effect<A, E, R>,
9146
+ filter: Filter.Filter<A, B, X>,
9147
+ orFailWith: (x: X) => E2
9148
+ ): Effect<B, E2 | E, R>
9149
+ /**
9150
+ * Filters an effect with a `Filter`, failing when the filter fails.
9207
9151
  *
9208
- * @since 2.0.0
9152
+ * @since 4.0.0
9209
9153
  * @category Filtering
9210
9154
  */
9211
- <A, E, R, B, X>(self: Effect<A, E, R>, filter: Filter.Filter<A, B, X>): Effect<B, E | Cause.NoSuchElementError, R>
9212
- } = internal.filterOrFail
9155
+ <A, E, R, B, X>(self: Effect<A, E, R>, filter: Filter.Filter<A, B, X>): Effect<B, Cause.NoSuchElementError | E, R>
9156
+ } = internal.filterMapOrFail
9213
9157
 
9214
9158
  // -----------------------------------------------------------------------------
9215
9159
  // Conditional Operators
@@ -12160,7 +12104,7 @@ export const onError: {
12160
12104
 
12161
12105
  /**
12162
12106
  * Runs the finalizer only when this effect fails and the `Cause` matches the
12163
- * filter, passing the filtered failure and the original cause.
12107
+ * provided predicate.
12164
12108
  *
12165
12109
  * @example
12166
12110
  * ```ts
@@ -12184,7 +12128,7 @@ export const onError: {
12184
12128
  export const onErrorIf: {
12185
12129
  /**
12186
12130
  * Runs the finalizer only when this effect fails and the `Cause` matches the
12187
- * filter, passing the filtered failure and the original cause.
12131
+ * provided predicate.
12188
12132
  *
12189
12133
  * @example
12190
12134
  * ```ts
@@ -12205,13 +12149,13 @@ export const onErrorIf: {
12205
12149
  * @since 4.0.0
12206
12150
  * @category Resource Management & Finalization
12207
12151
  */
12208
- <E, Result extends Filter.ResultOrBool, XE, XR>(
12209
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
12210
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect<void, XE, XR>
12152
+ <E, XE, XR>(
12153
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
12154
+ f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>
12211
12155
  ): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
12212
12156
  /**
12213
12157
  * Runs the finalizer only when this effect fails and the `Cause` matches the
12214
- * filter, passing the filtered failure and the original cause.
12158
+ * provided predicate.
12215
12159
  *
12216
12160
  * @example
12217
12161
  * ```ts
@@ -12232,13 +12176,43 @@ export const onErrorIf: {
12232
12176
  * @since 4.0.0
12233
12177
  * @category Resource Management & Finalization
12234
12178
  */
12235
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
12179
+ <A, E, R, XE, XR>(
12236
12180
  self: Effect<A, E, R>,
12237
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
12238
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Effect<void, XE, XR>
12181
+ predicate: Predicate.Predicate<Cause.Cause<E>>,
12182
+ f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>
12239
12183
  ): Effect<A, E | XE, R | XR>
12240
12184
  } = internal.onErrorIf
12241
12185
 
12186
+ /**
12187
+ * Runs the finalizer only when this effect fails and the cause matches the provided `Filter`.
12188
+ *
12189
+ * @since 4.0.0
12190
+ * @category Resource Management & Finalization
12191
+ */
12192
+ export const onErrorFilter: {
12193
+ /**
12194
+ * Runs the finalizer only when this effect fails and the cause matches the provided `Filter`.
12195
+ *
12196
+ * @since 4.0.0
12197
+ * @category Resource Management & Finalization
12198
+ */
12199
+ <A, E, EB, X, XE, XR>(
12200
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
12201
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect<void, XE, XR>
12202
+ ): <R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
12203
+ /**
12204
+ * Runs the finalizer only when this effect fails and the cause matches the provided `Filter`.
12205
+ *
12206
+ * @since 4.0.0
12207
+ * @category Resource Management & Finalization
12208
+ */
12209
+ <A, E, R, EB, X, XE, XR>(
12210
+ self: Effect<A, E, R>,
12211
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
12212
+ f: (failure: EB, cause: Cause.Cause<E>) => Effect<void, XE, XR>
12213
+ ): Effect<A, E | XE, R | XR>
12214
+ } = internal.onErrorFilter
12215
+
12242
12216
  /**
12243
12217
  * The low level primitive that powers `onExit`.
12244
12218
  * function is used to run a finalizer when the effect exits, regardless of the
@@ -12337,20 +12311,20 @@ export const onExit: {
12337
12311
  } = internal.onExit
12338
12312
 
12339
12313
  /**
12340
- * Runs the cleanup effect only when the `Exit` passes the provided filter.
12341
- *
12342
- * The cleanup is skipped when the filter returns `Filter.fail`.
12314
+ * Runs the cleanup effect only when the `Exit` satisfies the provided
12315
+ * predicate.
12343
12316
  *
12344
12317
  * @example
12345
12318
  * ```ts
12346
- * import { Console, Effect, Exit, Filter } from "effect"
12347
- *
12348
- * const exitFilter = Filter.fromPredicate(Exit.isSuccess<number, never>)
12319
+ * import { Console, Effect, Exit } from "effect"
12349
12320
  *
12350
12321
  * const program = Effect.onExitIf(
12351
12322
  * Effect.succeed(42),
12352
- * exitFilter,
12353
- * (success) => Console.log(`Succeeded with: ${success.value}`)
12323
+ * Exit.isSuccess,
12324
+ * (exit) =>
12325
+ * Exit.isSuccess(exit)
12326
+ * ? Console.log(`Succeeded with: ${exit.value}`)
12327
+ * : Effect.void
12354
12328
  * )
12355
12329
  * ```
12356
12330
  *
@@ -12359,64 +12333,88 @@ export const onExit: {
12359
12333
  */
12360
12334
  export const onExitIf: {
12361
12335
  /**
12362
- * Runs the cleanup effect only when the `Exit` passes the provided filter.
12363
- *
12364
- * The cleanup is skipped when the filter returns `Filter.fail`.
12336
+ * Runs the cleanup effect only when the `Exit` satisfies the provided
12337
+ * predicate.
12365
12338
  *
12366
12339
  * @example
12367
12340
  * ```ts
12368
- * import { Console, Effect, Exit, Filter } from "effect"
12369
- *
12370
- * const exitFilter = Filter.fromPredicate(Exit.isSuccess<number, never>)
12341
+ * import { Console, Effect, Exit } from "effect"
12371
12342
  *
12372
12343
  * const program = Effect.onExitIf(
12373
12344
  * Effect.succeed(42),
12374
- * exitFilter,
12375
- * (success) => Console.log(`Succeeded with: ${success.value}`)
12345
+ * Exit.isSuccess,
12346
+ * (exit) =>
12347
+ * Exit.isSuccess(exit)
12348
+ * ? Console.log(`Succeeded with: ${exit.value}`)
12349
+ * : Effect.void
12376
12350
  * )
12377
12351
  * ```
12378
12352
  *
12379
12353
  * @since 4.0.0
12380
12354
  * @category Resource Management & Finalization
12381
12355
  */
12382
- <A, E, XE, XR, Result extends Filter.ResultOrBool>(
12383
- filter: Filter.OrPredicate<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
12384
- f: (
12385
- pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
12386
- exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
12387
- ) => Effect<void, XE, XR>
12356
+ <A, E, XE, XR>(
12357
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
12358
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
12388
12359
  ): <R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
12389
12360
  /**
12390
- * Runs the cleanup effect only when the `Exit` passes the provided filter.
12391
- *
12392
- * The cleanup is skipped when the filter returns `Filter.fail`.
12361
+ * Runs the cleanup effect only when the `Exit` satisfies the provided
12362
+ * predicate.
12393
12363
  *
12394
12364
  * @example
12395
12365
  * ```ts
12396
- * import { Console, Effect, Exit, Filter } from "effect"
12397
- *
12398
- * const exitFilter = Filter.fromPredicate(Exit.isSuccess<number, never>)
12366
+ * import { Console, Effect, Exit } from "effect"
12399
12367
  *
12400
12368
  * const program = Effect.onExitIf(
12401
12369
  * Effect.succeed(42),
12402
- * exitFilter,
12403
- * (success) => Console.log(`Succeeded with: ${success.value}`)
12370
+ * Exit.isSuccess,
12371
+ * (exit) =>
12372
+ * Exit.isSuccess(exit)
12373
+ * ? Console.log(`Succeeded with: ${exit.value}`)
12374
+ * : Effect.void
12404
12375
  * )
12405
12376
  * ```
12406
12377
  *
12407
12378
  * @since 4.0.0
12408
12379
  * @category Resource Management & Finalization
12409
12380
  */
12410
- <A, E, R, XE, XR, Result extends Filter.ResultOrBool>(
12381
+ <A, E, R, XE, XR>(
12411
12382
  self: Effect<A, E, R>,
12412
- filter: Filter.OrPredicate<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
12413
- f: (
12414
- pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
12415
- exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
12416
- ) => Effect<void, XE, XR>
12383
+ predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
12384
+ f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
12417
12385
  ): Effect<A, E | XE, R | XR>
12418
12386
  } = internal.onExitIf
12419
12387
 
12388
+ /**
12389
+ * Runs the cleanup effect only when the `Exit` matches the provided `Filter`.
12390
+ *
12391
+ * @since 4.0.0
12392
+ * @category Resource Management & Finalization
12393
+ */
12394
+ export const onExitFilter: {
12395
+ /**
12396
+ * Runs the cleanup effect only when the `Exit` matches the provided `Filter`.
12397
+ *
12398
+ * @since 4.0.0
12399
+ * @category Resource Management & Finalization
12400
+ */
12401
+ <A, E, XE, XR, B, X>(
12402
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
12403
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
12404
+ ): <R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
12405
+ /**
12406
+ * Runs the cleanup effect only when the `Exit` matches the provided `Filter`.
12407
+ *
12408
+ * @since 4.0.0
12409
+ * @category Resource Management & Finalization
12410
+ */
12411
+ <A, E, R, XE, XR, B, X>(
12412
+ self: Effect<A, E, R>,
12413
+ filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
12414
+ f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
12415
+ ): Effect<A, E | XE, R | XR>
12416
+ } = internal.onExitFilter
12417
+
12420
12418
  // -----------------------------------------------------------------------------
12421
12419
  // Caching
12422
12420
  // -----------------------------------------------------------------------------
@@ -22381,136 +22379,70 @@ export class Transaction extends ServiceMap.Service<
22381
22379
  >()("effect/Effect/Transaction") {}
22382
22380
 
22383
22381
  /**
22384
- * Defines a transaction. Transactions are "all or nothing" with respect to changes made to
22385
- * transactional values (i.e. TxRef) that occur within the transaction body.
22382
+ * Accesses the current transaction state within an active transaction.
22386
22383
  *
22387
- * In Effect transactions are optimistic with retry, that means transactions are retried when:
22388
- *
22389
- * - the body of the transaction explicitely calls to `Effect.retryTransaction` and any of the
22390
- * accessed transactional values changes.
22391
- *
22392
- * - any of the accessed transactional values change during the execution of the transaction
22393
- * due to a different transaction committing before the current.
22394
- *
22395
- * - parent transaction retry, if you have a transaction within another transaction and
22396
- * the parent retries the child will also retry together with the parent.
22384
+ * This function requires `Transaction` in the context and does NOT create or strip
22385
+ * transaction boundaries. Use it to interact with the transaction journal (e.g. in
22386
+ * `TxRef` internals). To define a transaction boundary, use {@link transaction}.
22397
22387
  *
22398
22388
  * @example
22399
22389
  * ```ts
22400
22390
  * import { Effect, TxRef } from "effect"
22401
22391
  *
22402
22392
  * const program = Effect.gen(function*() {
22403
- * const ref1 = yield* TxRef.make(0)
22404
- * const ref2 = yield* TxRef.make(0)
22405
- *
22406
- * // All operations within atomic block succeed or fail together
22407
- * yield* Effect.atomic(Effect.gen(function*() {
22408
- * yield* TxRef.set(ref1, 10)
22409
- * yield* TxRef.set(ref2, 20)
22410
- * const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
22411
- * console.log(`Transaction sum: ${sum}`)
22412
- * }))
22413
- *
22414
- * console.log(`Final ref1: ${yield* TxRef.get(ref1)}`) // 10
22415
- * console.log(`Final ref2: ${yield* TxRef.get(ref2)}`) // 20
22416
- * })
22417
- * ```
22418
- *
22419
- * @since 4.0.0
22420
- * @category Transactions
22421
- */
22422
- export const atomic = <A, E, R>(
22423
- effect: Effect<A, E, R>
22424
- ): Effect<A, E, Exclude<R, Transaction>> => atomicWith(() => effect)
22425
-
22426
- /**
22427
- * Executes a function within a transaction context, providing access to the transaction state.
22428
- *
22429
- * @example
22430
- * ```ts
22431
- * import { Effect, TxRef } from "effect"
22432
- *
22433
- * const program = Effect.atomicWith((txState) =>
22434
- * Effect.gen(function*() {
22435
- * const ref = yield* TxRef.make(0)
22436
- *
22437
- * // Access transaction state for debugging
22438
- * console.log(`Journal size: ${txState.journal.size}`)
22439
- * console.log(`Retry flag: ${txState.retry}`)
22393
+ * const ref = yield* Effect.transaction(TxRef.make(0))
22440
22394
  *
22395
+ * yield* Effect.transaction(Effect.gen(function*() {
22441
22396
  * yield* TxRef.set(ref, 42)
22442
22397
  * return yield* TxRef.get(ref)
22443
- * })
22444
- * )
22445
- *
22446
- * Effect.runPromise(program).then(console.log) // 42
22398
+ * }))
22399
+ * })
22447
22400
  * ```
22448
22401
  *
22449
22402
  * @since 4.0.0
22450
22403
  * @category Transactions
22451
22404
  */
22452
- export const atomicWith = <A, E, R>(
22405
+ export const withTxState = <A, E, R>(
22453
22406
  f: (state: Transaction["Service"]) => Effect<A, E, R>
22454
- ): Effect<A, E, Exclude<R, Transaction>> =>
22455
- withFiber((fiber) => {
22456
- // Check if transaction already exists and reuse it (composing behavior)
22457
- if (fiber.services.mapUnsafe.has(Transaction.key)) {
22458
- return internalCall(() => f(ServiceMap.getUnsafe(fiber.services, Transaction))) as Effect<
22459
- A,
22460
- E,
22461
- Exclude<R, Transaction>
22462
- >
22463
- }
22464
- // No existing transaction, create isolated one using transactionWith
22465
- return transactionWith(f)
22466
- })
22407
+ ): Effect<A, E, R | Transaction> =>
22408
+ flatMap(
22409
+ Transaction.asEffect(),
22410
+ (state) => internalCall(() => f(state))
22411
+ )
22467
22412
 
22468
22413
  /**
22469
- * Creates an isolated transaction that never composes with parent transactions.
22414
+ * Defines a transaction boundary. Transactions are "all or nothing" with respect to changes
22415
+ * made to transactional values (i.e. TxRef) that occur within the transaction body.
22470
22416
  *
22471
- * **Details**
22417
+ * In Effect transactions are optimistic with retry, that means transactions are retried when:
22472
22418
  *
22473
- * Unlike `Effect.atomic`, which composes with parent transactions when nested,
22474
- * `Effect.transaction` always creates a new isolated transaction boundary.
22475
- * This ensures complete isolation between different transaction scopes.
22419
+ * - the body of the transaction explicitely calls to `Effect.retryTransaction` and any of the
22420
+ * accessed transactional values changes.
22476
22421
  *
22477
- * **Key Differences from Effect.atomic:**
22478
- * - Always creates a new transaction, even when called within another transaction
22479
- * - Parent transaction failures don't affect isolated transactions
22480
- * - Isolated transaction failures don't affect parent transactions
22481
- * - Each transaction has its own journal and retry logic
22422
+ * - any of the accessed transactional values change during the execution of the transaction
22423
+ * due to a different transaction committing before the current.
22482
22424
  *
22483
- * **When to Use:**
22484
- * - When you need guaranteed isolation between transaction scopes
22485
- * - For implementing independent operations that shouldn't be affected by outer transactions
22486
- * - When building transaction-based systems where isolation is critical
22425
+ * Each call to `transaction` always creates a new isolated transaction boundary with its own
22426
+ * journal and retry logic.
22487
22427
  *
22488
22428
  * @example
22489
22429
  * ```ts
22490
22430
  * import { Effect, TxRef } from "effect"
22491
22431
  *
22492
22432
  * const program = Effect.gen(function*() {
22493
- * const ref1 = yield* TxRef.make(0)
22494
- * const ref2 = yield* TxRef.make(100)
22433
+ * const ref1 = yield* Effect.transaction(TxRef.make(0))
22434
+ * const ref2 = yield* Effect.transaction(TxRef.make(0))
22495
22435
  *
22496
- * // Nested atomic transaction - ref1 will be part of outer transaction
22497
- * yield* Effect.atomic(Effect.gen(function*() {
22498
- * yield* TxRef.set(ref1, 10)
22499
- *
22500
- * // This atomic operation composes with the parent
22501
- * yield* Effect.atomic(Effect.gen(function*() {
22502
- * yield* TxRef.set(ref1, 20) // Part of same transaction
22503
- * }))
22504
- * }))
22505
- *
22506
- * // Isolated transaction - ref2 will be in its own transaction
22436
+ * // All operations within transaction block succeed or fail together
22507
22437
  * yield* Effect.transaction(Effect.gen(function*() {
22508
- * yield* TxRef.set(ref2, 200)
22438
+ * yield* TxRef.set(ref1, 10)
22439
+ * yield* TxRef.set(ref2, 20)
22440
+ * const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
22441
+ * console.log(`Transaction sum: ${sum}`)
22509
22442
  * }))
22510
22443
  *
22511
- * const val1 = yield* TxRef.get(ref1) // 20
22512
- * const val2 = yield* TxRef.get(ref2) // 200
22513
- * return { ref1: val1, ref2: val2 }
22444
+ * console.log(`Final ref1: ${yield* Effect.transaction(TxRef.get(ref1))}`) // 10
22445
+ * console.log(`Final ref2: ${yield* Effect.transaction(TxRef.get(ref2))}`) // 20
22514
22446
  * })
22515
22447
  * ```
22516
22448
  *
@@ -22522,34 +22454,21 @@ export const transaction = <A, E, R>(
22522
22454
  ): Effect<A, E, Exclude<R, Transaction>> => transactionWith(() => effect)
22523
22455
 
22524
22456
  /**
22525
- * Executes a function within an isolated transaction context, providing access to the transaction state.
22457
+ * Like {@link transaction} but provides access to the transaction state.
22526
22458
  *
22527
- * This function always creates a new transaction boundary, regardless of whether it's called
22528
- * within another transaction. This ensures complete isolation between transaction scopes.
22459
+ * Always creates a new isolated transaction boundary with its own journal and retry logic.
22529
22460
  *
22530
22461
  * @example
22531
22462
  * ```ts
22532
22463
  * import { Effect, TxRef } from "effect"
22533
22464
  *
22534
- * const program = Effect.transactionWith((txState) =>
22465
+ * const program = Effect.transactionWith((_txState) =>
22535
22466
  * Effect.gen(function*() {
22536
22467
  * const ref = yield* TxRef.make(0)
22537
- *
22538
- * // This transaction is isolated - it has its own journal
22539
- * // txState.journal is independent of any parent transaction
22540
- *
22541
22468
  * yield* TxRef.set(ref, 42)
22542
22469
  * return yield* TxRef.get(ref)
22543
22470
  * })
22544
22471
  * )
22545
- *
22546
- * // Even when nested in another atomic block, this transaction is isolated
22547
- * const nestedProgram = Effect.atomic(
22548
- * Effect.gen(function*() {
22549
- * const result = yield* program // Runs in its own isolated transaction
22550
- * return result
22551
- * })
22552
- * )
22553
22472
  * ```
22554
22473
  *
22555
22474
  * @since 4.0.0
@@ -22657,16 +22576,16 @@ function clearTransaction(state: Transaction["Service"]) {
22657
22576
  *
22658
22577
  * const program = Effect.gen(function*() {
22659
22578
  * // create a transactional reference
22660
- * const ref = yield* TxRef.make(0)
22579
+ * const ref = yield* Effect.transaction(TxRef.make(0))
22661
22580
  *
22662
22581
  * // forks a fiber that increases the value of `ref` every 100 millis
22663
22582
  * yield* Effect.forkChild(Effect.forever(
22664
22583
  * // update to transactional value
22665
- * TxRef.update(ref, (n) => n + 1).pipe(Effect.delay("100 millis"))
22584
+ * Effect.transaction(TxRef.update(ref, (n) => n + 1)).pipe(Effect.delay("100 millis"))
22666
22585
  * ))
22667
22586
  *
22668
22587
  * // the following will retry 10 times until the `ref` value is 10
22669
- * yield* Effect.atomic(Effect.gen(function*() {
22588
+ * yield* Effect.transaction(Effect.gen(function*() {
22670
22589
  * const value = yield* TxRef.get(ref)
22671
22590
  * if (value < 10) {
22672
22591
  * yield* Effect.log(`retry due to value: ${value}`)