effect 3.4.9 → 3.5.1

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 (166) hide show
  1. package/RcMap/package.json +6 -0
  2. package/RcRef/package.json +6 -0
  3. package/dist/cjs/Cause.js +22 -1
  4. package/dist/cjs/Cause.js.map +1 -1
  5. package/dist/cjs/Channel.js.map +1 -1
  6. package/dist/cjs/Config.js.map +1 -1
  7. package/dist/cjs/Console.js.map +1 -1
  8. package/dist/cjs/Data.js +3 -1
  9. package/dist/cjs/Data.js.map +1 -1
  10. package/dist/cjs/Duration.js +23 -2
  11. package/dist/cjs/Duration.js.map +1 -1
  12. package/dist/cjs/Effect.js +78 -15
  13. package/dist/cjs/Effect.js.map +1 -1
  14. package/dist/cjs/Logger.js +234 -13
  15. package/dist/cjs/Logger.js.map +1 -1
  16. package/dist/cjs/PubSub.js.map +1 -1
  17. package/dist/cjs/Random.js +24 -1
  18. package/dist/cjs/Random.js.map +1 -1
  19. package/dist/cjs/RcMap.js +52 -0
  20. package/dist/cjs/RcMap.js.map +1 -0
  21. package/dist/cjs/RcRef.js +51 -0
  22. package/dist/cjs/RcRef.js.map +1 -0
  23. package/dist/cjs/Stream.js +29 -2
  24. package/dist/cjs/Stream.js.map +1 -1
  25. package/dist/cjs/index.js +6 -2
  26. package/dist/cjs/index.js.map +1 -1
  27. package/dist/cjs/internal/cause.js +21 -5
  28. package/dist/cjs/internal/cause.js.map +1 -1
  29. package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
  30. package/dist/cjs/internal/channel.js.map +1 -1
  31. package/dist/cjs/internal/core-effect.js +0 -5
  32. package/dist/cjs/internal/core-effect.js.map +1 -1
  33. package/dist/cjs/internal/core.js +15 -10
  34. package/dist/cjs/internal/core.js.map +1 -1
  35. package/dist/cjs/internal/defaultServices.js +1 -1
  36. package/dist/cjs/internal/defaultServices.js.map +1 -1
  37. package/dist/cjs/internal/fiberRuntime.js +3 -1
  38. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  39. package/dist/cjs/internal/logger.js +129 -27
  40. package/dist/cjs/internal/logger.js.map +1 -1
  41. package/dist/cjs/internal/pubsub.js +216 -36
  42. package/dist/cjs/internal/pubsub.js.map +1 -1
  43. package/dist/cjs/internal/random.js +2 -1
  44. package/dist/cjs/internal/random.js.map +1 -1
  45. package/dist/cjs/internal/rcMap.js +129 -0
  46. package/dist/cjs/internal/rcMap.js.map +1 -0
  47. package/dist/cjs/internal/rcRef.js +122 -0
  48. package/dist/cjs/internal/rcRef.js.map +1 -0
  49. package/dist/cjs/internal/stream.js +57 -11
  50. package/dist/cjs/internal/stream.js.map +1 -1
  51. package/dist/cjs/internal/version.js +1 -1
  52. package/dist/dts/Cause.d.ts +40 -1
  53. package/dist/dts/Cause.d.ts.map +1 -1
  54. package/dist/dts/Channel.d.ts +3 -3
  55. package/dist/dts/Channel.d.ts.map +1 -1
  56. package/dist/dts/Config.d.ts +5 -0
  57. package/dist/dts/Config.d.ts.map +1 -1
  58. package/dist/dts/Console.d.ts +2 -4
  59. package/dist/dts/Console.d.ts.map +1 -1
  60. package/dist/dts/Duration.d.ts +5 -0
  61. package/dist/dts/Duration.d.ts.map +1 -1
  62. package/dist/dts/Effect.d.ts +78 -15
  63. package/dist/dts/Effect.d.ts.map +1 -1
  64. package/dist/dts/Logger.d.ts +238 -12
  65. package/dist/dts/Logger.d.ts.map +1 -1
  66. package/dist/dts/PubSub.d.ts +15 -4
  67. package/dist/dts/PubSub.d.ts.map +1 -1
  68. package/dist/dts/Random.d.ts +23 -0
  69. package/dist/dts/Random.d.ts.map +1 -1
  70. package/dist/dts/RcMap.d.ts +93 -0
  71. package/dist/dts/RcMap.d.ts.map +1 -0
  72. package/dist/dts/RcRef.d.ts +83 -0
  73. package/dist/dts/RcRef.d.ts.map +1 -0
  74. package/dist/dts/Stream.d.ts +64 -26
  75. package/dist/dts/Stream.d.ts.map +1 -1
  76. package/dist/dts/index.d.ts +8 -0
  77. package/dist/dts/index.d.ts.map +1 -1
  78. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  79. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  80. package/dist/dts/internal/logger.d.ts.map +1 -1
  81. package/dist/dts/internal/random.d.ts +1 -1
  82. package/dist/dts/internal/random.d.ts.map +1 -1
  83. package/dist/dts/internal/rcMap.d.ts +2 -0
  84. package/dist/dts/internal/rcMap.d.ts.map +1 -0
  85. package/dist/dts/internal/rcRef.d.ts +2 -0
  86. package/dist/dts/internal/rcRef.d.ts.map +1 -0
  87. package/dist/dts/internal/stream.d.ts +1 -0
  88. package/dist/dts/internal/stream.d.ts.map +1 -1
  89. package/dist/esm/Cause.js +21 -0
  90. package/dist/esm/Cause.js.map +1 -1
  91. package/dist/esm/Channel.js.map +1 -1
  92. package/dist/esm/Config.js.map +1 -1
  93. package/dist/esm/Console.js.map +1 -1
  94. package/dist/esm/Data.js +3 -1
  95. package/dist/esm/Data.js.map +1 -1
  96. package/dist/esm/Duration.js +20 -0
  97. package/dist/esm/Duration.js.map +1 -1
  98. package/dist/esm/Effect.js +78 -15
  99. package/dist/esm/Effect.js.map +1 -1
  100. package/dist/esm/Logger.js +233 -12
  101. package/dist/esm/Logger.js.map +1 -1
  102. package/dist/esm/PubSub.js.map +1 -1
  103. package/dist/esm/Random.js +23 -0
  104. package/dist/esm/Random.js.map +1 -1
  105. package/dist/esm/RcMap.js +44 -0
  106. package/dist/esm/RcMap.js.map +1 -0
  107. package/dist/esm/RcRef.js +43 -0
  108. package/dist/esm/RcRef.js.map +1 -0
  109. package/dist/esm/Stream.js +27 -0
  110. package/dist/esm/Stream.js.map +1 -1
  111. package/dist/esm/index.js +8 -0
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/internal/cause.js +21 -5
  114. package/dist/esm/internal/cause.js.map +1 -1
  115. package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
  116. package/dist/esm/internal/channel.js.map +1 -1
  117. package/dist/esm/internal/core-effect.js +0 -5
  118. package/dist/esm/internal/core-effect.js.map +1 -1
  119. package/dist/esm/internal/core.js +11 -7
  120. package/dist/esm/internal/core.js.map +1 -1
  121. package/dist/esm/internal/defaultServices.js +1 -1
  122. package/dist/esm/internal/defaultServices.js.map +1 -1
  123. package/dist/esm/internal/fiberRuntime.js +2 -0
  124. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  125. package/dist/esm/internal/logger.js +127 -26
  126. package/dist/esm/internal/logger.js.map +1 -1
  127. package/dist/esm/internal/pubsub.js +216 -36
  128. package/dist/esm/internal/pubsub.js.map +1 -1
  129. package/dist/esm/internal/random.js +2 -1
  130. package/dist/esm/internal/random.js.map +1 -1
  131. package/dist/esm/internal/rcMap.js +120 -0
  132. package/dist/esm/internal/rcMap.js.map +1 -0
  133. package/dist/esm/internal/rcRef.js +112 -0
  134. package/dist/esm/internal/rcRef.js.map +1 -0
  135. package/dist/esm/internal/stream.js +53 -8
  136. package/dist/esm/internal/stream.js.map +1 -1
  137. package/dist/esm/internal/version.js +1 -1
  138. package/package.json +17 -1
  139. package/src/Cause.ts +47 -1
  140. package/src/Channel.ts +3 -3
  141. package/src/Config.ts +6 -0
  142. package/src/Console.ts +2 -4
  143. package/src/Data.ts +1 -1
  144. package/src/Duration.ts +18 -0
  145. package/src/Effect.ts +78 -15
  146. package/src/Logger.ts +242 -12
  147. package/src/PubSub.ts +11 -4
  148. package/src/Random.ts +24 -0
  149. package/src/RcMap.ts +103 -0
  150. package/src/RcRef.ts +91 -0
  151. package/src/Stream.ts +83 -26
  152. package/src/index.ts +10 -0
  153. package/src/internal/cause.ts +26 -5
  154. package/src/internal/channel/channelExecutor.ts +1 -1
  155. package/src/internal/channel.ts +4 -3
  156. package/src/internal/core-effect.ts +0 -5
  157. package/src/internal/core.ts +19 -9
  158. package/src/internal/defaultServices.ts +1 -1
  159. package/src/internal/fiberRuntime.ts +6 -0
  160. package/src/internal/logger.ts +135 -27
  161. package/src/internal/pubsub.ts +249 -58
  162. package/src/internal/random.ts +2 -1
  163. package/src/internal/rcMap.ts +213 -0
  164. package/src/internal/rcRef.ts +172 -0
  165. package/src/internal/stream.ts +325 -111
  166. package/src/internal/version.ts +1 -1
