effect 3.10.19 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/dist/cjs/BigDecimal.js +125 -24
  2. package/dist/cjs/BigDecimal.js.map +1 -1
  3. package/dist/cjs/Channel.js +44 -4
  4. package/dist/cjs/Channel.js.map +1 -1
  5. package/dist/cjs/Config.js +8 -1
  6. package/dist/cjs/Config.js.map +1 -1
  7. package/dist/cjs/Context.js +26 -1
  8. package/dist/cjs/Context.js.map +1 -1
  9. package/dist/cjs/Cron.js +75 -67
  10. package/dist/cjs/Cron.js.map +1 -1
  11. package/dist/cjs/DateTime.js +114 -664
  12. package/dist/cjs/DateTime.js.map +1 -1
  13. package/dist/cjs/Effect.js +82 -4
  14. package/dist/cjs/Effect.js.map +1 -1
  15. package/dist/cjs/Inspectable.js +8 -4
  16. package/dist/cjs/Inspectable.js.map +1 -1
  17. package/dist/cjs/JSONSchema.js.map +1 -1
  18. package/dist/cjs/Micro.js +1099 -1072
  19. package/dist/cjs/Micro.js.map +1 -1
  20. package/dist/cjs/STM.js.map +1 -1
  21. package/dist/cjs/Schema.js +57 -8
  22. package/dist/cjs/Schema.js.map +1 -1
  23. package/dist/cjs/Sink.js +9 -1
  24. package/dist/cjs/Sink.js.map +1 -1
  25. package/dist/cjs/Stream.js +25 -7
  26. package/dist/cjs/Stream.js.map +1 -1
  27. package/dist/cjs/Utils.js +7 -1
  28. package/dist/cjs/Utils.js.map +1 -1
  29. package/dist/cjs/internal/channel/channelExecutor.js +5 -9
  30. package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
  31. package/dist/cjs/internal/channel.js +156 -130
  32. package/dist/cjs/internal/channel.js.map +1 -1
  33. package/dist/cjs/internal/config.js +13 -4
  34. package/dist/cjs/internal/config.js.map +1 -1
  35. package/dist/cjs/internal/context.js +46 -3
  36. package/dist/cjs/internal/context.js.map +1 -1
  37. package/dist/cjs/internal/dateTime.js +747 -0
  38. package/dist/cjs/internal/dateTime.js.map +1 -0
  39. package/dist/cjs/internal/fiberRuntime.js +34 -11
  40. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  41. package/dist/cjs/internal/groupBy.js +9 -3
  42. package/dist/cjs/internal/groupBy.js.map +1 -1
  43. package/dist/cjs/internal/layer.js +1 -1
  44. package/dist/cjs/internal/layer.js.map +1 -1
  45. package/dist/cjs/internal/mailbox.js +1 -1
  46. package/dist/cjs/internal/mailbox.js.map +1 -1
  47. package/dist/cjs/internal/sink.js +25 -21
  48. package/dist/cjs/internal/sink.js.map +1 -1
  49. package/dist/cjs/internal/stream.js +70 -71
  50. package/dist/cjs/internal/stream.js.map +1 -1
  51. package/dist/cjs/internal/version.js +1 -1
  52. package/dist/cjs/internal/version.js.map +1 -1
  53. package/dist/dts/BigDecimal.d.ts +56 -1
  54. package/dist/dts/BigDecimal.d.ts.map +1 -1
  55. package/dist/dts/Channel.d.ts +66 -5
  56. package/dist/dts/Channel.d.ts.map +1 -1
  57. package/dist/dts/Config.d.ts +23 -1
  58. package/dist/dts/Config.d.ts.map +1 -1
  59. package/dist/dts/Context.d.ts +111 -0
  60. package/dist/dts/Context.d.ts.map +1 -1
  61. package/dist/dts/Cron.d.ts +15 -6
  62. package/dist/dts/Cron.d.ts.map +1 -1
  63. package/dist/dts/DateTime.d.ts +40 -49
  64. package/dist/dts/DateTime.d.ts.map +1 -1
  65. package/dist/dts/Effect.d.ts +88 -1
  66. package/dist/dts/Effect.d.ts.map +1 -1
  67. package/dist/dts/Inspectable.d.ts.map +1 -1
  68. package/dist/dts/JSONSchema.d.ts +1 -0
  69. package/dist/dts/JSONSchema.d.ts.map +1 -1
  70. package/dist/dts/Micro.d.ts +875 -872
  71. package/dist/dts/Micro.d.ts.map +1 -1
  72. package/dist/dts/STM.d.ts +2 -0
  73. package/dist/dts/STM.d.ts.map +1 -1
  74. package/dist/dts/Schema.d.ts +32 -0
  75. package/dist/dts/Schema.d.ts.map +1 -1
  76. package/dist/dts/Sink.d.ts +8 -0
  77. package/dist/dts/Sink.d.ts.map +1 -1
  78. package/dist/dts/Stream.d.ts +50 -32
  79. package/dist/dts/Stream.d.ts.map +1 -1
  80. package/dist/dts/Utils.d.ts +4 -0
  81. package/dist/dts/Utils.d.ts.map +1 -1
  82. package/dist/dts/internal/context.d.ts +1 -1
  83. package/dist/dts/internal/context.d.ts.map +1 -1
  84. package/dist/dts/internal/dateTime.d.ts +2 -0
  85. package/dist/dts/internal/dateTime.d.ts.map +1 -0
  86. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  87. package/dist/dts/internal/stream.d.ts.map +1 -1
  88. package/dist/esm/BigDecimal.js +119 -20
  89. package/dist/esm/BigDecimal.js.map +1 -1
  90. package/dist/esm/Channel.js +42 -2
  91. package/dist/esm/Channel.js.map +1 -1
  92. package/dist/esm/Config.js +7 -0
  93. package/dist/esm/Config.js.map +1 -1
  94. package/dist/esm/Context.js +25 -0
  95. package/dist/esm/Context.js.map +1 -1
  96. package/dist/esm/Cron.js +75 -67
  97. package/dist/esm/Cron.js.map +1 -1
  98. package/dist/esm/DateTime.js +112 -627
  99. package/dist/esm/DateTime.js.map +1 -1
  100. package/dist/esm/Effect.js +77 -0
  101. package/dist/esm/Effect.js.map +1 -1
  102. package/dist/esm/Inspectable.js +8 -4
  103. package/dist/esm/Inspectable.js.map +1 -1
  104. package/dist/esm/JSONSchema.js.map +1 -1
  105. package/dist/esm/Micro.js +1077 -1047
  106. package/dist/esm/Micro.js.map +1 -1
  107. package/dist/esm/STM.js.map +1 -1
  108. package/dist/esm/Schema.js +54 -0
  109. package/dist/esm/Schema.js.map +1 -1
  110. package/dist/esm/Sink.js +8 -0
  111. package/dist/esm/Sink.js.map +1 -1
  112. package/dist/esm/Stream.js +23 -5
  113. package/dist/esm/Stream.js.map +1 -1
  114. package/dist/esm/Utils.js +5 -0
  115. package/dist/esm/Utils.js.map +1 -1
  116. package/dist/esm/internal/channel/channelExecutor.js +5 -7
  117. package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
  118. package/dist/esm/internal/channel.js +152 -129
  119. package/dist/esm/internal/channel.js.map +1 -1
  120. package/dist/esm/internal/config.js +11 -3
  121. package/dist/esm/internal/config.js.map +1 -1
  122. package/dist/esm/internal/context.js +42 -2
  123. package/dist/esm/internal/context.js.map +1 -1
  124. package/dist/esm/internal/dateTime.js +704 -0
  125. package/dist/esm/internal/dateTime.js.map +1 -0
  126. package/dist/esm/internal/fiberRuntime.js +31 -9
  127. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  128. package/dist/esm/internal/groupBy.js +9 -3
  129. package/dist/esm/internal/groupBy.js.map +1 -1
  130. package/dist/esm/internal/layer.js +1 -1
  131. package/dist/esm/internal/layer.js.map +1 -1
  132. package/dist/esm/internal/mailbox.js +1 -1
  133. package/dist/esm/internal/mailbox.js.map +1 -1
  134. package/dist/esm/internal/sink.js +23 -20
  135. package/dist/esm/internal/sink.js.map +1 -1
  136. package/dist/esm/internal/stream.js +66 -69
  137. package/dist/esm/internal/stream.js.map +1 -1
  138. package/dist/esm/internal/version.js +1 -1
  139. package/dist/esm/internal/version.js.map +1 -1
  140. package/package.json +1 -1
  141. package/src/BigDecimal.ts +131 -21
  142. package/src/Channel.ts +81 -5
  143. package/src/Config.ts +24 -1
  144. package/src/Context.ts +119 -0
  145. package/src/Cron.ts +85 -68
  146. package/src/DateTime.ts +155 -757
  147. package/src/Effect.ts +340 -1
  148. package/src/Inspectable.ts +11 -7
  149. package/src/JSONSchema.ts +1 -0
  150. package/src/Micro.ts +2005 -1757
  151. package/src/STM.ts +2 -0
  152. package/src/Schema.ts +60 -0
  153. package/src/Sink.ts +11 -0
  154. package/src/Stream.ts +55 -44
  155. package/src/Utils.ts +8 -0
  156. package/src/internal/channel/channelExecutor.ts +37 -33
  157. package/src/internal/channel.ts +504 -467
  158. package/src/internal/config.ts +18 -6
  159. package/src/internal/context.ts +56 -4
  160. package/src/internal/dateTime.ts +1126 -0
  161. package/src/internal/fiberRuntime.ts +35 -16
  162. package/src/internal/groupBy.ts +13 -22
  163. package/src/internal/layer.ts +5 -8
  164. package/src/internal/mailbox.ts +6 -4
  165. package/src/internal/sink.ts +55 -35
  166. package/src/internal/stream.ts +299 -299
  167. package/src/internal/version.ts +1 -1
