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/Stream.ts CHANGED
@@ -12,7 +12,7 @@ import * as Equal from "./Equal.ts"
12
12
  import * as ExecutionPlan from "./ExecutionPlan.ts"
13
13
  import * as Exit from "./Exit.ts"
14
14
  import * as Fiber from "./Fiber.ts"
15
- import * as Filter from "./Filter.ts"
15
+ import type * as Filter from "./Filter.ts"
16
16
  import type { LazyArg } from "./Function.ts"
17
17
  import { constant, constTrue, constVoid, dual, identity } from "./Function.ts"
18
18
  import type { TypeLambda } from "./HKT.ts"
@@ -5766,7 +5766,7 @@ export const filter: {
5766
5766
  * @since 2.0.0
5767
5767
  * @category Filtering
5768
5768
  */
5769
- <A, Result extends Filter.ResultOrBool>(filter: Filter.OrPredicate<NoInfer<A>, Result>): <E, R>(self: Stream<A, E, R>) => Stream<Filter.Pass<A, Result>, E, R>
5769
+ <A>(predicate: Predicate<NoInfer<A>>): <E, R>(self: Stream<A, E, R>) => Stream<A, E, R>
5770
5770
  /**
5771
5771
  * Filters a stream to the elements that satisfy a predicate.
5772
5772
  *
@@ -5812,27 +5812,52 @@ export const filter: {
5812
5812
  * @since 2.0.0
5813
5813
  * @category Filtering
5814
5814
  */
5815
- <A, E, R, Result extends Filter.ResultOrBool>(self: Stream<A, E, R>, filter: Filter.OrPredicate<NoInfer<A>, Result>): Stream<Filter.Pass<A, Result>, E, R>
5815
+ <A, E, R>(self: Stream<A, E, R>, predicate: Predicate<A>): Stream<A, E, R>
5816
5816
  } = dual(
5817
5817
  2,
5818
- <A, E, R, Result extends Filter.ResultOrBool>(
5818
+ <A, E, R>(
5819
5819
  self: Stream<A, E, R>,
5820
- filter: Filter.OrPredicate<NoInfer<A>, Result>
5821
- ): Stream<Filter.Pass<A, Result>, E, R> => fromChannel(Channel.filterArray(toChannel(self), filter))
5820
+ predicate: Predicate<A>
5821
+ ): Stream<A, E, R> => fromChannel(Channel.filterArray(toChannel(self), predicate))
5822
5822
  )
5823
5823
 
5824
5824
  /**
5825
- * Effectfully filters and maps elements in a single pass.
5825
+ * Filters and maps stream elements in one pass using a `Filter`.
5826
+ *
5827
+ * @since 4.0.0
5828
+ * @category Filtering
5829
+ */
5830
+ export const filterMap: {
5831
+ /**
5832
+ * Filters and maps stream elements in one pass using a `Filter`.
5833
+ *
5834
+ * @since 4.0.0
5835
+ * @category Filtering
5836
+ */
5837
+ <A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Stream<A, E, R>) => Stream<B, E, R>
5838
+ /**
5839
+ * Filters and maps stream elements in one pass using a `Filter`.
5840
+ *
5841
+ * @since 4.0.0
5842
+ * @category Filtering
5843
+ */
5844
+ <A, E, R, B, X>(self: Stream<A, E, R>, filter: Filter.Filter<A, B, X>): Stream<B, E, R>
5845
+ } = dual(
5846
+ 2,
5847
+ <A, E, R, B, X>(
5848
+ self: Stream<A, E, R>,
5849
+ filter: Filter.Filter<A, B, X>
5850
+ ): Stream<B, E, R> => fromChannel(Channel.filterMapArray(toChannel(self), filter))
5851
+ )
5852
+
5853
+ /**
5854
+ * Effectfully filters elements in a single pass.
5826
5855
  *
5827
5856
  * @example
5828
5857
  * ```ts
5829
- * import { Console, Effect, Filter, Result, Stream } from "effect"
5830
- *
5831
- * const filter = Filter.makeEffect((n: number) =>
5832
- * Effect.succeed(n > 2 ? Result.succeed(n + 1) : Result.fail(n))
5833
- * )
5858
+ * import { Console, Effect, Stream } from "effect"
5834
5859
  *
5835
- * const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect(filter))
5860
+ * const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect((n) => Effect.succeed(n > 2)))
5836
5861
  *
5837
5862
  * const program = Effect.gen(function*() {
5838
5863
  * const result = yield* Stream.runCollect(stream)
@@ -5840,7 +5865,7 @@ export const filter: {
5840
5865
  * })
5841
5866
  *
5842
5867
  * Effect.runPromise(program)
5843
- * // Output: [ 4, 5 ]
5868
+ * // Output: [ 3, 4 ]
5844
5869
  * ```
5845
5870
  *
5846
5871
  * @since 2.0.0
@@ -5848,17 +5873,13 @@ export const filter: {
5848
5873
  */
5849
5874
  export const filterEffect: {
5850
5875
  /**
5851
- * Effectfully filters and maps elements in a single pass.
5876
+ * Effectfully filters elements in a single pass.
5852
5877
  *
5853
5878
  * @example
5854
5879
  * ```ts
5855
- * import { Console, Effect, Filter, Result, Stream } from "effect"
5856
- *
5857
- * const filter = Filter.makeEffect((n: number) =>
5858
- * Effect.succeed(n > 2 ? Result.succeed(n + 1) : Result.fail(n))
5859
- * )
5880
+ * import { Console, Effect, Stream } from "effect"
5860
5881
  *
5861
- * const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect(filter))
5882
+ * const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect((n) => Effect.succeed(n > 2)))
5862
5883
  *
5863
5884
  * const program = Effect.gen(function*() {
5864
5885
  * const result = yield* Stream.runCollect(stream)
@@ -5866,25 +5887,21 @@ export const filterEffect: {
5866
5887
  * })
5867
5888
  *
5868
5889
  * Effect.runPromise(program)
5869
- * // Output: [ 4, 5 ]
5890
+ * // Output: [ 3, 4 ]
5870
5891
  * ```
5871
5892
  *
5872
5893
  * @since 2.0.0
5873
5894
  * @category Filtering
5874
5895
  */
5875
- <A, B, X, EX, RX>(filter: Filter.FilterEffect<A, B, X, EX, RX>): <E, R>(self: Stream<A, E, R>) => Stream<B, E | EX, R | RX>
5896
+ <A, EX, RX>(predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, EX, RX>): <E, R>(self: Stream<A, E, R>) => Stream<A, E | EX, R | RX>
5876
5897
  /**
5877
- * Effectfully filters and maps elements in a single pass.
5898
+ * Effectfully filters elements in a single pass.
5878
5899
  *
5879
5900
  * @example
5880
5901
  * ```ts
5881
- * import { Console, Effect, Filter, Result, Stream } from "effect"
5882
- *
5883
- * const filter = Filter.makeEffect((n: number) =>
5884
- * Effect.succeed(n > 2 ? Result.succeed(n + 1) : Result.fail(n))
5885
- * )
5902
+ * import { Console, Effect, Stream } from "effect"
5886
5903
  *
5887
- * const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect(filter))
5904
+ * const stream = Stream.make(1, 2, 3, 4).pipe(Stream.filterEffect((n) => Effect.succeed(n > 2)))
5888
5905
  *
5889
5906
  * const program = Effect.gen(function*() {
5890
5907
  * const result = yield* Stream.runCollect(stream)
@@ -5892,35 +5909,65 @@ export const filterEffect: {
5892
5909
  * })
5893
5910
  *
5894
5911
  * Effect.runPromise(program)
5895
- * // Output: [ 4, 5 ]
5912
+ * // Output: [ 3, 4 ]
5896
5913
  * ```
5897
5914
  *
5898
5915
  * @since 2.0.0
5899
5916
  * @category Filtering
5900
5917
  */
5918
+ <A, E, R, EX, RX>(
5919
+ self: Stream<A, E, R>,
5920
+ predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, EX, RX>
5921
+ ): Stream<A, E | EX, R | RX>
5922
+ } = dual(
5923
+ 2,
5924
+ <A, E, R, EX, RX>(
5925
+ self: Stream<A, E, R>,
5926
+ predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, EX, RX>
5927
+ ): Stream<A, E | EX, R | RX> => fromChannel(Channel.filterArrayEffect(toChannel(self), predicate))
5928
+ )
5929
+
5930
+ /**
5931
+ * Effectfully filters and maps elements in a single pass.
5932
+ *
5933
+ * @since 4.0.0
5934
+ * @category Filtering
5935
+ */
5936
+ export const filterMapEffect: {
5937
+ /**
5938
+ * Effectfully filters and maps elements in a single pass.
5939
+ *
5940
+ * @since 4.0.0
5941
+ * @category Filtering
5942
+ */
5943
+ <A, B, X, EX, RX>(filter: Filter.FilterEffect<NoInfer<A>, B, X, EX, RX>): <E, R>(self: Stream<A, E, R>) => Stream<B, E | EX, R | RX>
5944
+ /**
5945
+ * Effectfully filters and maps elements in a single pass.
5946
+ *
5947
+ * @since 4.0.0
5948
+ * @category Filtering
5949
+ */
5901
5950
  <A, E, R, B, X, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<A, B, X, EX, RX>): Stream<B, E | EX, R | RX>