package/src/PubSub.ts CHANGED
@@ -46,7 +46,9 @@ export interface PubSub<in out A> extends Queue.Enqueue<A>, Pipeable {
46
46
  * @since 2.0.0
47
47
  * @category constructors
48
48
  */
49
- export const bounded: <A>(requestedCapacity: number) => Effect.Effect<PubSub<A>> = internal.bounded
49
+ export const bounded: <A>(
50
+ capacity: number | { readonly capacity: number; readonly replay?: number | undefined }
51
+ ) => Effect.Effect<PubSub<A>> = internal.bounded
50
52
 
51
53
  /**
52
54
  * Creates a bounded `PubSub` with the dropping strategy. The `PubSub` will drop new
@@ -57,7 +59,9 @@ export const bounded: <A>(requestedCapacity: number) => Effect.Effect<PubSub<A>>
57
59
  * @since 2.0.0
58
60
  * @category constructors
59
61
  */
60
- export const dropping: <A>(requestedCapacity: number) => Effect.Effect<PubSub<A>> = internal.dropping
62
+ export const dropping: <A>(
63
+ capacity: number | { readonly capacity: number; readonly replay?: number | undefined }
64
+ ) => Effect.Effect<PubSub<A>> = internal.dropping
61
65
 
62
66
  /**
63
67
  * Creates a bounded `PubSub` with the sliding strategy. The `PubSub` will add new
@@ -68,7 +72,9 @@ export const dropping: <A>(requestedCapacity: number) => Effect.Effect<PubSub<A>
68
72
  * @since 2.0.0
69
73
  * @category constructors
70
74
  */
71
- export const sliding: <A>(requestedCapacity: number) => Effect.Effect<PubSub<A>> = internal.sliding
75
+ export const sliding: <A>(
76
+ capacity: number | { readonly capacity: number; readonly replay?: number | undefined }
77
+ ) => Effect.Effect<PubSub<A>> = internal.sliding
72
78
 
73
79
  /**
74
80
  * Creates an unbounded `PubSub`.
@@ -76,7 +82,8 @@ export const sliding: <A>(requestedCapacity: number) => Effect.Effect<PubSub<A>>
76
82
  * @since 2.0.0
77
83
  * @category constructors
78
84
  */
79
- export const unbounded: <A>() => Effect.Effect<PubSub<A>> = internal.unbounded
85
+ export const unbounded: <A>(options?: { readonly replay?: number | undefined }) => Effect.Effect<PubSub<A>> =
86
+ internal.unbounded
80
87
 
81
88
  /**
82
89
  * Returns the number of elements the queue can hold.
package/src/Random.ts CHANGED
@@ -118,3 +118,27 @@ export const randomWith: <A, E, R>(f: (random: Random) => Effect.Effect<A, E, R>
118
118
  * @category context
119
119
  */
120
120
  export const Random: Context.Tag<Random, Random> = internal.randomTag
121
+
122
+ /**
123
+ * Constructs the `Random` service, seeding the pseudo-random number generator
124
+ * with an hash of the specified seed.
125
+ * This constructor is useful for generating predictable sequences of random values for specific use cases.
126
+ *
127
+ * Example uses:
128
+ * - Generating random UI data for visual tests.
129
+ * - Creating data that needs to change daily but remain the same throughout a single day, such as using a date as the seed.
130
+ *
131
+ * @param seed - The seed value used to initialize the generator.
132
+ *
133
+ * @example
134
+ * import { Effect, Random } from "effect"
135
+ *
136
+ * const random1 = Random.make("myseed")
137
+ * const random2 = Random.make("myseed")
138
+ *
139
+ * assert.equal(Effect.runSync(random1.next), Effect.runSync(random2.next))
140
+ *
141
+ * @since 3.5.0
142
+ * @category constructors
143
+ */
144
+ export const make: <A>(seed: A) => Random = internal.make
package/src/RcMap.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @since 3.5.0
3
+ */
4
+ import type * as Cause from "./Cause.js"
5
+ import type * as Duration from "./Duration.js"
6
+ import type * as Effect from "./Effect.js"
7
+ import * as internal from "./internal/rcMap.js"
8
+ import { type Pipeable } from "./Pipeable.js"
9
+ import type * as Scope from "./Scope.js"
10
+ import type * as Types from "./Types.js"
11
+
12
+ /**
13
+ * @since 3.5.0
14
+ * @category type ids
15
+ */
16
+ export const TypeId: unique symbol = internal.TypeId
17
+
18
+ /**
19
+ * @since 3.5.0
20
+ * @category type ids
21
+ */
22
+ export type TypeId = typeof TypeId
23
+
24
+ /**
25
+ * @since 3.5.0
26
+ * @category models
27
+ */
28
+ export interface RcMap<in K, out A, out E = never> extends Pipeable {
29
+ readonly [TypeId]: RcMap.Variance<K, A, E>
30
+ }
31
+
32
+ /**
33
+ * @since 3.5.0
34
+ * @category models
35
+ */
36
+ export declare namespace RcMap {
37
+ /**
38
+ * @since 3.5.0
39
+ * @category models
40
+ */
41
+ export interface Variance<K, A, E> {
42
+ readonly _K: Types.Contravariant<K>
43
+ readonly _A: Types.Covariant<A>
44
+ readonly _E: Types.Covariant<E>
45
+ }
46
+ }
47
+
48
+ /**
49
+ * An `RcMap` can contain multiple reference counted resources that can be indexed
50
+ * by a key. The resources are lazily acquired on the first call to `get` and
51
+ * released when the last reference is released.
52
+ *
53
+ * Complex keys can extend `Equal` and `Hash` to allow lookups by value.
54
+ *
55
+ * @since 3.5.0
56
+ * @category models
57
+ * @param capacity The maximum number of resources that can be held in the map.
58
+ * @param idleTimeToLive When the reference count reaches zero, the resource will be released after this duration.
59
+ * @example
60
+ * import { Effect, RcMap } from "effect"
61
+ *
62
+ * Effect.gen(function*() {
63
+ * const map = yield* RcMap.make({
64
+ * lookup: (key: string) =>
65
+ * Effect.acquireRelease(
66
+ * Effect.succeed(`acquired ${key}`),
67
+ * () => Effect.log(`releasing ${key}`)
68
+ * )
69
+ * })
70
+ *
71
+ * // Get "foo" from the map twice, which will only acquire it once.
72
+ * // It will then be released once the scope closes.
73
+ * yield* RcMap.get(map, "foo").pipe(
74
+ * Effect.andThen(RcMap.get(map, "foo")),
75
+ * Effect.scoped
76
+ * )
77
+ * })
78
+ */
79
+ export const make: {
80
+ <K, A, E, R>(
81
+ options: {
82
+ readonly lookup: (key: K) => Effect.Effect<A, E, R>
83
+ readonly idleTimeToLive?: Duration.DurationInput | undefined
84
+ readonly capacity?: undefined
85
+ }
86
+ ): Effect.Effect<RcMap<K, A, E>, never, Scope.Scope | R>
87
+ <K, A, E, R>(
88
+ options: {
89
+ readonly lookup: (key: K) => Effect.Effect<A, E, R>
90
+ readonly idleTimeToLive?: Duration.DurationInput | undefined
91
+ readonly capacity: number
92
+ }
93
+ ): Effect.Effect<RcMap<K, A, E | Cause.ExceededCapacityException>, never, Scope.Scope | R>
94
+ } = internal.make
95
+
96
+ /**
97
+ * @since 3.5.0
98
+ * @category combinators
99
+ */
100
+ export const get: {
101
+ <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<A, E, Scope.Scope>
102
+ <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>
103
+ } = internal.get
package/src/RcRef.ts ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @since 3.5.0
3
+ */
4
+ import type * as Duration from "./Duration.js"
5
+ import type * as Effect from "./Effect.js"
6
+ import * as internal from "./internal/rcRef.js"
7
+ import { type Pipeable } from "./Pipeable.js"
8
+ import type * as Scope from "./Scope.js"
9
+ import type * as Types from "./Types.js"
10
+
11
+ /**
12
+ * @since 3.5.0
13
+ * @category type ids
14
+ */
15
+ export const TypeId: unique symbol = internal.TypeId
16
+
17
+ /**
18
+ * @since 3.5.0
19
+ * @category type ids
20
+ */
21
+ export type TypeId = typeof TypeId
22
+
23
+ /**
24
+ * @since 3.5.0
25
+ * @category models
26
+ */
27
+ export interface RcRef<out A, out E = never> extends Pipeable {
28
+ readonly [TypeId]: RcRef.Variance<A, E>
29
+ }
30
+
31
+ /**
32
+ * @since 3.5.0
33
+ * @category models
34
+ */
35
+ export declare namespace RcRef {
36
+ /**
37
+ * @since 3.5.0
38
+ * @category models
39
+ */
40
+ export interface Variance<A, E> {
41
+ readonly _A: Types.Covariant<A>
42
+ readonly _E: Types.Covariant<E>
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Create an `RcRef` from an acquire `Effect`.
48
+ *
49
+ * An RcRef wraps a reference counted resource that can be acquired and released
50
+ * multiple times.
51
+ *
52
+ * The resource is lazily acquired on the first call to `get` and released when
53
+ * the last reference is released.
54
+ *
55
+ * @since 3.5.0
56
+ * @category constructors
57
+ * @example
58
+ * import { Effect, RcRef } from "effect"
59
+ *
60
+ * Effect.gen(function*() {
61
+ * const ref = yield* RcRef.make({
62
+ * acquire: Effect.acquireRelease(
63
+ * Effect.succeed("foo"),
64
+ * () => Effect.log("release foo")
65
+ * )
66
+ * })
67
+ *
68
+ * // will only acquire the resource once, and release it
69
+ * // when the scope is closed
70
+ * yield* RcRef.get(ref).pipe(
71
+ * Effect.andThen(RcRef.get(ref)),
72
+ * Effect.scoped
73
+ * )
74
+ * })
75
+ */
76
+ export const make: <A, E, R>(
77
+ options: {
78
+ readonly acquire: Effect.Effect<A, E, R>
79
+ /**
80
+ * When the reference count reaches zero, the resource will be released
81
+ * after this duration.
82
+ */
83
+ readonly idleTimeToLive?: Duration.DurationInput | undefined
84
+ }
85
+ ) => Effect.Effect<RcRef<A, E>, never, R | Scope.Scope> = internal.make
86
+
87
+ /**
88
+ * @since 3.5.0
89
+ * @category combinators
90
+ */
91
+ export const get: <A, E>(self: RcRef<A, E>) => Effect.Effect<A, E, Scope.Scope> = internal.get
package/src/Stream.ts CHANGED
@@ -30,7 +30,7 @@ import type * as Emit from "./StreamEmit.js"
30
30
  import type * as HaltStrategy from "./StreamHaltStrategy.js"
31
31
  import type * as Take from "./Take.js"
32
32
  import type * as Tracer from "./Tracer.js"
33
- import type { Covariant, NoInfer } from "./Types.js"
33
+ import type { Covariant, NoInfer, TupleOf } from "./Types.js"
34
34
  import type * as Unify from "./Unify.js"
35
35
 
36
36
  /**
@@ -146,6 +146,7 @@ export declare namespace Stream {
146
146
  /**
147
147
  * @since 2.0.0
148
148
  * @category models
149
+ * @deprecated use Types.TupleOf instead
149
150
  */
150
151
  export type DynamicTuple<T, N extends number> = N extends N ? number extends N ? Array<T> : DynamicTupleOf<T, N, []>
151
152
  : never
@@ -153,6 +154,7 @@ export declare namespace Stream {
153
154
  /**
154
155
  * @since 2.0.0
155
156
  * @category models
157
+ * @deprecated use Types.TupleOf instead
156
158
  */
157
159
  export type DynamicTupleOf<T, N extends number, R extends Array<unknown>> = R["length"] extends N ? R
158
160
  : DynamicTupleOf<T, N, [T, ...R]>
@@ -310,7 +312,10 @@ export const as: {
310
312
 
311
313
  const _async: <A, E = never, R = never>(
312
314
  register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<void, never, R> | void,
313
- outputBuffer?: number
315
+ bufferSize?: number | "unbounded" | {
316
+ readonly bufferSize?: number | undefined
317
+ readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
318
+ } | undefined
314
319
  ) => Stream<A, E, R> = internal._async
315
320
 
316
321
  export {
@@ -362,7 +367,10 @@ export {
362
367
  */
363
368
  export const asyncEffect: <A, E = never, R = never>(
364
369
  register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<unknown, E, R>,
365
- outputBuffer?: number
370
+ bufferSize?: number | "unbounded" | {
371
+ readonly bufferSize?: number | undefined
372
+ readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
373
+ } | undefined
366
374
  ) => Stream<A, E, R> = internal.asyncEffect
367
375
 
368
376
  /**
@@ -376,7 +384,10 @@ export const asyncEffect: <A, E = never, R = never>(
376
384
  */
377
385
  export const asyncScoped: <A, E = never, R = never>(
378
386
  register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<unknown, E, R | Scope.Scope>,
379
- outputBuffer?: number
387
+ bufferSize?: number | "unbounded" | {
388
+ readonly bufferSize?: number | undefined
389
+ readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
390
+ } | undefined
380
391
  ) => Stream<A, E, Exclude<R, Scope.Scope>> = internal.asyncScoped
381
392
 
382
393
  /**
@@ -484,12 +495,12 @@ export const broadcast: {
484
495
  maximumLag: number
485
496
  ): <A, E, R>(
486
497
  self: Stream<A, E, R>
487
- ) => Effect.Effect<Stream.DynamicTuple<Stream<A, E>, N>, never, Scope.Scope | R>
498
+ ) => Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
488
499
  <A, E, R, N extends number>(
489
500
  self: Stream<A, E, R>,
490
501
  n: N,
491
502
  maximumLag: number
492
- ): Effect.Effect<Stream.DynamicTuple<Stream<A, E>, N>, never, Scope.Scope | R>
503
+ ): Effect.Effect<TupleOf<N, Stream<A, E>>, never, Scope.Scope | R>
493
504
  } = internal.broadcast
494
505
 
495
506
  /**
@@ -521,12 +532,12 @@ export const broadcastedQueues: {
521
532
  maximumLag: number
522
533
  ): <A, E, R>(
523
534
  self: Stream<A, E, R>
524
- ) => Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<A, E>>, N>, never, R | Scope.Scope>
535
+ ) => Effect.Effect<TupleOf<N, Queue.Dequeue<Take.Take<A, E>>>, never, R | Scope.Scope>
525
536
  <A, E, R, N extends number>(
526
537
  self: Stream<A, E, R>,
527
538
  n: N,
528
539
  maximumLag: number
529
- ): Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Take.Take<A, E>>, N>, never, Scope.Scope | R>
540
+ ): Effect.Effect<TupleOf<N, Queue.Dequeue<Take.Take<A, E>>>, never, Scope.Scope | R>
530
541
  } = internal.broadcastedQueues
531
542
 
532
543
  /**
@@ -1139,7 +1150,7 @@ export const distributedWith: {
1139
1150
  }
1140
1151
  ): <E, R>(
1141
1152
  self: Stream<A, E, R>
1142
- ) => Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>, N>, never, Scope.Scope | R>
1153
+ ) => Effect.Effect<TupleOf<N, Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>>, never, Scope.Scope | R>
1143
1154
  <A, E, R, N extends number>(
1144
1155
  self: Stream<A, E, R>,
1145
1156
  options: {
@@ -1147,7 +1158,7 @@ export const distributedWith: {
1147
1158
  readonly maximumLag: number
1148
1159
  readonly decide: (a: A) => Effect.Effect<Predicate<number>>
1149
1160
  }
1150
- ): Effect.Effect<Stream.DynamicTuple<Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>, N>, never, Scope.Scope | R>
1161
+ ): Effect.Effect<TupleOf<N, Queue.Dequeue<Exit.Exit<A, Option.Option<E>>>>, never, Scope.Scope | R>
1151
1162
  } = internal.distributedWith
1152
1163
 
1153
1164
  /**
@@ -2843,8 +2854,8 @@ export const mergeEither: {
2843
2854
  * @category utils
2844
2855
  */
2845
2856
  export const mergeLeft: {
2846
- <A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | R>
2847
- <A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A, E | E2, R | R2>
2857
+ <AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AL, ER | EL, RR | RL>
2858
+ <AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AL, EL | ER, RL | RR>
2848
2859
  } = internal.mergeLeft
2849
2860
 
2850
2861
  /**
@@ -2855,8 +2866,8 @@ export const mergeLeft: {
2855
2866
  * @category utils
2856
2867
  */
2857
2868
  export const mergeRight: {
2858
- <A2, E2, R2>(that: Stream<A2, E2, R2>): <A, E, R>(self: Stream<A, E, R>) => Stream<A2, E2 | E, R2 | R>
2859
- <A, E, R, A2, E2, R2>(self: Stream<A, E, R>, that: Stream<A2, E2, R2>): Stream<A2, E | E2, R | R2>
2869
+ <AR, ER, RR>(right: Stream<AR, ER, RR>): <AL, EL, RL>(left: Stream<AL, EL, RL>) => Stream<AR, ER | EL, RR | RL>
2870
+ <AL, EL, RL, AR, ER, RR>(left: Stream<AL, EL, RL>, right: Stream<AR, ER, RR>): Stream<AR, EL | ER, RL | RR>
2860
2871
  } = internal.mergeRight
2861
2872
 
2862
2873
  /**
@@ -3357,6 +3368,40 @@ export const provideSomeLayer: {
3357
3368
  ): Stream<A, E | E2, RIn | Exclude<R, ROut>>
3358
3369
  } = internal.provideSomeLayer
3359
3370
 
3371
+ /**
3372
+ * Returns a stream that mirrors the first upstream to emit an item.
3373
+ * As soon as one of the upstream emits a first value, all the others are interrupted.
3374
+ * The resulting stream will forward all items from the "winning" source stream.
3375
+ * Any upstream failures will cause the returned stream to fail.
3376
+ *
3377
+ * @example
3378
+ * import { Stream, Schedule, Console, Effect } from "effect"
3379
+ *
3380
+ * const stream = Stream.raceAll(
3381
+ * Stream.fromSchedule(Schedule.spaced('1 millis')),
3382
+ * Stream.fromSchedule(Schedule.spaced('2 millis')),
3383
+ * Stream.fromSchedule(Schedule.spaced('4 millis')),
3384
+ * ).pipe(Stream.take(6), Stream.tap(Console.log))
3385
+ *
3386
+ * Effect.runPromise(Stream.runDrain(stream))
3387
+ * // Output each millisecond from the first stream, the rest streams are interrupted
3388
+ * // 0
3389
+ * // 1
3390
+ * // 2
3391
+ * // 3
3392
+ * // 4
3393
+ * // 5
3394
+ * @since 3.5.0
3395
+ * @category racing
3396
+ */
3397
+ export const raceAll: <S extends ReadonlyArray<Stream<any, any, any>>>(
3398
+ ...streams: S
3399
+ ) => Stream<
3400
+ Stream.Success<S[number]>,
3401
+ Stream.Error<S[number]>,
3402
+ Stream.Context<S[number]>
3403
+ > = internal.raceAll
3404
+
3360
3405
  /**
3361
3406
  * Constructs a stream from a range of integers, including both endpoints.
3362
3407
  *
@@ -3638,7 +3683,7 @@ export const run: {
3638
3683
  <A, E, R, A2, E2, R2>(
3639
3684
  self: Stream<A, E, R>,
3640
3685
  sink: Sink.Sink<A2, A, unknown, E2, R2>
3641
- ): Effect.Effect<A2, E | E2, R | R2>
3686
+ ): Effect.Effect<A2, E | E2, Exclude<R | R2, Scope.Scope>>
3642
3687
  } = internal.run
3643
3688
 
3644
3689
  /**
@@ -3647,7 +3692,8 @@ export const run: {
3647
3692
  * @since 2.0.0
3648
3693
  * @category destructors
3649
3694
  */
3650
- export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, R> = internal.runCollect
3695
+ export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk.Chunk<A>, E, Exclude<R, Scope.Scope>> =
3696
+ internal.runCollect
3651
3697
 
3652
3698
  /**
3653
3699
  * Runs the stream and emits the number of elements processed
@@ -3655,7 +3701,8 @@ export const runCollect: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<Chunk
3655
3701
  * @since 2.0.0
3656
3702
  * @category destructors
3657
3703
  */
3658
- export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number, E, R> = internal.runCount
3704
+ export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number, E, Exclude<R, Scope.Scope>> =
3705
+ internal.runCount
3659
3706
 
3660
3707
  /**
3661
3708
  * Runs the stream only for its effects. The emitted elements are discarded.
@@ -3663,7 +3710,8 @@ export const runCount: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<number,
3663
3710
  * @since 2.0.0
3664
3711
  * @category destructors
3665
3712
  */
3666
- export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, R> = internal.runDrain
3713
+ export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E, Exclude<R, Scope.Scope>> =
3714
+ internal.runDrain
3667
3715
 
3668
3716
  /**
3669
3717
  * Executes a pure fold over the stream of values - reduces all elements in
@@ -3673,8 +3721,8 @@ export const runDrain: <A, E, R>(self: Stream<A, E, R>) => Effect.Effect<void, E
3673
3721
  * @category destructors
3674
3722
  */
3675
3723
  export const runFold: {
3676
- <S, A>(s: S, f: (s: S, a: A) => S): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, R>
3677
- <A, E, R, S>(self: Stream<A, E, R>, s: S, f: (s: S, a: A) => S): Effect.Effect<S, E, R>
3724
+ <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>>
3725
+ <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>>
3678
3726
  } = internal.runFold
3679
3727
 
3680
3728
  /**
@@ -3687,12 +3735,12 @@ export const runFoldEffect: {
3687
3735
  <S, A, E2, R2>(
3688
3736
  s: S,
3689
3737
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3690
- ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, R2 | R>
3738
+ ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, Exclude<R | R2, Scope.Scope>>
3691
3739
  <A, E, R, S, E2, R2>(
3692
3740
  self: Stream<A, E, R>,
3693
3741
  s: S,
3694
3742
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3695
- ): Effect.Effect<S, E | E2, R | R2>
3743
+ ): Effect.Effect<S, E | E2, Exclude<R | R2, Scope.Scope>>
3696
3744
  } = internal.runFoldEffect
3697
3745
 
3698
3746
  /**
@@ -3734,8 +3782,17 @@ export const runFoldScopedEffect: {
3734
3782
  * @category destructors
3735
3783
  */
3736
3784
  export const runFoldWhile: {
3737
- <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>
3738
- <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>
3785
+ <S, A>(
3786
+ s: S,
3787
+ cont: Predicate<S>,
3788
+ f: (s: S, a: A) => S
3789
+ ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E, Exclude<R, Scope.Scope>>
3790
+ <A, E, R, S>(
3791
+ self: Stream<A, E, R>,
3792
+ s: S,
3793
+ cont: Predicate<S>,
3794
+ f: (s: S, a: A) => S
3795
+ ): Effect.Effect<S, E, Exclude<R, Scope.Scope>>
3739
3796
  } = internal.runFoldWhile
3740
3797
 
3741
3798
  /**
@@ -3750,13 +3807,13 @@ export const runFoldWhileEffect: {
3750
3807
  s: S,
3751
3808
  cont: Predicate<S>,
3752
3809
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3753
- ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, R2 | R>
3810
+ ): <E, R>(self: Stream<A, E, R>) => Effect.Effect<S, E2 | E, Exclude<R | R2, Scope.Scope>>
3754
3811
  <A, E, R, S, E2, R2>(
3755
3812
  self: Stream<A, E, R>,
3756
3813
  s: S,
3757
3814
  cont: Predicate<S>,
3758
3815
  f: (s: S, a: A) => Effect.Effect<S, E2, R2>
3759
- ): Effect.Effect<S, E | E2, R | R2>
3816
+ ): Effect.Effect<S, E | E2, Exclude<R | R2, Scope.Scope>>
3760
3817
  } = internal.runFoldWhileEffect
3761
3818
 
3762
3819
  /**
package/src/index.ts CHANGED
@@ -605,6 +605,16 @@ export * as Random from "./Random.js"
605
605
  */
606
606
  export * as RateLimiter from "./RateLimiter.js"
607
607
 
608
+ /**
609
+ * @since 3.5.0
610
+ */
611
+ export * as RcMap from "./RcMap.js"
612
+
613
+ /**
614
+ * @since 3.5.0
615
+ */
616
+ export * as RcRef from "./RcRef.js"
617
+
608
618
  /**
609
619
  * @since 2.0.0
610
620
  */
@@ -970,25 +970,46 @@ export const reduceWithContext = dual<
970
970
  // -----------------------------------------------------------------------------
971
971
 
972
972
  /** @internal */
973
- export const pretty = <E>(cause: Cause.Cause<E>): string => {
973
+ export const pretty = <E>(cause: Cause.Cause<E>, options?: {
974
+ readonly renderErrorCause?: boolean | undefined
975
+ }): string => {
974
976
  if (isInterruptedOnly(cause)) {
975
977
  return "All fibers interrupted without errors."
976
978
  }
977
- return prettyErrors<E>(cause).map((e) => e.stack).join("\n")
979
+ return prettyErrors<E>(cause).map(function(e) {
980
+ if (options?.renderErrorCause !== true || e.cause === undefined) {
981
+ return e.stack
982
+ }
983
+ return `${e.stack} {\n${renderErrorCause(e.cause as PrettyError, " ")}\n}`
984
+ }).join("\n")
985
+ }
986
+
987
+ const renderErrorCause = (cause: PrettyError, prefix: string) => {
988
+ const lines = cause.stack!.split("\n")
989
+ let stack = `${prefix}[cause]: ${lines[0]}`
990
+ for (let i = 1, len = lines.length; i < len; i++) {
991
+ stack += `\n${prefix}${lines[i]}`
992
+ }
993
+ return stack
978
994
  }
979
995
 
980
996
  class PrettyError extends globalThis.Error implements Cause.PrettyError {
981
997
  span: undefined | Span = undefined
982
998
  constructor(originalError: unknown) {
999
+ const originalErrorIsObject = typeof originalError === "object" && originalError !== null
983
1000
  const prevLimit = Error.stackTraceLimit
984
- Error.stackTraceLimit = 0
985
- super(prettyErrorMessage(originalError))
1001
+ Error.stackTraceLimit = 1
1002
+ super(prettyErrorMessage(originalError), {
1003
+ cause: originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined"
1004
+ ? new PrettyError(originalError.cause)
1005
+ : undefined
1006
+ })
986
1007
  if (this.message === "") {
987
1008
  this.message = "An error has occurred"
988
1009
  }
989
1010
  Error.stackTraceLimit = prevLimit
990
1011
  this.name = originalError instanceof Error ? originalError.name : "Error"
991
- if (typeof originalError === "object" && originalError !== null) {
1012
+ if (originalErrorIsObject) {
992
1013
  if (spanSymbol in originalError) {
993
1014
  this.span = originalError[spanSymbol] as Span
994
1015
  }
@@ -1095,7 +1095,7 @@ export const readUpstream = <A, E2, R, E>(
1095
1095
  /** @internal */
1096
1096
  export const run = <Env, InErr, InDone, OutErr, OutDone>(
1097
1097
  self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
1098
- ): Effect.Effect<OutDone, OutErr, Env> => pipe(runScoped(self), Effect.scoped)
1098
+ ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => pipe(runScoped(self), Effect.scoped)
1099
1099
 
1100
1100
  /** @internal */
1101
1101
  export const runScoped = <Env, InErr, InDone, OutErr, OutDone>(
@@ -2052,17 +2052,18 @@ export const repeated = <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2052
2052
  /** @internal */
2053
2053
  export const run = <OutErr, InErr, OutDone, InDone, Env>(
2054
2054
  self: Channel.Channel<never, unknown, OutErr, InErr, OutDone, InDone, Env>
2055
- ): Effect.Effect<OutDone, OutErr, Env> => Effect.scoped(executor.runScoped(self))
2055
+ ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => Effect.scoped(executor.runScoped(self))
2056
2056
 
2057
2057
  /** @internal */
2058
2058
  export const runCollect = <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2059
2059
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
2060
- ): Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Env> => executor.run(core.collectElements(self))
2060
+ ): Effect.Effect<[Chunk.Chunk<OutElem>, OutDone], OutErr, Exclude<Env, Scope.Scope>> =>
2061
+ executor.run(core.collectElements(self))
2061
2062
 
2062
2063
  /** @internal */
2063
2064
  export const runDrain = <OutElem, OutErr, InErr, OutDone, InDone, Env>(
2064
2065
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, Env>
2065
- ): Effect.Effect<OutDone, OutErr, Env> => executor.run(drain(self))
2066
+ ): Effect.Effect<OutDone, OutErr, Exclude<Env, Scope.Scope>> => executor.run(drain(self))
2066
2067
 
2067
2068
  /** @internal */
2068
2069
  export const scoped = <A, E, R>(
@@ -911,11 +911,6 @@ export const logWithLevel = (level?: LogLevel.LogLevel) =>
911
911
  i--
912
912
  }
913
913
  }
914
- if (message.length === 0) {
915
- message = "" as any
916
- } else if (message.length === 1) {
917
- message = message[0]
918
- }
919
914
  if (cause === undefined) {
920
915
  cause = internalCause.empty
921
916
  }