package/src/STM.ts CHANGED
@@ -106,6 +106,8 @@ export interface STMTypeLambda extends TypeLambda {
106
106
  */
107
107
  declare module "./Context.js" {
108
108
  interface Tag<Id, Value> extends STM<Value, never, Id> {}
109
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
110
+ interface Reference<Id, Value> extends STM<Value> {}
109
111
  }
110
112
 
111
113
  /**
package/src/Schema.ts CHANGED
@@ -5041,6 +5041,10 @@ export class UUID extends String$.pipe(
5041
5041
  schemaId: UUIDSchemaId,
5042
5042
  identifier: "UUID",
5043
5043
  title: "UUID",
5044
+ jsonSchema: {
5045
+ format: "uuid",
5046
+ pattern: uuidRegexp.source
5047
+ },
5044
5048
  description: "a Universally Unique Identifier",
5045
5049
  arbitrary: (): LazyArbitrary<string> => (fc) => fc.uuid()
5046
5050
  })
@@ -5073,6 +5077,49 @@ export class ULID extends String$.pipe(
5073
5077
  })
5074
5078
  ) {}
5075
5079
 
5080
+ /**
5081
+ * Defines a schema that represents a `URL` object.
5082
+ *
5083
+ * @category URL constructors
5084
+ * @since 3.11.0
5085
+ */
5086
+ export class URLFromSelf extends instanceOf(URL, {
5087
+ identifier: "URLFromSelf",
5088
+ title: "URLFromSelf",
5089
+ arbitrary: (): LazyArbitrary<URL> => (fc) => fc.webUrl().map((s) => new URL(s)),
5090
+ pretty: () => (url) => url.toString()
5091
+ }) {}
5092
+
5093
+ /** @ignore */
5094
+ class URL$ extends transformOrFail(
5095
+ String$.annotations({ description: "a string that will be parsed into a URL" }),
5096
+ URLFromSelf,
5097
+ {
5098
+ strict: true,
5099
+ decode: (str, _, ast) =>
5100
+ ParseResult.try({
5101
+ try: () => new URL(str),
5102
+ catch: () => new ParseResult.Type(ast, str)
5103
+ }),
5104
+ encode: (url) => ParseResult.succeed(url.toString())
5105
+ }
5106
+ ).annotations({
5107
+ identifier: "URL",
5108
+ title: "URL",
5109
+ pretty: () => (url) => url.toString()
5110
+ }) {}
5111
+
5112
+ export {
5113
+ /**
5114
+ * Defines a schema that attempts to convert a `string` to a `URL` object using
5115
+ * the `new URL` constructor.
5116
+ *
5117
+ * @category URL transformations
5118
+ * @since 3.11.0
5119
+ */
5120
+ URL$ as URL
5121
+ }
5122
+
5076
5123
  /**
5077
5124
  * @category schema id
5078
5125
  * @since 3.10.0
@@ -9793,6 +9840,19 @@ export class BooleanFromUnknown extends transform(
9793
9840
  { strict: true, decode: Predicate.isTruthy, encode: identity }
9794
9841
  ).annotations({ identifier: "BooleanFromUnknown" }) {}
9795
9842
 
9843
+ /**
9844
+ * Converts an `string` value into its corresponding `boolean`
9845
+ * ("true" as `true` and "false" as `false`).
9846
+ *
9847
+ * @category boolean transformations
9848
+ * @since 3.11.0
9849
+ */
9850
+ export class BooleanFromString extends transform(
9851
+ Literal("true", "false"),
9852
+ Boolean$,
9853
+ { strict: true, decode: (value) => value === "true", encode: (value) => value ? "true" : "false" }
9854
+ ).annotations({ identifier: "BooleanFromString" }) {}
9855
+
9796
9856
  /**
9797
9857
  * @category Config validations
9798
9858
  * @since 3.10.0
package/src/Sink.ts CHANGED
@@ -1765,6 +1765,17 @@ export const unwrapScoped: <A, In, L, E, R>(
1765
1765
  effect: Effect.Effect<Sink<A, In, L, E, R>, E, R>
1766
1766
  ) => Sink<A, In, L, E, Exclude<R, Scope.Scope>> = internal.unwrapScoped
1767
1767
 
1768
+ /**
1769
+ * Constructs a `Sink` from a function which receives a `Scope` and returns
1770
+ * an effect that will result in a `Sink` if successful.
1771
+ *
1772
+ * @since 3.11.0
1773
+ * @category constructors
1774
+ */
1775
+ export const unwrapScopedWith: <A, In, L, E, R>(
1776
+ f: (scope: Scope.Scope) => Effect.Effect<Sink<A, In, L, E, R>, E, R>
1777
+ ) => Sink<A, In, L, E, R> = internal.unwrapScopedWith
1778
+
1768
1779
  /**
1769
1780
  * Returns the sink that executes this one and times its execution.
1770
1781
  *
package/src/Stream.ts CHANGED
@@ -6162,8 +6162,8 @@ export const paginateEffect: <S, A, E, R>(
6162
6162
 
6163
6163
  /**
6164
6164
  * Partition a stream using a predicate. The first stream will contain all
6165
- * element evaluated to true and the second one will contain all element
6166
- * evaluated to false. The faster stream may advance by up to buffer elements
6165
+ * element evaluated to false and the second one will contain all element
6166
+ * evaluated to true. The faster stream may advance by up to buffer elements
6167
6167
  * further than the slower one.
6168
6168
  *
6169
6169
  * @example
@@ -6176,15 +6176,15 @@ export const paginateEffect: <S, A, E, R>(
6176
6176
  *
6177
6177
  * const program = Effect.scoped(
6178
6178
  * Effect.gen(function*() {
6179
- * const [evens, odds] = yield* partition
6180
- * console.log(yield* Stream.runCollect(evens))
6179
+ * const [odds, evens] = yield* partition
6181
6180
  * console.log(yield* Stream.runCollect(odds))
6181
+ * console.log(yield* Stream.runCollect(evens))
6182
6182
  * })
6183
6183
  * )
6184
6184
  *
6185
6185
  * // Effect.runPromise(program)
6186
- * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6187
6186
  * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] }
6187
+ * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6188
6188
  * ```
6189
6189
  *
6190
6190
  * @since 2.0.0
@@ -6193,8 +6193,8 @@ export const paginateEffect: <S, A, E, R>(
6193
6193
  export const partition: {
6194
6194
  /**
6195
6195
  * Partition a stream using a predicate. The first stream will contain all
6196
- * element evaluated to true and the second one will contain all element
6197
- * evaluated to false. The faster stream may advance by up to buffer elements
6196
+ * element evaluated to false and the second one will contain all element
6197
+ * evaluated to true. The faster stream may advance by up to buffer elements
6198
6198
  * further than the slower one.
6199
6199
  *
6200
6200
  * @example
@@ -6207,15 +6207,15 @@ export const partition: {
6207
6207
  *
6208
6208
  * const program = Effect.scoped(
6209
6209
  * Effect.gen(function*() {
6210
- * const [evens, odds] = yield* partition
6211
- * console.log(yield* Stream.runCollect(evens))
6210
+ * const [odds, evens] = yield* partition
6212
6211
  * console.log(yield* Stream.runCollect(odds))
6212
+ * console.log(yield* Stream.runCollect(evens))
6213
6213
  * })
6214
6214
  * )
6215
6215
  *
6216
6216
  * // Effect.runPromise(program)
6217
- * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6218
6217
  * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] }
6218
+ * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6219
6219
  * ```
6220
6220
  *
6221
6221
  * @since 2.0.0
@@ -6229,8 +6229,8 @@ export const partition: {
6229
6229
  ) => Effect.Effect<[excluded: Stream<Exclude<C, B>, E, never>, satisfying: Stream<B, E, never>], E, R | Scope.Scope>
6230
6230
  /**
6231
6231
  * Partition a stream using a predicate. The first stream will contain all
6232
- * element evaluated to true and the second one will contain all element
6233
- * evaluated to false. The faster stream may advance by up to buffer elements
6232
+ * element evaluated to false and the second one will contain all element
6233
+ * evaluated to true. The faster stream may advance by up to buffer elements
6234
6234
  * further than the slower one.
6235
6235
  *
6236
6236
  * @example
@@ -6243,15 +6243,15 @@ export const partition: {
6243
6243
  *
6244
6244
  * const program = Effect.scoped(
6245
6245
  * Effect.gen(function*() {
6246
- * const [evens, odds] = yield* partition
6247
- * console.log(yield* Stream.runCollect(evens))
6246
+ * const [odds, evens] = yield* partition
6248
6247
  * console.log(yield* Stream.runCollect(odds))
6248
+ * console.log(yield* Stream.runCollect(evens))
6249
6249
  * })
6250
6250
  * )
6251
6251
  *
6252
6252
  * // Effect.runPromise(program)
6253
- * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6254
6253
  * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] }
6254
+ * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6255
6255
  * ```
6256
6256
  *
6257
6257
  * @since 2.0.0
@@ -6265,8 +6265,8 @@ export const partition: {
6265
6265
  ) => Effect.Effect<[excluded: Stream<A, E, never>, satisfying: Stream<A, E, never>], E, Scope.Scope | R>
6266
6266
  /**
6267
6267
  * Partition a stream using a predicate. The first stream will contain all
6268
- * element evaluated to true and the second one will contain all element
6269
- * evaluated to false. The faster stream may advance by up to buffer elements
6268
+ * element evaluated to false and the second one will contain all element
6269
+ * evaluated to true. The faster stream may advance by up to buffer elements
6270
6270
  * further than the slower one.
6271
6271
  *
6272
6272
  * @example
@@ -6279,15 +6279,15 @@ export const partition: {
6279
6279
  *
6280
6280
  * const program = Effect.scoped(
6281
6281
  * Effect.gen(function*() {
6282
- * const [evens, odds] = yield* partition
6283
- * console.log(yield* Stream.runCollect(evens))
6282
+ * const [odds, evens] = yield* partition
6284
6283
  * console.log(yield* Stream.runCollect(odds))
6284
+ * console.log(yield* Stream.runCollect(evens))
6285
6285
  * })
6286
6286
  * )
6287
6287
  *
6288
6288
  * // Effect.runPromise(program)
6289
- * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6290
6289
  * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] }
6290
+ * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6291
6291
  * ```
6292
6292
  *
6293
6293
  * @since 2.0.0
@@ -6300,8 +6300,8 @@ export const partition: {
6300
6300
  ): Effect.Effect<[excluded: Stream<Exclude<C, B>, E, never>, satisfying: Stream<B, E, never>], E, R | Scope.Scope>
6301
6301
  /**
6302
6302
  * Partition a stream using a predicate. The first stream will contain all
6303
- * element evaluated to true and the second one will contain all element
6304
- * evaluated to false. The faster stream may advance by up to buffer elements
6303
+ * element evaluated to false and the second one will contain all element
6304
+ * evaluated to true. The faster stream may advance by up to buffer elements
6305
6305
  * further than the slower one.
6306
6306
  *
6307
6307
  * @example
@@ -6314,15 +6314,15 @@ export const partition: {
6314
6314
  *
6315
6315
  * const program = Effect.scoped(
6316
6316
  * Effect.gen(function*() {
6317
- * const [evens, odds] = yield* partition
6318
- * console.log(yield* Stream.runCollect(evens))
6317
+ * const [odds, evens] = yield* partition
6319
6318
  * console.log(yield* Stream.runCollect(odds))
6319
+ * console.log(yield* Stream.runCollect(evens))
6320
6320
  * })
6321
6321
  * )
6322
6322
  *
6323
6323
  * // Effect.runPromise(program)
6324
- * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6325
6324
  * // { _id: 'Chunk', values: [ 1, 3, 5, 7, 9 ] }
6325
+ * // { _id: 'Chunk', values: [ 2, 4, 6, 8, 10 ] }
6326
6326
  * ```
6327
6327
  *
6328
6328
  * @since 2.0.0
@@ -7420,8 +7420,7 @@ export const run: {
7420
7420
  * @since 2.0.0
7421
7421
  * @category destructors
7422
7422
  */
7423
- export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, Exclude<R, Scope.Scope>> =
7424
- internal.runCollect
7423
+ export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, R> = internal.runCollect
7425
7424
 
7426
7425
  /**
7427
7426
  * Runs the stream and emits the number of elements processed
@@ -7429,8 +7428,7 @@ export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk
7429
7428
  * @since 2.0.0
7430
7429
  * @category destructors
7431
7430
  */
7432
- export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number, E, Exclude<R, Scope.Scope>> =
7433
- internal.runCount
7431
+ export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number, E, R> = internal.runCount
7434
7432
 
7435
7433
  /**
7436
7434
  * Runs the stream only for its effects. The emitted elements are discarded.
@@ -7438,8 +7436,7 @@ export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number,
7438
7436
  * @since 2.0.0
7439
7437
  * @category destructors
7440
7438
  */
7441
- export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>> =
7442
- internal.runDrain
7439
+ export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, R> = internal.runDrain
7443
7440
 
7444
7441
  /**
7445
7442
  * Executes a pure fold over the stream of values - reduces all elements in
@@ -7456,7 +7453,7 @@ export const runFold: {
7456
7453
  * @since 2.0.0
7457
7454
  * @category destructors
7458
7455
  */
7459
- <S, A>(s: S, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, Exclude<R, Scope.Scope>>
7456
+ <S, A>(s: S, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, R>
7460
7457
  /**
7461
7458
  * Executes a pure fold over the stream of values - reduces all elements in
7462
7459
  * the stream to a value of type `S`.
@@ -7464,7 +7461,7 @@ export const runFold: {
7464
7461
  * @since 2.0.0
7465
7462
  * @category destructors
7466
7463
  */
7467
- <A, E, R, S>(self: Stream<A, E, R>, s: S, f: (s: S, a: A) => S): Effect.Effect<S, E, Exclude<R, Scope.Scope>>
7464
+ <A, E, R, S>(self: Stream<A, E, R>, s: S, f: (s: S, a: A) => S): Effect.Effect<S, E, R>
7468
7465
  } = internal.runFold
7469
7466
 
7470
7467
  /**
@@ -7571,11 +7568,7 @@ export const runFoldWhile: {
7571
7568
  * @since 2.0.0
7572
7569
  * @category destructors
7573
7570
  */
7574
- <S, A>(
7575
- s: S,
7576
- cont: Predicate<S>,
7577
- f: (s: S, a: A) => S
7578
- ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, Exclude<R, Scope.Scope>>
7571
+ <S, A>(s: S, cont: Predicate<S>, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, R>
7579
7572
  /**
7580
7573
  * Reduces the elements in the stream to a value of type `S`. Stops the fold
7581
7574
  * early when the condition is not fulfilled. Example:
@@ -7583,12 +7576,7 @@ export const runFoldWhile: {
7583
7576
  * @since 2.0.0
7584
7577
  * @category destructors
7585
7578
  */
7586
- <A, E, R, S>(
7587
- self: Stream<A, E, R>,
7588
- s: S,
7589
- cont: Predicate<S>,
7590
- f: (s: S, a: A) => S
7591
- ): Effect.Effect<S, E, Exclude<R, Scope.Scope>>
7579
+ <A, E, R, S>(self: Stream<A, E, R>, s: S, cont: Predicate<S>, f: (s: S, a: A) => S): Effect.Effect<S, E, R>
7592
7580
  } = internal.runFoldWhile
7593
7581
 
7594
7582
  /**
@@ -8323,6 +8311,17 @@ export const scheduleWith: {
8323
8311
  export const scoped: <A, E, R>(effect: Effect.Effect<A, E, R>) => Stream<A, E, Exclude<R, Scope.Scope>> =
8324
8312
  internal.scoped
8325
8313
 
8314
+ /**
8315
+ * Use a function that receives a scope and returns an effect to emit an output
8316
+ * element. The output element will be the result of the returned effect, if
8317
+ * successful.
8318
+ *
8319
+ * @since 3.11.0
8320
+ * @category constructors
8321
+ */
8322
+ export const scopedWith: <A, E, R>(f: (scope: Scope.Scope) => Effect.Effect<A, E, R>) => Stream<A, E, R> =
8323
+ internal.scopedWith
8324
+
8326
8325
  /**
8327
8326
  * Emits a sliding window of `n` elements.
8328
8327
  *
@@ -9914,6 +9913,18 @@ export const unwrapScoped: <A, E2, R2, E, R>(
9914
9913
  effect: Effect.Effect<Stream<A, E2, R2>, E, R>
9915
9914
  ) => Stream<A, E | E2, R2 | Exclude<R, Scope.Scope>> = internal.unwrapScoped
9916
9915
 
9916
+ /**
9917
+ * Creates a stream produced from a function which receives a `Scope` and
9918
+ * returns an `Effect`. The resulting stream will emit a single element, which
9919
+ * will be the result of the returned effect, if successful.
9920
+ *
9921
+ * @since 3.11.0
9922
+ * @category constructors
9923
+ */
9924
+ export const unwrapScopedWith: <A, E2, R2, E, R>(
9925
+ f: (scope: Scope.Scope) => Effect.Effect<Stream<A, E2, R2>, E, R>
9926
+ ) => Stream<A, E | E2, R | R2> = internal.unwrapScopedWith
9927
+
9917
9928
  /**
9918
9929
  * Updates the specified service within the context of the `Stream`.
9919
9930
  *
package/src/Utils.ts CHANGED
@@ -791,3 +791,11 @@ const tracingFunction = (name: string) => {
791
791
  * @category tracing
792
792
  */
793
793
  export const internalCall = tracingFunction("effect_internal_function")
794
+
795
+ const genConstructor = (function*() {}).constructor
796
+
797
+ /**
798
+ * @since 3.11.0
799
+ */
800
+ export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>
801
+ isObject(u) && u.constructor === genConstructor
@@ -7,7 +7,7 @@ import * as Effect from "../../Effect.js"
7
7
  import * as ExecutionStrategy from "../../ExecutionStrategy.js"
8
8
  import * as Exit from "../../Exit.js"
9
9
  import * as Fiber from "../../Fiber.js"
10
- import { identity, pipe } from "../../Function.js"
10
+ import { dual, identity, pipe } from "../../Function.js"
11
11
  import * as Option from "../../Option.js"
12
12
  import * as Scope from "../../Scope.js"
13
13
  import type * as UpstreamPullStrategy from "../../UpstreamPullStrategy.js"
@@ -1092,14 +1092,18 @@ export const readUpstream = <A, E2, R, E>(
1092
1092
  }
1093
1093
 
1094
1094
  /** @internal */
1095
- export const run = <Env, InErr, InDone, OutErr, OutDone>(
1096
- self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
1097
- ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => pipe(runScoped(self), Effect.scoped)
1098
-
1099
- /** @internal */
1100
- export const runScoped = <Env, InErr, InDone, OutErr, OutDone>(
1101
- self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
1102
- ): Effect.Effect<OutDone, OutErr, Env | Scope.Scope> => {
1095
+ export const runIn = dual<
1096
+ (scope: Scope.Scope) => <Env, InErr, InDone, OutErr, OutDone>(
1097
+ self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
1098
+ ) => Effect.Effect<OutDone, OutErr, Env>,
1099
+ <Env, InErr, InDone, OutErr, OutDone>(
1100
+ self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>,
1101
+ scope: Scope.Scope
1102
+ ) => Effect.Effect<OutDone, OutErr, Env>
1103
+ >(2, <Env, InErr, InDone, OutErr, OutDone>(
1104
+ self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>,
1105
+ scope: Scope.Scope
1106
+ ) => {
1103
1107
  const run = (
1104
1108
  channelDeferred: Deferred.Deferred<OutDone, OutErr>,
1105
1109
  scopeDeferred: Deferred.Deferred<void>,
@@ -1109,8 +1113,7 @@ export const runScoped = <Env, InErr, InDone, OutErr, OutDone>(
1109
1113
  Effect.sync(() => new ChannelExecutor(self, void 0, identity)),
1110
1114
  (exec) =>
1111
1115
  Effect.suspend(() =>
1112
- pipe(
1113
- runScopedInterpret(exec.run() as ChannelState.ChannelState<OutErr, Env>, exec),
1116
+ runScopedInterpret(exec.run() as ChannelState.ChannelState<OutErr, Env>, exec).pipe(
1114
1117
  Effect.intoDeferred(channelDeferred),
1115
1118
  Effect.zipRight(Deferred.await(channelDeferred)),
1116
1119
  Effect.zipLeft(Deferred.await(scopeDeferred))
@@ -1128,33 +1131,34 @@ export const runScoped = <Env, InErr, InDone, OutErr, OutDone>(
1128
1131
  }
1129
1132
  )
1130
1133
  return Effect.uninterruptibleMask((restore) =>
1131
- Effect.flatMap(Effect.scope, (parent) =>
1132
- pipe(
1133
- Effect.all([
1134
- Scope.fork(parent, ExecutionStrategy.sequential),
1135
- Deferred.make<OutDone, OutErr>(),
1136
- Deferred.make<void>()
1137
- ]),
1138
- Effect.flatMap(([child, channelDeferred, scopeDeferred]) =>
1139
- pipe(
1140
- Effect.forkScoped(restore(run(channelDeferred, scopeDeferred, child))),
1141
- Effect.flatMap((fiber) =>
1142
- pipe(
1143
- Scope.addFinalizer(
1144
- parent,
1145
- Deferred.succeed(scopeDeferred, void 0).pipe(
1146
- Effect.zipRight(Effect.yieldNow())
1134
+ Effect.all([
1135
+ Scope.fork(scope, ExecutionStrategy.sequential),
1136
+ Deferred.make<OutDone, OutErr>(),
1137
+ Deferred.make<void>()
1138
+ ]).pipe(Effect.flatMap(([child, channelDeferred, scopeDeferred]) =>
1139
+ restore(run(channelDeferred, scopeDeferred, child)).pipe(
1140
+ Effect.forkIn(scope),
1141
+ Effect.flatMap((fiber) =>
1142
+ scope.addFinalizer(() =>
1143
+ Deferred.isDone(channelDeferred).pipe(
1144
+ Effect.flatMap((isDone) =>
1145
+ isDone
1146
+ ? Deferred.succeed(scopeDeferred, void 0).pipe(
1147
+ Effect.zipRight(Fiber.await(fiber)),
1148
+ Effect.zipRight(Fiber.inheritAll(fiber))
1149
+ )
1150
+ : Deferred.succeed(scopeDeferred, void 0).pipe(
1151
+ Effect.zipRight(Fiber.interrupt(fiber)),
1152
+ Effect.zipRight(Fiber.inheritAll(fiber))
1147
1153
  )
1148
- ),
1149
- Effect.zipRight(restore(Deferred.await(channelDeferred))),
1150
- Effect.zipLeft(Fiber.inheritAll(fiber))
1151
1154
  )
1152
1155
  )
1153
- )
1156
+ ).pipe(Effect.zipRight(restore(Deferred.await(channelDeferred))))
1154
1157
  )
1155
- ))
1158
+ )
1159
+ ))
1156
1160
  )
1157
- }
1161
+ })
1158
1162
 
1159
1163
  /** @internal */
1160
1164
  const runScopedInterpret = <Env, InErr, InDone, OutErr, OutDone>(