5902
5951
  } = dual(
5903
5952
  2,
5904
5953
  <A, E, R, B, X, EX, RX>(
5905
5954
  self: Stream<A, E, R>,
5906
5955
  filter: Filter.FilterEffect<A, B, X, EX, RX>
5907
- ): Stream<B, E | EX, R | RX> => fromChannel(Channel.filterArrayEffect(toChannel(self), filter))
5956
+ ): Stream<B, E | EX, R | RX> => fromChannel(Channel.filterMapArrayEffect(toChannel(self), filter))
5908
5957
  )
5909
5958
 
5910
5959
  /**
5911
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
5960
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
5912
5961
  *
5913
5962
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
5914
5963
  *
5915
5964
  * @example
5916
5965
  * ```ts
5917
- * import { Console, Effect, Filter, Result, Stream } from "effect"
5966
+ * import { Console, Effect, Result, Stream } from "effect"
5918
5967
  *
5919
5968
  * const program = Effect.gen(function*() {
5920
5969
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
5921
- * Stream.partitionQueue(
5922
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
5923
- * )
5970
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
5924
5971
  * )
5925
5972
  *
5926
5973
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -5940,63 +5987,17 @@ export const filterEffect: {
5940
5987
  */
5941
5988
  export const partitionQueue: {
5942
5989
  /**
5943
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
5990
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
5944
5991
  *
5945
5992
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
5946
5993
  *
5947
5994
  * @example
5948
5995
  * ```ts
5949
- * import { Console, Effect, Filter, Result, Stream } from "effect"
5950
- *
5951
- * const program = Effect.gen(function*() {
5952
- * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
5953
- * Stream.partitionQueue(
5954
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
5955
- * )
5956
- * )
5957
- *
5958
- * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
5959
- * const failValues = yield* Stream.fromQueue(fails).pipe(Stream.runCollect)
5960
- *
5961
- * yield* Console.log(passValues)
5962
- * // Output: [ 2, 4 ]
5963
- * yield* Console.log(failValues)
5964
- * // Output: [ 1, 3 ]
5965
- * })
5966
- *
5967
- * Effect.runPromise(Effect.scoped(program))
5968
- * ```
5969
- *
5970
- * @since 4.0.0
5971
- * @category Filtering
5972
- */
5973
- <A, B extends A>(
5974
- refinement: Refinement<NoInfer<A>, B>,
5975
- options?: {
5976
- readonly capacity?: number | "unbounded" | undefined
5977
- }
5978
- ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<
5979
- [
5980
- passes: Queue.Dequeue<B, E | Cause.Done>,
5981
- fails: Queue.Dequeue<Exclude<A, B>, E | Cause.Done>
5982
- ],
5983
- never,
5984
- R | Scope.Scope
5985
- >
5986
- /**
5987
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
5988
- *
5989
- * Each queue fails with the stream error or `Cause.Done` when the source ends.
5990
- *
5991
- * @example
5992
- * ```ts
5993
- * import { Console, Effect, Filter, Result, Stream } from "effect"
5996
+ * import { Console, Effect, Result, Stream } from "effect"
5994
5997
  *
5995
5998
  * const program = Effect.gen(function*() {
5996
5999
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
5997
- * Stream.partitionQueue(
5998
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
5999
- * )
6000
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6000
6001
  * )
6001
6002
  *
6002
6003
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -6014,78 +6015,31 @@ export const partitionQueue: {
6014
6015
  * @since 4.0.0
6015
6016
  * @category Filtering
6016
6017
  */
6017
- <A, Result extends Filter.ResultOrBool>(
6018
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
6018
+ <A, Pass, Fail>(
6019
+ filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
6019
6020
  options?: {
6020
6021
  readonly capacity?: number | "unbounded" | undefined
6021
6022
  }
6022
6023
  ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<
6023
6024
  [
6024
- passes: Queue.Dequeue<Filter.Pass<A, Result>, E | Cause.Done>,
6025
- fails: Queue.Dequeue<Filter.Fail<A, Result>, E | Cause.Done>
6026
- ],
6027
- never,
6028
- R | Scope.Scope
6029
- >
6030
- /**
6031
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
6032
- *
6033
- * Each queue fails with the stream error or `Cause.Done` when the source ends.
6034
- *
6035
- * @example
6036
- * ```ts
6037
- * import { Console, Effect, Filter, Result, Stream } from "effect"
6038
- *
6039
- * const program = Effect.gen(function*() {
6040
- * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
6041
- * Stream.partitionQueue(
6042
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
6043
- * )
6044
- * )
6045
- *
6046
- * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
6047
- * const failValues = yield* Stream.fromQueue(fails).pipe(Stream.runCollect)
6048
- *
6049
- * yield* Console.log(passValues)
6050
- * // Output: [ 2, 4 ]
6051
- * yield* Console.log(failValues)
6052
- * // Output: [ 1, 3 ]
6053
- * })
6054
- *
6055
- * Effect.runPromise(Effect.scoped(program))
6056
- * ```
6057
- *
6058
- * @since 4.0.0
6059
- * @category Filtering
6060
- */
6061
- <A, E, R, B extends A>(
6062
- self: Stream<A, E, R>,
6063
- refinement: Refinement<A, B>,
6064
- options?: {
6065
- readonly capacity?: number | "unbounded" | undefined
6066
- }
6067
- ): Effect.Effect<
6068
- [
6069
- passes: Queue.Dequeue<B, E | Cause.Done>,
6070
- fails: Queue.Dequeue<Exclude<A, B>, E | Cause.Done>
6025
+ passes: Queue.Dequeue<Pass, E | Cause.Done>,
6026
+ fails: Queue.Dequeue<Fail, E | Cause.Done>
6071
6027
  ],
6072
6028
  never,
6073
6029
  R | Scope.Scope
6074
6030
  >
6075
6031
  /**
6076
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
6032
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
6077
6033
  *
6078
6034
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
6079
6035
  *
6080
6036
  * @example
6081
6037
  * ```ts
6082
- * import { Console, Effect, Filter, Result, Stream } from "effect"
6038
+ * import { Console, Effect, Result, Stream } from "effect"
6083
6039
  *
6084
6040
  * const program = Effect.gen(function*() {
6085
6041
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
6086
- * Stream.partitionQueue(
6087
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
6088
- * )
6042
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6089
6043
  * )
6090
6044
  *
6091
6045
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -6103,16 +6057,16 @@ export const partitionQueue: {
6103
6057
  * @since 4.0.0
6104
6058
  * @category Filtering
6105
6059
  */
6106
- <A, E, R, Result extends Filter.ResultOrBool>(
6060
+ <A, E, R, Pass, Fail>(
6107
6061
  self: Stream<A, E, R>,
6108
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
6062
+ filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
6109
6063
  options?: {
6110
6064
  readonly capacity?: number | "unbounded" | undefined
6111
6065
  }
6112
6066
  ): Effect.Effect<
6113
6067
  [
6114
- passes: Queue.Dequeue<Filter.Pass<A, Result>, E | Cause.Done>,
6115
- fails: Queue.Dequeue<Filter.Fail<A, Result>, E | Cause.Done>
6068
+ passes: Queue.Dequeue<Pass, E | Cause.Done>,
6069
+ fails: Queue.Dequeue<Fail, E | Cause.Done>
6116
6070
  ],
6117
6071
  never,
6118
6072
  R | Scope.Scope
@@ -6120,16 +6074,16 @@ export const partitionQueue: {
6120
6074
  } = dual(
6121
6075
  (args) => isStream(args[0]),
6122
6076
  Effect.fnUntraced(
6123
- function*<A, E, R, Result extends Filter.ResultOrBool>(
6077
+ function*<A, E, R, Pass, Fail>(
6124
6078
  self: Stream<A, E, R>,
6125
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
6079
+ filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
6126
6080
  options?: {
6127
6081
  readonly capacity?: number | "unbounded" | undefined
6128
6082
  }
6129
6083
  ): Effect.fn.Return<
6130
6084
  [
6131
- passes: Queue.Dequeue<any, E | Cause.Done>,
6132
- fails: Queue.Dequeue<any, E | Cause.Done>
6085
+ passes: Queue.Dequeue<Pass, E | Cause.Done>,
6086
+ fails: Queue.Dequeue<Fail, E | Cause.Done>
6133
6087
  ],
6134
6088
  never,
6135
6089
  R | Scope.Scope
@@ -6138,19 +6092,17 @@ export const partitionQueue: {
6138
6092
  const pull = yield* Channel.toPullScoped(self.channel, scope)
6139
6093
  const capacity = options?.capacity === "unbounded" ? undefined : options?.capacity ?? DefaultChunkSize
6140
6094
  const passes = yield* Queue.make</**
6141
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
6095
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
6142
6096
  *
6143
6097
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
6144
6098
  *
6145
6099
  * @example
6146
6100
  * ```ts
6147
- * import { Console, Effect, Filter, Result, Stream } from "effect"
6101
+ * import { Console, Effect, Result, Stream } from "effect"
6148
6102
  *
6149
6103
  * const program = Effect.gen(function*() {
6150
6104
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
6151
- * Stream.partitionQueue(
6152
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
6153
- * )
6105
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6154
6106
  * )
6155
6107
  *
6156
6108
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -6168,20 +6120,18 @@ export const partitionQueue: {
6168
6120
  * @since 4.0.0
6169
6121
  * @category Filtering
6170
6122
  */
6171
- any, /**
6172
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
6123
+ Pass, /**
6124
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
6173
6125
  *
6174
6126
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
6175
6127
  *
6176
6128
  * @example
6177
6129
  * ```ts
6178
- * import { Console, Effect, Filter, Result, Stream } from "effect"
6130
+ * import { Console, Effect, Result, Stream } from "effect"
6179
6131
  *
6180
6132
  * const program = Effect.gen(function*() {
6181
6133
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
6182
- * Stream.partitionQueue(
6183
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
6184
- * )
6134
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6185
6135
  * )
6186
6136
  *
6187
6137
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -6201,19 +6151,17 @@ export const partitionQueue: {
6201
6151
  */
6202
6152
  E | Cause.Done>({ capacity })
6203
6153
  const fails = yield* Queue.make</**
6204
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
6154
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
6205
6155
  *
6206
6156
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
6207
6157
  *
6208
6158
  * @example
6209
6159
  * ```ts
6210
- * import { Console, Effect, Filter, Result, Stream } from "effect"
6160
+ * import { Console, Effect, Result, Stream } from "effect"
6211
6161
  *
6212
6162
  * const program = Effect.gen(function*() {
6213
6163
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
6214
- * Stream.partitionQueue(
6215
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
6216
- * )
6164
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6217
6165
  * )
6218
6166
  *
6219
6167
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -6231,20 +6179,18 @@ export const partitionQueue: {
6231
6179
  * @since 4.0.0
6232
6180
  * @category Filtering
6233
6181
  */
6234
- any, /**
6235
- * Partitions a stream using a Filter and exposes passing and failing values as queues.
6182
+ Fail, /**
6183
+ * Partitions a stream using a `Filter` and exposes passing and failing values as queues.
6236
6184
  *
6237
6185
  * Each queue fails with the stream error or `Cause.Done` when the source ends.
6238
6186
  *
6239
6187
  * @example
6240
6188
  * ```ts
6241
- * import { Console, Effect, Filter, Result, Stream } from "effect"
6189
+ * import { Console, Effect, Result, Stream } from "effect"
6242
6190
  *
6243
6191
  * const program = Effect.gen(function*() {
6244
6192
  * const [passes, fails] = yield* Stream.make(1, 2, 3, 4).pipe(
6245
- * Stream.partitionQueue(
6246
- * Filter.make((n) => (n % 2 === 0 ? Result.succeed(n) : Result.fail(n)))
6247
- * )
6193
+ * Stream.partitionQueue((n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6248
6194
  * )
6249
6195
  *
6250
6196
  * const passValues = yield* Stream.fromQueue(passes).pipe(Stream.runCollect)
@@ -6264,12 +6210,19 @@ export const partitionQueue: {
6264
6210
  */
6265
6211
  E | Cause.Done>({ capacity })
6266
6212
 
6267
- const partitionArr = Arr.partition(filter as any)
6268
-
6269
6213
  yield* Effect.gen(function*() {
6270
6214
  while (true) {
6271
6215
  const chunk = yield* pull
6272
- const [excluded, satisfying] = partitionArr(chunk)
6216
+ const excluded: Array<Fail> = []
6217
+ const satisfying: Array<Pass> = []
6218
+ for (let i = 0; i < chunk.length; i++) {
6219
+ const result = filter(chunk[i] as NoInfer<A>)
6220
+ if (Result.isFailure(result)) {
6221
+ excluded.push(result.failure)
6222
+ } else {
6223
+ satisfying.push(result.success)
6224
+ }
6225
+ }
6273
6226
  let passFiber: Fiber.Fiber<any> | undefined = undefined
6274
6227
  if (satisfying.length > 0) {
6275
6228
  const leftover = Queue.offerAllUnsafe(passes, satisfying)
@@ -6300,147 +6253,112 @@ export const partitionQueue: {
6300
6253
  )
6301
6254
 
6302
6255
  /**
6303
- * Splits a stream using an effectful filter, producing pass and fail streams.
6256
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6304
6257
  *
6305
6258
  * @since 4.0.0
6306
6259
  * @category Filtering
6307
- *
6308
- * @example
6309
- * ```ts
6310
- * import { Console, Effect, Result, Stream } from "effect"
6311
- *
6312
- * const program = Effect.scoped(
6313
- * Effect.gen(function*() {
6314
- * const [evens, odds] = yield* Stream.make(1, 2, 3, 4).pipe(
6315
- * Stream.partitionEffect((n) =>
6316
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6317
- * )
6318
- * )
6319
- * const result = yield* Effect.all({
6320
- * evens: Stream.runCollect(evens),
6321
- * odds: Stream.runCollect(odds)
6322
- * })
6323
- * yield* Console.log(result)
6324
- * })
6325
- * )
6326
- *
6327
- * Effect.runPromise(program)
6328
- * // Output: { evens: [ 2, 4 ], odds: [ 1, 3 ] }
6329
- * ```
6330
6260
  */
6331
6261
  export const partitionEffect: {
6332
6262
  /**
6333
- * Splits a stream using an effectful filter, producing pass and fail streams.
6263
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6334
6264
  *
6335
6265
  * @since 4.0.0
6336
6266
  * @category Filtering
6337
- *
6338
- * @example
6339
- * ```ts
6340
- * import { Console, Effect, Result, Stream } from "effect"
6341
- *
6342
- * const program = Effect.scoped(
6343
- * Effect.gen(function*() {
6344
- * const [evens, odds] = yield* Stream.make(1, 2, 3, 4).pipe(
6345
- * Stream.partitionEffect((n) =>
6346
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6347
- * )
6348
- * )
6349
- * const result = yield* Effect.all({
6350
- * evens: Stream.runCollect(evens),
6351
- * odds: Stream.runCollect(odds)
6352
- * })
6353
- * yield* Console.log(result)
6354
- * })
6355
- * )
6356
- *
6357
- * Effect.runPromise(program)
6358
- * // Output: { evens: [ 2, 4 ], odds: [ 1, 3 ] }
6359
- * ```
6360
6267
  */
6361
- <A, B, X, EX, RX>(
6362
- filter: Filter.FilterEffect<A, B, X, EX, RX>,
6268
+ <A, Pass, Fail, EX, RX>(
6269
+ filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>,
6363
6270
  options?: {
6364
6271
  readonly capacity?: number | "unbounded" | undefined
6365
6272
  readonly concurrency?: number | "unbounded" | undefined
6366
6273
  }
6367
6274
  ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<
6368
6275
  [
6369
- passes: Stream<B, E | EX>,
6370
- fails: Stream<X, E | EX>
6276
+ passes: Stream<Pass, E | EX>,
6277
+ fails: Stream<Fail, E | EX>
6371
6278
  ],
6372
6279
  never,
6373
6280
  R | RX | Scope.Scope
6374
6281
  >
6375
6282
  /**
6376
- * Splits a stream using an effectful filter, producing pass and fail streams.
6283
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6377
6284
  *
6378
6285
  * @since 4.0.0
6379
6286
  * @category Filtering
6380
- *
6381
- * @example
6382
- * ```ts
6383
- * import { Console, Effect, Result, Stream } from "effect"
6384
- *
6385
- * const program = Effect.scoped(
6386
- * Effect.gen(function*() {
6387
- * const [evens, odds] = yield* Stream.make(1, 2, 3, 4).pipe(
6388
- * Stream.partitionEffect((n) =>
6389
- * Effect.succeed(n % 2 === 0 ? Result.succeed(n) : Result.fail(n))
6390
- * )
6391
- * )
6392
- * const result = yield* Effect.all({
6393
- * evens: Stream.runCollect(evens),
6394
- * odds: Stream.runCollect(odds)
6395
- * })
6396
- * yield* Console.log(result)
6397
- * })
6398
- * )
6399
- *
6400
- * Effect.runPromise(program)
6401
- * // Output: { evens: [ 2, 4 ], odds: [ 1, 3 ] }
6402
- * ```
6403
6287
  */
6404
- <A, E, R, B, X, EX, RX>(
6288
+ <A, E, R, Pass, Fail, EX, RX>(
6405
6289
  self: Stream<A, E, R>,
6406
- filter: Filter.FilterEffect<A, B, X, EX, RX>,
6290
+ filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>,
6407
6291
  options?: {
6408
6292
  readonly capacity?: number | "unbounded" | undefined
6409
6293
  readonly concurrency?: number | "unbounded" | undefined
6410
6294
  }
6411
6295
  ): Effect.Effect<
6412
6296
  [
6413
- passes: Stream<B, E | EX>,
6414
- fails: Stream<X, E | EX>
6297
+ passes: Stream<Pass, E | EX>,
6298
+ fails: Stream<Fail, E | EX>
6415
6299
  ],
6416
6300
  never,
6417
6301
  R | RX | Scope.Scope
6418
6302
  >
6419
6303
  } = dual(
6420
6304
  (args) => isStream(args[0]),
6421
- <A, E, R, B, X, EX, RX>(self: Stream<A, E, R>, filter: Filter.FilterEffect<A, B, X, EX, RX>, options?: {
6422
- readonly capacity?: number | "unbounded" | undefined
6423
- readonly concurrency?: number | "unbounded" | undefined
6424
- }): Effect.Effect<
6305
+ <A, E, R, Pass, Fail, EX, RX>(
6306
+ self: Stream<A, E, R>,
6307
+ filter: Filter.FilterEffect<NoInfer<A>, Pass, Fail, EX, RX>,
6308
+ options?: {
6309
+ readonly capacity?: number | "unbounded" | undefined
6310
+ readonly concurrency?: number | "unbounded" | undefined
6311
+ }
6312
+ ): Effect.Effect<
6425
6313
  [
6426
- passes: Stream<B, E | EX>,
6427
- fails: Stream<X, E | EX>
6314
+ passes: Stream<Pass, E | EX>,
6315
+ fails: Stream<Fail, E | EX>
6428
6316
  ],
6429
6317
  never,
6430
6318
  R | RX | Scope.Scope
6431
6319
  > =>
6432
6320
  Effect.map(
6433
- self.pipe(
6434
- mapEffect(filter, options),
6435
- partitionQueue(identity as any, options)
6321
+ partitionQueue</**
6322
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6323
+ *
6324
+ * @since 4.0.0
6325
+ * @category Filtering
6326
+ */
6327
+ Result.Result<Pass, Fail>, /**
6328
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6329
+ *
6330
+ * @since 4.0.0
6331
+ * @category Filtering
6332
+ */
6333
+ E | EX, /**
6334
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6335
+ *
6336
+ * @since 4.0.0
6337
+ * @category Filtering
6338
+ */
6339
+ R | RX, /**
6340
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6341
+ *
6342
+ * @since 4.0.0
6343
+ * @category Filtering
6344
+ */
6345
+ Pass, /**
6346
+ * Splits a stream using an effectful `Filter`, producing pass and fail streams.
6347
+ *
6348
+ * @since 4.0.0
6349
+ * @category Filtering
6350
+ */
6351
+ Fail>(
6352
+ mapEffect(self, (a) => filter(a as NoInfer<A>), options),
6353
+ (result) => result,
6354
+ options
6436
6355
  ),
6437
- ([passes, fails]) => [fromQueue(passes), fromQueue(fails)]
6438
- ) as any
6356
+ ([passes, fails]) => [fromQueue(passes), fromQueue(fails)] as const
6357
+ )
6439
6358
  )
6440
6359
 
6441
6360
  /**
6442
- * Splits a stream into excluded and satisfying substreams using a predicate,
6443
- * refinement, or Filter.
6361
+ * Splits a stream into excluded and satisfying substreams using a `Filter`.
6444
6362
  *
6445
6363
  * The faster stream may advance up to `bufferSize` elements ahead of the slower
6446
6364
  * one.
@@ -6450,12 +6368,12 @@ export const partitionEffect: {
6450
6368
  *
6451
6369
  * @example
6452
6370
  * ```ts
6453
- * import { Console, Effect, Stream } from "effect"
6371
+ * import { Console, Effect, Result, Stream } from "effect"
6454
6372
  *
6455
6373
  * const program = Effect.gen(function*() {
6456
6374
  * const [excluded, satisfying] = yield* Stream.partition(
6457
6375
  * Stream.make(1, 2, 3, 4),
6458
- * (n) => n % 2 === 0
6376
+ * (n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n)
6459
6377
  * )
6460
6378
  * const left = yield* Stream.runCollect(excluded)
6461
6379
  * const right = yield* Stream.runCollect(satisfying)
@@ -6468,46 +6386,7 @@ export const partitionEffect: {
6468
6386
  */
6469
6387
  export const partition: {
6470
6388
  /**
6471
- * Splits a stream into excluded and satisfying substreams using a predicate,
6472
- * refinement, or Filter.
6473
- *
6474
- * The faster stream may advance up to `bufferSize` elements ahead of the slower
6475
- * one.
6476
- *
6477
- * @since 4.0.0
6478
- * @category Filtering
6479
- *
6480
- * @example
6481
- * ```ts
6482
- * import { Console, Effect, Stream } from "effect"
6483
- *
6484
- * const program = Effect.gen(function*() {
6485
- * const [excluded, satisfying] = yield* Stream.partition(
6486
- * Stream.make(1, 2, 3, 4),
6487
- * (n) => n % 2 === 0
6488
- * )
6489
- * const left = yield* Stream.runCollect(excluded)
6490
- * const right = yield* Stream.runCollect(satisfying)
6491
- * yield* Console.log(left)
6492
- * // Output: [ 1, 3 ]
6493
- * yield* Console.log(right)
6494
- * // Output: [ 2, 4 ]
6495
- * })
6496
- * ```
6497
- */
6498
- <C extends A, B extends A, A = C>(
6499
- refinement: Refinement<NoInfer<A>, B>,
6500
- options?: { readonly bufferSize?: number | undefined }
6501
- ): <E, R>(
6502
- self: Stream<C, E, R>
6503
- ) => Effect.Effect<
6504
- [excluded: Stream<Exclude<C, B>, E>, satisfying: Stream<B, E>],
6505
- never,
6506
- R | Scope.Scope
6507
- >
6508
- /**
6509
- * Splits a stream into excluded and satisfying substreams using a predicate,
6510
- * refinement, or Filter.
6389
+ * Splits a stream into excluded and satisfying substreams using a `Filter`.
6511
6390
  *
6512
6391
  * The faster stream may advance up to `bufferSize` elements ahead of the slower
6513
6392
  * one.
@@ -6517,12 +6396,12 @@ export const partition: {
6517
6396
  *
6518
6397
  * @example
6519
6398
  * ```ts
6520
- * import { Console, Effect, Stream } from "effect"
6399
+ * import { Console, Effect, Result, Stream } from "effect"
6521
6400
  *
6522
6401
  * const program = Effect.gen(function*() {
6523
6402
  * const [excluded, satisfying] = yield* Stream.partition(
6524
6403
  * Stream.make(1, 2, 3, 4),
6525
- * (n) => n % 2 === 0
6404
+ * (n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n)
6526
6405
  * )
6527
6406
  * const left = yield* Stream.runCollect(excluded)
6528
6407
  * const right = yield* Stream.runCollect(satisfying)
@@ -6533,56 +6412,18 @@ export const partition: {
6533
6412
  * })
6534
6413
  * ```
6535
6414
  */
6536
- <A, Result extends Filter.ResultOrBool>(
6537
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
6415
+ <A, Pass, Fail>(
6416
+ filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
6538
6417
  options?: { readonly bufferSize?: number | undefined }
6539
6418
  ): <E, R>(
6540
6419
  self: Stream<A, E, R>
6541
6420
  ) => Effect.Effect<
6542
- [excluded: Stream<Filter.Fail<A, Result>, E>, satisfying: Stream<Filter.Pass<A, Result>, E>],
6543
- never,
6544
- R | Scope.Scope
6545
- >
6546
- /**
6547
- * Splits a stream into excluded and satisfying substreams using a predicate,
6548
- * refinement, or Filter.
6549
- *
6550
- * The faster stream may advance up to `bufferSize` elements ahead of the slower
6551
- * one.
6552
- *
6553
- * @since 4.0.0
6554
- * @category Filtering
6555
- *
6556
- * @example
6557
- * ```ts
6558
- * import { Console, Effect, Stream } from "effect"
6559
- *
6560
- * const program = Effect.gen(function*() {
6561
- * const [excluded, satisfying] = yield* Stream.partition(
6562
- * Stream.make(1, 2, 3, 4),
6563
- * (n) => n % 2 === 0
6564
- * )
6565
- * const left = yield* Stream.runCollect(excluded)
6566
- * const right = yield* Stream.runCollect(satisfying)
6567
- * yield* Console.log(left)
6568
- * // Output: [ 1, 3 ]
6569
- * yield* Console.log(right)
6570
- * // Output: [ 2, 4 ]
6571
- * })
6572
- * ```
6573
- */
6574
- <C extends A, E, R, B extends A, A = C>(
6575
- self: Stream<C, E, R>,
6576
- refinement: Refinement<A, B>,
6577
- options?: { readonly bufferSize?: number | undefined }
6578
- ): Effect.Effect<
6579
- [excluded: Stream<Exclude<C, B>, E>, satisfying: Stream<B, E>],
6421
+ [excluded: Stream<Fail, E>, satisfying: Stream<Pass, E>],
6580
6422
  never,
6581
6423
  R | Scope.Scope
6582
6424
  >
6583
6425
  /**
6584
- * Splits a stream into excluded and satisfying substreams using a predicate,
6585
- * refinement, or Filter.
6426
+ * Splits a stream into excluded and satisfying substreams using a `Filter`.
6586
6427
  *
6587
6428
  * The faster stream may advance up to `bufferSize` elements ahead of the slower
6588
6429
  * one.
@@ -6592,12 +6433,12 @@ export const partition: {
6592
6433
  *
6593
6434
  * @example
6594
6435
  * ```ts
6595
- * import { Console, Effect, Stream } from "effect"
6436
+ * import { Console, Effect, Result, Stream } from "effect"
6596
6437
  *
6597
6438
  * const program = Effect.gen(function*() {
6598
6439
  * const [excluded, satisfying] = yield* Stream.partition(
6599
6440
  * Stream.make(1, 2, 3, 4),
6600
- * (n) => n % 2 === 0
6441
+ * (n) => n % 2 === 0 ? Result.succeed(n) : Result.fail(n)
6601
6442
  * )
6602
6443
  * const left = yield* Stream.runCollect(excluded)
6603
6444
  * const right = yield* Stream.runCollect(satisfying)
@@ -6608,28 +6449,28 @@ export const partition: {
6608
6449
  * })
6609
6450
  * ```
6610
6451
  */
6611
- <A, E, R, Result extends Filter.ResultOrBool>(
6452
+ <A, E, R, Pass, Fail>(
6612
6453
  self: Stream<A, E, R>,
6613
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
6454
+ filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
6614
6455
  options?: { readonly bufferSize?: number | undefined }
6615
6456
  ): Effect.Effect<
6616
- [excluded: Stream<Filter.Fail<A, Result>, E>, satisfying: Stream<Filter.Pass<A, Result>, E>],
6457
+ [excluded: Stream<Fail, E>, satisfying: Stream<Pass, E>],
6617
6458
  never,
6618
6459
  R | Scope.Scope
6619
6460
  >
6620
6461
  } = dual(
6621
6462
  (args) => isStream(args[0]),
6622
- <A, E, R, Result extends Filter.ResultOrBool>(
6463
+ <A, E, R, Pass, Fail>(
6623
6464
  self: Stream<A, E, R>,
6624
- filter: Filter.OrPredicate<NoInfer<A>, Result>,
6465
+ filter: Filter.Filter<NoInfer<A>, Pass, Fail>,
6625
6466
  options?: { readonly bufferSize?: number | undefined }
6626
6467
  ): Effect.Effect<
6627
- [excluded: Stream<Filter.Fail<A, Result>, E>, satisfying: Stream<Filter.Pass<A, Result>, E>],
6468
+ [excluded: Stream<Fail, E>, satisfying: Stream<Pass, E>],
6628
6469
  never,
6629
6470
  R | Scope.Scope
6630
6471
  > =>
6631
6472
  Effect.map(
6632
- partitionQueue(filter, { capacity: options?.bufferSize ?? 16 })(self),
6473
+ partitionQueue(self, filter, { capacity: options?.bufferSize ?? 16 }),
6633
6474
  ([passes, fails]) => [fromQueue(fails), fromQueue(passes)] as const
6634
6475
  )
6635
6476
  )
@@ -7411,7 +7252,7 @@ export const tapError: {
7411
7252
  ))
7412
7253
 
7413
7254
  /**
7414
- * Recovers from errors that match a filter by switching to a recovery stream.
7255
+ * Recovers from errors that match a predicate by switching to a recovery stream.
7415
7256
  *
7416
7257
  * When a failure matches the filter, the stream switches to the recovery
7417
7258
  * stream. Non-matching failures propagate downstream, so the error type is
@@ -7425,12 +7266,12 @@ export const tapError: {
7425
7266
  *
7426
7267
  * @example
7427
7268
  * ```ts
7428
- * import { Console, Effect, Filter, Stream } from "effect"
7269
+ * import { Console, Effect, Stream } from "effect"
7429
7270
  *
7430
7271
  * const stream = Stream.make(1, 2).pipe(
7431
7272
  * Stream.concat(Stream.fail(42)),
7432
7273
  * Stream.catchIf(
7433
- * Filter.fromPredicate((error): error is 42 => error === 42),
7274
+ * (error): error is 42 => error === 42,
7434
7275
  * () => Stream.make(999)
7435
7276
  * )
7436
7277
  * )
@@ -7449,7 +7290,7 @@ export const tapError: {
7449
7290
  */
7450
7291
  export const catchIf: {
7451
7292
  /**
7452
- * Recovers from errors that match a filter by switching to a recovery stream.
7293
+ * Recovers from errors that match a predicate by switching to a recovery stream.
7453
7294
  *
7454
7295
  * When a failure matches the filter, the stream switches to the recovery
7455
7296
  * stream. Non-matching failures propagate downstream, so the error type is
@@ -7463,12 +7304,12 @@ export const catchIf: {
7463
7304
  *
7464
7305
  * @example
7465
7306
  * ```ts
7466
- * import { Console, Effect, Filter, Stream } from "effect"
7307
+ * import { Console, Effect, Stream } from "effect"
7467
7308
  *
7468
7309
  * const stream = Stream.make(1, 2).pipe(
7469
7310
  * Stream.concat(Stream.fail(42)),
7470
7311
  * Stream.catchIf(
7471
- * Filter.fromPredicate((error): error is 42 => error === 42),
7312
+ * (error): error is 42 => error === 42,
7472
7313
  * () => Stream.make(999)
7473
7314
  * )
7474
7315
  * )
@@ -7491,7 +7332,7 @@ export const catchIf: {
7491
7332
  orElse?: ((e: Exclude<E, EB>) => Stream<A3, E3, R3>) | undefined
7492
7333
  ): <A, R>(self: Stream<A, E, R>) => Stream<A2 | A | A3, E2 | E3, R2 | R | R3>
7493
7334
  /**
7494
- * Recovers from errors that match a filter by switching to a recovery stream.
7335
+ * Recovers from errors that match a predicate by switching to a recovery stream.
7495
7336
  *
7496
7337
  * When a failure matches the filter, the stream switches to the recovery
7497
7338
  * stream. Non-matching failures propagate downstream, so the error type is
@@ -7505,12 +7346,12 @@ export const catchIf: {
7505
7346
  *
7506
7347
  * @example
7507
7348
  * ```ts
7508
- * import { Console, Effect, Filter, Stream } from "effect"
7349
+ * import { Console, Effect, Stream } from "effect"
7509
7350
  *
7510
7351
  * const stream = Stream.make(1, 2).pipe(
7511
7352
  * Stream.concat(Stream.fail(42)),
7512
7353
  * Stream.catchIf(
7513
- * Filter.fromPredicate((error): error is 42 => error === 42),
7354
+ * (error): error is 42 => error === 42,
7514
7355
  * () => Stream.make(999)
7515
7356
  * )
7516
7357
  * )
@@ -7527,13 +7368,13 @@ export const catchIf: {
7527
7368
  * @since 4.0.0
7528
7369
  * @category Error Handling
7529
7370
  */
7530
- <E, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(
7531
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
7532
- f: (failure: Filter.Pass<E, Result>) => Stream<A2, E2, R2>,
7533
- orElse?: ((failure: Filter.Fail<E, Result>) => Stream<A3, E3, R3>) | undefined
7534
- ): <A, R>(self: Stream<A, E, R>) => Stream<A | A2 | A3, E2 | E3, R | R2 | R3>
7371
+ <E, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
7372
+ predicate: Predicate<NoInfer<E>>,
7373
+ f: (e: NoInfer<E>) => Stream<A2, E2, R2>,
7374
+ orElse?: ((e: NoInfer<E>) => Stream<A3, E3, R3>) | undefined
7375
+ ): <A, R>(self: Stream<A, E, R>) => Stream<A2 | A | A3, E2 | E3, R2 | R | R3>
7535
7376
  /**
7536
- * Recovers from errors that match a filter by switching to a recovery stream.
7377
+ * Recovers from errors that match a predicate by switching to a recovery stream.
7537
7378
  *
7538
7379
  * When a failure matches the filter, the stream switches to the recovery
7539
7380
  * stream. Non-matching failures propagate downstream, so the error type is
@@ -7547,12 +7388,12 @@ export const catchIf: {
7547
7388
  *
7548
7389
  * @example
7549
7390
  * ```ts
7550
- * import { Console, Effect, Filter, Stream } from "effect"
7391
+ * import { Console, Effect, Stream } from "effect"
7551
7392
  *
7552
7393
  * const stream = Stream.make(1, 2).pipe(
7553
7394
  * Stream.concat(Stream.fail(42)),
7554
7395
  * Stream.catchIf(
7555
- * Filter.fromPredicate((error): error is 42 => error === 42),
7396
+ * (error): error is 42 => error === 42,
7556
7397
  * () => Stream.make(999)
7557
7398
  * )
7558
7399
  * )
@@ -7576,7 +7417,7 @@ export const catchIf: {
7576
7417
  orElse?: ((e: Exclude<E, EB>) => Stream<A3, E3, R3>) | undefined
7577
7418
  ): Stream<A | A2 | A3, E2 | E3, R | R2 | R3>
7578
7419
  /**
7579
- * Recovers from errors that match a filter by switching to a recovery stream.
7420
+ * Recovers from errors that match a predicate by switching to a recovery stream.
7580
7421
  *
7581
7422
  * When a failure matches the filter, the stream switches to the recovery
7582
7423
  * stream. Non-matching failures propagate downstream, so the error type is
@@ -7590,12 +7431,12 @@ export const catchIf: {
7590
7431
  *
7591
7432
  * @example
7592
7433
  * ```ts
7593
- * import { Console, Effect, Filter, Stream } from "effect"
7434
+ * import { Console, Effect, Stream } from "effect"
7594
7435
  *
7595
7436
  * const stream = Stream.make(1, 2).pipe(
7596
7437
  * Stream.concat(Stream.fail(42)),
7597
7438
  * Stream.catchIf(
7598
- * Filter.fromPredicate((error): error is 42 => error === 42),
7439
+ * (error): error is 42 => error === 42,
7599
7440
  * () => Stream.make(999)
7600
7441
  * )
7601
7442
  * )
@@ -7612,37 +7453,96 @@ export const catchIf: {
7612
7453
  * @since 4.0.0
7613
7454
  * @category Error Handling
7614
7455
  */
7615
- <A, E, R, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(
7456
+ <A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
7616
7457
  self: Stream<A, E, R>,
7617
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
7618
- f: (failure: Filter.Pass<E, Result>) => Stream<A2, E2, R2>,
7619
- orElse?: ((failure: Filter.Fail<E, Result>) => Stream<A3, E3, R3>) | undefined
7458
+ predicate: Predicate<E>,
7459
+ f: (e: E) => Stream<A2, E2, R2>,
7460
+ orElse?: ((e: E) => Stream<A3, E3, R3>) | undefined
7620
7461
  ): Stream<A | A2 | A3, E2 | E3, R | R2 | R3>
7621
7462
  } = dual((args) => isStream(args[0]), <
7622
7463
  A,
7623
7464
  E,
7624
7465
  R,
7625
- Result extends Filter.ResultOrBool,
7626
7466
  A2,
7627
7467
  E2,
7628
7468
  R2,
7629
7469
  A3 = never,
7630
- E3 = Filter.Fail<E, Result>,
7470
+ E3 = E,
7631
7471
  R3 = never
7632
7472
  >(
7633
7473
  self: Stream<A, E, R>,
7634
- filter: Filter.OrPredicate<NoInfer<E>, Result>,
7635
- f: (failure: Filter.Pass<E, Result>) => Stream<A2, E2, R2>,
7636
- orElse?: ((failure: Filter.Fail<E, Result>) => Stream<A3, E3, R3>) | undefined
7474
+ predicate: Predicate<E>,
7475
+ f: (failure: E) => Stream<A2, E2, R2>,
7476
+ orElse?: ((failure: E) => Stream<A3, E3, R3>) | undefined
7637
7477
  ): Stream<A | A2 | A3, E2 | E3, R | R2 | R3> =>
7638
7478
  fromChannel(
7639
7479
  Channel.catchIf(
7640
7480
  toChannel(self),
7641
- filter as any,
7642
- (e: any) => f(e).channel,
7643
- orElse && ((e: any) => orElse(e).channel)
7481
+ predicate,
7482
+ (e) => f(e).channel,
7483
+ orElse && ((e) => orElse(e).channel)
7484
+ )
7485
+ ))
7486
+
7487
+ /**
7488
+ * Recovers from errors that match a `Filter` by switching to a recovery
7489
+ * stream.
7490
+ *
7491
+ * @since 4.0.0
7492
+ * @category Error Handling
7493
+ */
7494
+ export const catchFilter: {
7495
+ /**
7496
+ * Recovers from errors that match a `Filter` by switching to a recovery
7497
+ * stream.
7498
+ *
7499
+ * @since 4.0.0
7500
+ * @category Error Handling
7501
+ */
7502
+ <E, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
7503
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
7504
+ f: (failure: EB) => Stream<A2, E2, R2>,
7505
+ orElse?: ((failure: X) => Stream<A3, E3, R3>) | undefined
7506
+ ): <A, R>(self: Stream<A, E, R>) => Stream<A | A2 | A3, E2 | E3, R | R2 | R3>
7507
+ /**
7508
+ * Recovers from errors that match a `Filter` by switching to a recovery
7509
+ * stream.
7510
+ *
7511
+ * @since 4.0.0
7512
+ * @category Error Handling
7513
+ */
7514
+ <A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
7515
+ self: Stream<A, E, R>,
7516
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
7517
+ f: (failure: EB) => Stream<A2, E2, R2>,
7518
+ orElse?: ((failure: X) => Stream<A3, E3, R3>) | undefined
7519
+ ): Stream<A | A2 | A3, E2 | E3, R | R2 | R3>
7520
+ } = dual((args) => isStream(args[0]), <
7521
+ A,
7522
+ E,
7523
+ R,
7524
+ EB,
7525
+ A2,
7526
+ E2,
7527
+ R2,
7528
+ X,
7529
+ A3 = never,
7530
+ E3 = X,
7531
+ R3 = never
7532
+ >(
7533
+ self: Stream<A, E, R>,
7534
+ filter: Filter.Filter<NoInfer<E>, EB, X>,
7535
+ f: (failure: EB) => Stream<A2, E2, R2>,
7536
+ orElse?: ((failure: X) => Stream<A3, E3, R3>) | undefined
7537
+ ): Stream<A | A2 | A3, E2 | E3, R | R2 | R3> =>
7538
+ fromChannel(
7539
+ Channel.catchFilter(
7540
+ toChannel(self),
7541
+ filter,
7542
+ (e) => f(e).channel,
7543
+ orElse && ((e) => orElse(e).channel)
7644
7544
  )
7645
- ) as any)
7545
+ ))
7646
7546
 
7647
7547
  /**
7648
7548
  * Recovers from failures whose `_tag` matches the provided value by switching to
@@ -7981,7 +7881,7 @@ export const catchTags: {
7981
7881
  >
7982
7882
  } = dual((args) => isStream(args[0]), (self, cases, orElse) => {
7983
7883
  let keys: Array<string>
7984
- return catchIf(
7884
+ return catchFilter(
7985
7885
  self,
7986
7886
  (e: any) => {
7987
7887
  keys ??= Object.keys(cases)
@@ -8572,12 +8472,12 @@ export const catchCauseIf: {
8572
8472
  * @since 4.0.0
8573
8473
  * @category Error Handling
8574
8474
  */
8575
- <E, Result extends Filter.ResultOrBool<Cause.Cause<any>>, A2, E2, R2>(
8576
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
8577
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8475
+ <E, A2, E2, R2>(
8476
+ predicate: Predicate<Cause.Cause<E>>,
8477
+ f: (cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8578
8478
  ): <A, R>(
8579
8479
  self: Stream<A, E, R>
8580
- ) => Stream<A | A2, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R2 | R>
8480
+ ) => Stream<A | A2, E | E2, R2 | R>
8581
8481
  /**
8582
8482
  * Recovers from stream failures by filtering the `Cause` and switching to a recovery stream.
8583
8483
  * Non-matching causes are re-emitted as failures.
@@ -8611,19 +8511,68 @@ export const catchCauseIf: {
8611
8511
  * @since 4.0.0
8612
8512
  * @category Error Handling
8613
8513
  */
8614
- <A, E, R, A2, E2, R2, Result extends Filter.ResultOrBool<Cause.Cause<any>>>(
8514
+ <A, E, R, A2, E2, R2>(
8615
8515
  self: Stream<A, E, R>,
8616
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
8617
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8618
- ): Stream<A | A2, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2>
8619
- } = dual(3, <A, E, R, A2, E2, R2, Result extends Filter.ResultOrBool<Cause.Cause<any>>>(
8516
+ predicate: Predicate<Cause.Cause<E>>,
8517
+ f: (cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8518
+ ): Stream<A | A2, E | E2, R | R2>
8519
+ } = dual(3, <A, E, R, A2, E2, R2>(
8620
8520
  self: Stream<A, E, R>,
8621
- filter: Filter.OrPredicate<Cause.Cause<E>, Result>,
8622
- f: (failure: Filter.Pass<Cause.Cause<E>, Result>, cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8623
- ): Stream<A | A2, Cause.Cause.Error<Filter.Fail<Cause.Cause<E>, Result>> | E2, R | R2> =>
8521
+ predicate: Predicate<Cause.Cause<E>>,
8522
+ f: (cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8523
+ ): Stream<A | A2, E | E2, R | R2> =>
8624
8524
  fromChannel(
8625
- Channel.catchCauseIf(self.channel, filter as any, (failure: any, cause: any) =>
8626
- (f as any)(failure, cause).channel) as any
8525
+ Channel.catchCauseIf(
8526
+ self.channel,
8527
+ predicate,
8528
+ (cause) => f(cause).channel
8529
+ )
8530
+ ))
8531
+
8532
+ /**
8533
+ * Recovers from stream failures by filtering the `Cause` and switching to a
8534
+ * recovery stream.
8535
+ *
8536
+ * @since 4.0.0
8537
+ * @category Error Handling
8538
+ */
8539
+ export const catchCauseFilter: {
8540
+ /**
8541
+ * Recovers from stream failures by filtering the `Cause` and switching to a
8542
+ * recovery stream.
8543
+ *
8544
+ * @since 4.0.0
8545
+ * @category Error Handling
8546
+ */
8547
+ <E, EB, A2, E2, R2, X extends Cause.Cause<any>>(
8548
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
8549
+ f: (failure: EB, cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8550
+ ): <A, R>(
8551
+ self: Stream<A, E, R>
8552
+ ) => Stream<A | A2, Cause.Cause.Error<X> | E2, R2 | R>
8553
+ /**
8554
+ * Recovers from stream failures by filtering the `Cause` and switching to a
8555
+ * recovery stream.
8556
+ *
8557
+ * @since 4.0.0
8558
+ * @category Error Handling
8559
+ */
8560
+ <A, E, R, EB, A2, E2, R2, X extends Cause.Cause<any>>(
8561
+ self: Stream<A, E, R>,
8562
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
8563
+ f: (failure: EB, cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8564
+ ): Stream<A | A2, Cause.Cause.Error<X> | E2, R | R2>
8565
+ } = dual(3, <A, E, R, EB, A2, E2, R2, X extends Cause.Cause<any>>(
8566
+ self: Stream<A, E, R>,
8567
+ filter: Filter.Filter<Cause.Cause<E>, EB, X>,
8568
+ f: (failure: EB, cause: Cause.Cause<E>) => Stream<A2, E2, R2>
8569
+ ): Stream<A | A2, Cause.Cause.Error<X> | E2, R | R2> =>
8570
+ fromChannel(
8571
+ Channel.catchCauseFilter(
8572
+ self.channel,
8573
+ filter,
8574
+ (failure, cause) => f(failure, cause).channel
8575
+ )
8627
8576
  ))
8628
8577
 
8629
8578
  /**
@@ -9764,7 +9713,7 @@ export const takeWhile: {
9764
9713
  * @since 2.0.0
9765
9714
  * @category Filtering
9766
9715
  */
9767
- <A, B, X>(f: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Stream<A, E, R>) => Stream<B, E, R>
9716
+ <A, E, R, B extends A>(self: Stream<A, E, R>, refinement: (a: NoInfer<A>, n: number) => a is B): Stream<B, E, R>
9768
9717
  /**
9769
9718
  * Takes the longest initial prefix of elements that satisfy the predicate.
9770
9719
  *
@@ -9788,71 +9737,71 @@ export const takeWhile: {
9788
9737
  * @since 2.0.0
9789
9738
  * @category Filtering
9790
9739
  */
9791
- <A, E, R, B extends A>(self: Stream<A, E, R>, refinement: (a: NoInfer<A>, n: number) => a is B): Stream<B, E, R>
9740
+ <A, E, R>(self: Stream<A, E, R>, predicate: (a: NoInfer<A>, n: number) => boolean): Stream<A, E, R>
9741
+ } = dual(
9742
+ 2,
9743
+ <A, E, R>(
9744
+ self: Stream<A, E, R>,
9745
+ predicate: (a: A, n: number) => boolean
9746
+ ): Stream<A, E, R> =>
9747
+ transformPull(self, (pull, _scope) =>
9748
+ Effect.sync(() => {
9749
+ let i = 0
9750
+ let done = false
9751
+ const pump: Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E, void, R> = Effect.flatMap(
9752
+ Effect.suspend(() => done ? Cause.done() : pull),
9753
+ (chunk) => {
9754
+ const out: Array<A> = []
9755
+ for (let j = 0; j < chunk.length; j++) {
9756
+ if (!predicate(chunk[j], i++)) {
9757
+ done = true
9758
+ break
9759
+ }
9760
+ out.push(chunk[j])
9761
+ }
9762
+ return Arr.isReadonlyArrayNonEmpty(out) ? Effect.succeed(out) : done ? Cause.done() : pump
9763
+ }
9764
+ )
9765
+ return pump
9766
+ }))
9767
+ )
9768
+
9769
+ /**
9770
+ * Takes the longest initial prefix of elements that satisfy the filter.
9771
+ *
9772
+ * @since 4.0.0
9773
+ * @category Filtering
9774
+ */
9775
+ export const takeWhileFilter: {
9792
9776
  /**
9793
- * Takes the longest initial prefix of elements that satisfy the predicate.
9794
- *
9795
- * @example
9796
- * ```ts
9797
- * import { Console, Effect, Stream } from "effect"
9798
- *
9799
- * const stream = Stream.range(1, 5).pipe(
9800
- * Stream.takeWhile((n) => n % 3 !== 0)
9801
- * )
9802
- *
9803
- * const program = Effect.gen(function*() {
9804
- * const result = yield* Stream.runCollect(stream)
9805
- * yield* Console.log(result)
9806
- * })
9777
+ * Takes the longest initial prefix of elements that satisfy the filter.
9807
9778
  *
9808
- * Effect.runPromise(program)
9809
- * // Output: [ 1, 2 ]
9810
- * ```
9811
- *
9812
- * @since 2.0.0
9779
+ * @since 4.0.0
9813
9780
  * @category Filtering
9814
9781
  */
9815
- <A, E, R>(self: Stream<A, E, R>, predicate: (a: NoInfer<A>, n: number) => boolean): Stream<A, E, R>
9782
+ <A, B, X>(f: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Stream<A, E, R>) => Stream<B, E, R>
9816
9783
  /**
9817
- * Takes the longest initial prefix of elements that satisfy the predicate.
9818
- *
9819
- * @example
9820
- * ```ts
9821
- * import { Console, Effect, Stream } from "effect"
9822
- *
9823
- * const stream = Stream.range(1, 5).pipe(
9824
- * Stream.takeWhile((n) => n % 3 !== 0)
9825
- * )
9784
+ * Takes the longest initial prefix of elements that satisfy the filter.
9826
9785
  *
9827
- * const program = Effect.gen(function*() {
9828
- * const result = yield* Stream.runCollect(stream)
9829
- * yield* Console.log(result)
9830
- * })
9831
- *
9832
- * Effect.runPromise(program)
9833
- * // Output: [ 1, 2 ]
9834
- * ```
9835
- *
9836
- * @since 2.0.0
9786
+ * @since 4.0.0
9837
9787
  * @category Filtering
9838
9788
  */
9839
9789
  <A, E, R, B, X>(self: Stream<A, E, R>, f: Filter.Filter<NoInfer<A>, B, X>): Stream<B, E, R>
9840
9790
  } = dual(
9841
9791
  2,
9842
- <A, E, R>(
9792
+ <A, E, R, B, X>(
9843
9793
  self: Stream<A, E, R>,
9844
- f: Filter.Filter<A, any, any> | ((a: A, n: number) => boolean)
9845
- ): Stream<any, E, R> =>
9794
+ filter: Filter.Filter<NoInfer<A>, B, X>
9795
+ ): Stream<B, E, R> =>
9846
9796
  transformPull(self, (pull, _scope) =>
9847
9797
  Effect.sync(() => {
9848
- let i = 0
9849
9798
  let done = false
9850
- const pump: Pull.Pull<Arr.NonEmptyReadonlyArray<any>, E, void, R> = Effect.flatMap(
9799
+ const pump: Pull.Pull<Arr.NonEmptyReadonlyArray<B>, E, void, R> = Effect.flatMap(
9851
9800
  Effect.suspend(() => done ? Cause.done() : pull),
9852
9801
  (chunk) => {
9853
- const out: Array<any> = []
9802
+ const out: Array<B> = []
9854
9803
  for (let j = 0; j < chunk.length; j++) {
9855
- const result = Filter.apply(f as any, chunk[j], i++)
9804
+ const result = filter(chunk[j])
9856
9805
  if (Result.isFailure(result)) {
9857
9806
  done = true
9858
9807
  break
@@ -10247,29 +10196,6 @@ export const dropWhile: {
10247
10196
  * @category Filtering
10248
10197
  */
10249
10198
  <A>(predicate: (a: NoInfer<A>, index: number) => boolean): <E, R>(self: Stream<A, E, R>) => Stream<A, E, R>
10250
- /**
10251
- * Drops elements from the stream while the specified predicate evaluates to `true`.
10252
- *
10253
- * @example
10254
- * ```ts
10255
- * import { Console, Effect, Stream } from "effect"
10256
- *
10257
- * const program = Effect.gen(function*() {
10258
- * const values = yield* Stream.make(1, 2, 3, 4, 5).pipe(
10259
- * Stream.dropWhile((n) => n < 3),
10260
- * Stream.runCollect
10261
- * )
10262
- * yield* Console.log(values)
10263
- * })
10264
- *
10265
- * Effect.runPromise(program)
10266
- * // Output: [ 3, 4, 5 ]
10267
- * ```
10268
- *
10269
- * @since 2.0.0
10270
- * @category Filtering
10271
- */
10272
- <A, B, X>(f: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Stream<A, E, R>) => Stream<A, E, R>
10273
10199
  /**
10274
10200
  * Drops elements from the stream while the specified predicate evaluates to `true`.
10275
10201
  *
@@ -10296,39 +10222,53 @@ export const dropWhile: {
10296
10222
  self: Stream<A, E, R>,
10297
10223
  predicate: (a: NoInfer<A>, index: number) => boolean
10298
10224
  ): Stream<A, E, R>
10225
+ } = dual(2, <A, E, R>(
10226
+ self: Stream<A, E, R>,
10227
+ predicate: (a: A, index: number) => boolean
10228
+ ): Stream<A, E, R> =>
10229
+ transformPull(self, (pull, _scope) =>
10230
+ Effect.sync(() => {
10231
+ let dropping = true
10232
+ let index = 0
10233
+ const filtered: Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E> = Effect.flatMap(pull, (arr) => {
10234
+ const found = arr.findIndex((a) => !predicate(a, index++))
10235
+ if (found === -1) return filtered
10236
+ dropping = false
10237
+ return Effect.succeed(arr.slice(found) as Arr.NonEmptyArray<A>)
10238
+ })
10239
+ return Effect.suspend(() => dropping ? filtered : pull)
10240
+ })))
10241
+
10242
+ /**
10243
+ * Drops elements while the filter succeeds.
10244
+ *
10245
+ * @since 4.0.0
10246
+ * @category Filtering
10247
+ */
10248
+ export const dropWhileFilter: {
10299
10249
  /**
10300
- * Drops elements from the stream while the specified predicate evaluates to `true`.
10250
+ * Drops elements while the filter succeeds.
10301
10251
  *
10302
- * @example
10303
- * ```ts
10304
- * import { Console, Effect, Stream } from "effect"
10305
- *
10306
- * const program = Effect.gen(function*() {
10307
- * const values = yield* Stream.make(1, 2, 3, 4, 5).pipe(
10308
- * Stream.dropWhile((n) => n < 3),
10309
- * Stream.runCollect
10310
- * )
10311
- * yield* Console.log(values)
10312
- * })
10313
- *
10314
- * Effect.runPromise(program)
10315
- * // Output: [ 3, 4, 5 ]
10316
- * ```
10252
+ * @since 4.0.0
10253
+ * @category Filtering
10254
+ */
10255
+ <A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Stream<A, E, R>) => Stream<A, E, R>
10256
+ /**
10257
+ * Drops elements while the filter succeeds.
10317
10258
  *
10318
- * @since 2.0.0
10259
+ * @since 4.0.0
10319
10260
  * @category Filtering
10320
10261
  */
10321
- <A, E, R, B, X>(self: Stream<A, E, R>, f: Filter.Filter<NoInfer<A>, B, X>): Stream<A, E, R>
10322
- } = dual(2, <A, E, R>(
10262
+ <A, E, R, B, X>(self: Stream<A, E, R>, filter: Filter.Filter<NoInfer<A>, B, X>): Stream<A, E, R>
10263
+ } = dual(2, <A, E, R, B, X>(
10323
10264
  self: Stream<A, E, R>,
10324
- f: Filter.Filter<A, any, any> | ((a: A, index: number) => boolean)
10265
+ filter: Filter.Filter<NoInfer<A>, B, X>
10325
10266
  ): Stream<A, E, R> =>
10326
10267
  transformPull(self, (pull, _scope) =>
10327
10268
  Effect.sync(() => {
10328
10269
  let dropping = true
10329
- let index = 0
10330
10270
  const filtered: Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E> = Effect.flatMap(pull, (arr) => {
10331
- const found = arr.findIndex((a) => Result.isFailure(Filter.apply(f as any, a, index++)))
10271
+ const found = arr.findIndex((a) => Result.isFailure(filter(a)))
10332
10272
  if (found === -1) return filtered
10333
10273
  dropping = false
10334
10274
  return Effect.succeed(arr.slice(found) as Arr.NonEmptyArray<A>)