effect 3.12.11 → 3.13.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 (204) hide show
  1. package/README.md +38 -49
  2. package/dist/cjs/Channel.js.map +1 -1
  3. package/dist/cjs/DateTime.js +17 -1
  4. package/dist/cjs/DateTime.js.map +1 -1
  5. package/dist/cjs/Differ.js.map +1 -1
  6. package/dist/cjs/Duration.js +128 -1
  7. package/dist/cjs/Duration.js.map +1 -1
  8. package/dist/cjs/Effect.js +175 -37
  9. package/dist/cjs/Effect.js.map +1 -1
  10. package/dist/cjs/Either.js +2 -1
  11. package/dist/cjs/Either.js.map +1 -1
  12. package/dist/cjs/FiberHandle.js +54 -21
  13. package/dist/cjs/FiberHandle.js.map +1 -1
  14. package/dist/cjs/FiberMap.js +51 -24
  15. package/dist/cjs/FiberMap.js.map +1 -1
  16. package/dist/cjs/FiberSet.js +50 -17
  17. package/dist/cjs/FiberSet.js.map +1 -1
  18. package/dist/cjs/HashMap.js +19 -1
  19. package/dist/cjs/HashMap.js.map +1 -1
  20. package/dist/cjs/HashSet.js +9 -1
  21. package/dist/cjs/HashSet.js.map +1 -1
  22. package/dist/cjs/Layer.js +21 -1
  23. package/dist/cjs/Layer.js.map +1 -1
  24. package/dist/cjs/Match.js +659 -38
  25. package/dist/cjs/Match.js.map +1 -1
  26. package/dist/cjs/RcMap.js +11 -1
  27. package/dist/cjs/RcMap.js.map +1 -1
  28. package/dist/cjs/Reloadable.js.map +1 -1
  29. package/dist/cjs/STM.js.map +1 -1
  30. package/dist/cjs/Schedule.js +1074 -309
  31. package/dist/cjs/Schedule.js.map +1 -1
  32. package/dist/cjs/Schema.js +73 -1
  33. package/dist/cjs/Schema.js.map +1 -1
  34. package/dist/cjs/Stream.js.map +1 -1
  35. package/dist/cjs/internal/channel.js.map +1 -1
  36. package/dist/cjs/internal/core-effect.js.map +1 -1
  37. package/dist/cjs/internal/core.js +27 -3
  38. package/dist/cjs/internal/core.js.map +1 -1
  39. package/dist/cjs/internal/dateTime.js +4 -1
  40. package/dist/cjs/internal/dateTime.js.map +1 -1
  41. package/dist/cjs/internal/differ.js +4 -0
  42. package/dist/cjs/internal/differ.js.map +1 -1
  43. package/dist/cjs/internal/effect/circular.js +3 -2
  44. package/dist/cjs/internal/effect/circular.js.map +1 -1
  45. package/dist/cjs/internal/fiberRuntime.js +21 -7
  46. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  47. package/dist/cjs/internal/hashMap.js +10 -1
  48. package/dist/cjs/internal/hashMap.js.map +1 -1
  49. package/dist/cjs/internal/keyedPool.js +1 -1
  50. package/dist/cjs/internal/keyedPool.js.map +1 -1
  51. package/dist/cjs/internal/layer.js.map +1 -1
  52. package/dist/cjs/internal/rcMap.js +86 -56
  53. package/dist/cjs/internal/rcMap.js.map +1 -1
  54. package/dist/cjs/internal/reloadable.js.map +1 -1
  55. package/dist/cjs/internal/schedule.js.map +1 -1
  56. package/dist/cjs/internal/sink.js.map +1 -1
  57. package/dist/cjs/internal/stm/stm.js.map +1 -1
  58. package/dist/cjs/internal/stream.js.map +1 -1
  59. package/dist/cjs/internal/version.js +1 -1
  60. package/dist/cjs/internal/version.js.map +1 -1
  61. package/dist/dts/Channel.d.ts +4 -4
  62. package/dist/dts/Channel.d.ts.map +1 -1
  63. package/dist/dts/DateTime.d.ts +16 -0
  64. package/dist/dts/DateTime.d.ts.map +1 -1
  65. package/dist/dts/Differ.d.ts +2 -1
  66. package/dist/dts/Differ.d.ts.map +1 -1
  67. package/dist/dts/Duration.d.ts +64 -0
  68. package/dist/dts/Duration.d.ts.map +1 -1
  69. package/dist/dts/Effect.d.ts +402 -30
  70. package/dist/dts/Effect.d.ts.map +1 -1
  71. package/dist/dts/Either.d.ts +7 -0
  72. package/dist/dts/Either.d.ts.map +1 -1
  73. package/dist/dts/FiberHandle.d.ts +26 -0
  74. package/dist/dts/FiberHandle.d.ts.map +1 -1
  75. package/dist/dts/FiberMap.d.ts +26 -0
  76. package/dist/dts/FiberMap.d.ts.map +1 -1
  77. package/dist/dts/FiberSet.d.ts +25 -0
  78. package/dist/dts/FiberSet.d.ts.map +1 -1
  79. package/dist/dts/HashMap.d.ts +38 -0
  80. package/dist/dts/HashMap.d.ts.map +1 -1
  81. package/dist/dts/HashSet.d.ts +7 -0
  82. package/dist/dts/HashSet.d.ts.map +1 -1
  83. package/dist/dts/Layer.d.ts +32 -13
  84. package/dist/dts/Layer.d.ts.map +1 -1
  85. package/dist/dts/Match.d.ts +731 -48
  86. package/dist/dts/Match.d.ts.map +1 -1
  87. package/dist/dts/RcMap.d.ts +32 -0
  88. package/dist/dts/RcMap.d.ts.map +1 -1
  89. package/dist/dts/Reloadable.d.ts +13 -13
  90. package/dist/dts/Reloadable.d.ts.map +1 -1
  91. package/dist/dts/STM.d.ts +4 -4
  92. package/dist/dts/STM.d.ts.map +1 -1
  93. package/dist/dts/Schedule.d.ts +2294 -633
  94. package/dist/dts/Schedule.d.ts.map +1 -1
  95. package/dist/dts/Schema.d.ts +40 -4
  96. package/dist/dts/Schema.d.ts.map +1 -1
  97. package/dist/dts/Stream.d.ts +8 -8
  98. package/dist/dts/Stream.d.ts.map +1 -1
  99. package/dist/dts/Trie.d.ts +7 -7
  100. package/dist/dts/Trie.d.ts.map +1 -1
  101. package/dist/dts/index.d.ts +25 -0
  102. package/dist/dts/index.d.ts.map +1 -1
  103. package/dist/dts/internal/stm/stm.d.ts +2 -2
  104. package/dist/dts/internal/stm/stm.d.ts.map +1 -1
  105. package/dist/esm/Channel.js.map +1 -1
  106. package/dist/esm/DateTime.js +16 -0
  107. package/dist/esm/DateTime.js.map +1 -1
  108. package/dist/esm/Differ.js.map +1 -1
  109. package/dist/esm/Duration.js +124 -0
  110. package/dist/esm/Duration.js.map +1 -1
  111. package/dist/esm/Effect.js +170 -32
  112. package/dist/esm/Effect.js.map +1 -1
  113. package/dist/esm/Either.js +7 -0
  114. package/dist/esm/Either.js.map +1 -1
  115. package/dist/esm/FiberHandle.js +48 -18
  116. package/dist/esm/FiberHandle.js.map +1 -1
  117. package/dist/esm/FiberMap.js +46 -22
  118. package/dist/esm/FiberMap.js.map +1 -1
  119. package/dist/esm/FiberSet.js +45 -15
  120. package/dist/esm/FiberSet.js.map +1 -1
  121. package/dist/esm/HashMap.js +17 -0
  122. package/dist/esm/HashMap.js.map +1 -1
  123. package/dist/esm/HashSet.js +7 -0
  124. package/dist/esm/HashSet.js.map +1 -1
  125. package/dist/esm/Layer.js +20 -0
  126. package/dist/esm/Layer.js.map +1 -1
  127. package/dist/esm/Match.js +665 -40
  128. package/dist/esm/Match.js.map +1 -1
  129. package/dist/esm/RcMap.js +10 -0
  130. package/dist/esm/RcMap.js.map +1 -1
  131. package/dist/esm/Reloadable.js.map +1 -1
  132. package/dist/esm/STM.js.map +1 -1
  133. package/dist/esm/Schedule.js +1074 -309
  134. package/dist/esm/Schedule.js.map +1 -1
  135. package/dist/esm/Schema.js +71 -0
  136. package/dist/esm/Schema.js.map +1 -1
  137. package/dist/esm/Stream.js.map +1 -1
  138. package/dist/esm/index.js +25 -0
  139. package/dist/esm/index.js.map +1 -1
  140. package/dist/esm/internal/channel.js.map +1 -1
  141. package/dist/esm/internal/core-effect.js.map +1 -1
  142. package/dist/esm/internal/core.js +23 -0
  143. package/dist/esm/internal/core.js.map +1 -1
  144. package/dist/esm/internal/dateTime.js +2 -0
  145. package/dist/esm/internal/dateTime.js.map +1 -1
  146. package/dist/esm/internal/differ.js +4 -0
  147. package/dist/esm/internal/differ.js.map +1 -1
  148. package/dist/esm/internal/effect/circular.js +3 -2
  149. package/dist/esm/internal/effect/circular.js.map +1 -1
  150. package/dist/esm/internal/fiberRuntime.js +18 -5
  151. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  152. package/dist/esm/internal/hashMap.js +9 -0
  153. package/dist/esm/internal/hashMap.js.map +1 -1
  154. package/dist/esm/internal/keyedPool.js +1 -1
  155. package/dist/esm/internal/keyedPool.js.map +1 -1
  156. package/dist/esm/internal/layer.js.map +1 -1
  157. package/dist/esm/internal/rcMap.js +85 -55
  158. package/dist/esm/internal/rcMap.js.map +1 -1
  159. package/dist/esm/internal/reloadable.js.map +1 -1
  160. package/dist/esm/internal/schedule.js.map +1 -1
  161. package/dist/esm/internal/sink.js.map +1 -1
  162. package/dist/esm/internal/stm/stm.js.map +1 -1
  163. package/dist/esm/internal/stream.js.map +1 -1
  164. package/dist/esm/internal/version.js +1 -1
  165. package/dist/esm/internal/version.js.map +1 -1
  166. package/package.json +2 -1
  167. package/src/Channel.ts +14 -17
  168. package/src/DateTime.ts +17 -8
  169. package/src/Differ.ts +2 -1
  170. package/src/Duration.ts +147 -0
  171. package/src/Effect.ts +528 -140
  172. package/src/Either.ts +9 -0
  173. package/src/FiberHandle.ts +95 -35
  174. package/src/FiberMap.ts +104 -39
  175. package/src/FiberSet.ts +93 -24
  176. package/src/HashMap.ts +40 -0
  177. package/src/HashSet.ts +8 -0
  178. package/src/Layer.ts +94 -40
  179. package/src/Match.ts +733 -49
  180. package/src/RcMap.ts +34 -0
  181. package/src/Reloadable.ts +17 -27
  182. package/src/STM.ts +10 -17
  183. package/src/Schedule.ts +2325 -653
  184. package/src/Schema.ts +81 -4
  185. package/src/Stream.ts +26 -33
  186. package/src/Trie.ts +7 -7
  187. package/src/index.ts +25 -0
  188. package/src/internal/channel.ts +37 -39
  189. package/src/internal/core-effect.ts +84 -84
  190. package/src/internal/core.ts +80 -0
  191. package/src/internal/dateTime.ts +3 -0
  192. package/src/internal/differ.ts +4 -0
  193. package/src/internal/effect/circular.ts +3 -2
  194. package/src/internal/fiberRuntime.ts +31 -6
  195. package/src/internal/hashMap.ts +16 -0
  196. package/src/internal/keyedPool.ts +1 -1
  197. package/src/internal/layer.ts +52 -52
  198. package/src/internal/rcMap.ts +131 -89
  199. package/src/internal/reloadable.ts +25 -28
  200. package/src/internal/schedule.ts +29 -23
  201. package/src/internal/sink.ts +16 -15
  202. package/src/internal/stm/stm.ts +54 -46
  203. package/src/internal/stream.ts +100 -100
  204. package/src/internal/version.ts +1 -1
package/src/Schema.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  * @since 3.10.0
3
3
  */
4
4
 
5
+ import type { StandardSchemaV1 } from "@standard-schema/spec"
5
6
  import type { ArbitraryAnnotation, ArbitraryGenerationContext, LazyArbitrary } from "./Arbitrary.js"
6
7
  import * as array_ from "./Array.js"
7
8
  import * as bigDecimal_ from "./BigDecimal.js"
@@ -44,6 +45,7 @@ import type * as pretty_ from "./Pretty.js"
44
45
  import * as record_ from "./Record.js"
45
46
  import * as redacted_ from "./Redacted.js"
46
47
  import * as Request from "./Request.js"
48
+ import * as scheduler_ from "./Scheduler.js"
47
49
  import type { ParseOptions } from "./SchemaAST.js"
48
50
  import * as AST from "./SchemaAST.js"
49
51
  import * as sortedSet_ from "./SortedSet.js"
@@ -128,6 +130,81 @@ const variance = {
128
130
  _R: (_: never) => _
129
131
  }
130
132
 
133
+ const makeStandardResult = <A>(exit: exit_.Exit<StandardSchemaV1.Result<A>>): StandardSchemaV1.Result<A> =>
134
+ exit_.isSuccess(exit) ? exit.value : makeStandardFailureResult(cause_.pretty(exit.cause))
135
+
136
+ const makeStandardFailureResult = (message: string): StandardSchemaV1.FailureResult => ({
137
+ issues: [{ message }]
138
+ })
139
+
140
+ const makeStandardFailureFromParseIssue = (
141
+ issue: ParseResult.ParseIssue
142
+ ): Effect.Effect<StandardSchemaV1.FailureResult> =>
143
+ Effect.map(ParseResult.ArrayFormatter.formatIssue(issue), (issues) => ({
144
+ issues: issues.map((issue) => ({
145
+ path: issue.path,
146
+ message: issue.message
147
+ }))
148
+ }))
149
+
150
+ /**
151
+ * Returns a "Standard Schema" object conforming to the [Standard Schema
152
+ * v1](https://standardschema.dev/) specification.
153
+ *
154
+ * This function creates a schema whose `validate` method attempts to decode and
155
+ * validate the provided input synchronously. If the underlying `Schema`
156
+ * includes any asynchronous components (e.g., asynchronous message resolutions
157
+ * or checks), then validation will necessarily return a `Promise` instead.
158
+ *
159
+ * Any detected defects will be reported via a single issue containing no
160
+ * `path`.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * import { Schema } from "effect"
165
+ *
166
+ * const schema = Schema.Struct({
167
+ * name: Schema.String
168
+ * })
169
+ *
170
+ * // ┌─── StandardSchemaV1<{ readonly name: string; }>
171
+ * // ▼
172
+ * const standardSchema = Schema.standardSchemaV1(schema)
173
+ * ```
174
+ *
175
+ * @category Standard Schema
176
+ * @since 3.13.0
177
+ */
178
+ export const standardSchemaV1 = <A, I>(schema: Schema<A, I, never>): StandardSchemaV1<I, A> => {
179
+ const decodeUnknown = ParseResult.decodeUnknown(schema)
180
+ return {
181
+ "~standard": {
182
+ version: 1,
183
+ vendor: "effect",
184
+ validate(value) {
185
+ const scheduler = new scheduler_.SyncScheduler()
186
+ const fiber = Effect.runFork(
187
+ Effect.matchEffect(decodeUnknown(value), {
188
+ onFailure: makeStandardFailureFromParseIssue,
189
+ onSuccess: (value) => Effect.succeed({ value })
190
+ }),
191
+ { scheduler }
192
+ )
193
+ scheduler.flush()
194
+ const exit = fiber.unsafePoll()
195
+ if (exit) {
196
+ return makeStandardResult(exit)
197
+ }
198
+ return new Promise((resolve) => {
199
+ fiber.addObserver((exit) => {
200
+ resolve(makeStandardResult(exit))
201
+ })
202
+ })
203
+ }
204
+ }
205
+ }
206
+ }
207
+
131
208
  interface AllAnnotations<A, TypeParameters extends ReadonlyArray<any>>
132
209
  extends Annotations.Schema<A, TypeParameters>, PropertySignature.Annotations<A>
133
210
  {}
@@ -8677,7 +8754,7 @@ type ClassAnnotations<Self, A> =
8677
8754
  | Annotations.Schema<Self>
8678
8755
  | readonly [
8679
8756
  Annotations.Schema<Self> | undefined,
8680
- Annotations.Schema<Self>?,
8757
+ (Annotations.Schema<Self> | undefined)?,
8681
8758
  Annotations.Schema<A>?
8682
8759
  ]
8683
8760
 
@@ -8956,7 +9033,7 @@ export const TaggedClass = <Self = never>(identifier?: string) =>
8956
9033
  <Tag extends string, Fields extends Struct.Fields>(
8957
9034
  tag: Tag,
8958
9035
  fieldsOr: Fields | HasFields<Fields>,
8959
- annotations?: ClassAnnotations<Self, Struct.Type<Fields>>
9036
+ annotations?: ClassAnnotations<Self, Struct.Type<{ readonly _tag: tag<Tag> } & Fields>>
8960
9037
  ): [Self] extends [never] ? MissingSelfGeneric<"TaggedClass", `"Tag", `>
8961
9038
  : TaggedClass<Self, Tag, { readonly _tag: tag<Tag> } & Fields> =>
8962
9039
  {
@@ -9019,7 +9096,7 @@ export const TaggedError = <Self = never>(identifier?: string) =>
9019
9096
  <Tag extends string, Fields extends Struct.Fields>(
9020
9097
  tag: Tag,
9021
9098
  fieldsOr: Fields | HasFields<Fields>,
9022
- annotations?: ClassAnnotations<Self, Struct.Type<Fields>>
9099
+ annotations?: ClassAnnotations<Self, Struct.Type<{ readonly _tag: tag<Tag> } & Fields>>
9023
9100
  ): [Self] extends [never] ? MissingSelfGeneric<"TaggedError", `"Tag", `>
9024
9101
  : TaggedErrorClass<
9025
9102
  Self,
@@ -10825,7 +10902,7 @@ export const TaggedRequest =
10825
10902
  success: Success
10826
10903
  payload: Payload
10827
10904
  },
10828
- annotations?: Annotations.Schema<Self>
10905
+ annotations?: ClassAnnotations<Self, Struct.Type<{ readonly _tag: tag<Tag> } & Payload>>
10829
10906
  ): [Self] extends [never] ? MissingSelfGeneric<"TaggedRequest", `"Tag", SuccessSchema, FailureSchema, `>
10830
10907
  : TaggedRequestClass<
10831
10908
  Self,
package/src/Stream.ts CHANGED
@@ -6743,10 +6743,7 @@ export const provideService: {
6743
6743
  * @since 2.0.0
6744
6744
  * @category context
6745
6745
  */
6746
- <T extends Context.Tag<any, any>>(
6747
- tag: T,
6748
- resource: Context.Tag.Service<T>
6749
- ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, Exclude<R, Context.Tag.Identifier<T>>>
6746
+ <I, S>(tag: Context.Tag<I, S>, resource: NoInfer<S>): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, Exclude<R, I>>
6750
6747
  /**
6751
6748
  * Provides the stream with the single service it requires. If the stream
6752
6749
  * requires more than one service use `Stream.provideContext` instead.
@@ -6754,11 +6751,7 @@ export const provideService: {
6754
6751
  * @since 2.0.0
6755
6752
  * @category context
6756
6753
  */
6757
- <A, E, R, T extends Context.Tag<any, any>>(
6758
- self: Stream<A, E, R>,
6759
- tag: T,
6760
- resource: Context.Tag.Service<T>
6761
- ): Stream<A, E, Exclude<R, Context.Tag.Identifier<T>>>
6754
+ <A, E, R, I, S>(self: Stream<A, E, R>, tag: Context.Tag<I, S>, resource: NoInfer<S>): Stream<A, E, Exclude<R, I>>
6762
6755
  } = internal.provideService
6763
6756
 
6764
6757
  /**
@@ -6776,10 +6769,10 @@ export const provideServiceEffect: {
6776
6769
  * @since 2.0.0
6777
6770
  * @category context
6778
6771
  */
6779
- <T extends Context.Tag<any, any>, E2, R2>(
6780
- tag: T,
6781
- effect: Effect.Effect<Context.Tag.Service<T>, E2, R2>
6782
- ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | Exclude<R, Context.Tag.Identifier<T>>>
6772
+ <I, S, E2, R2>(
6773
+ tag: Context.Tag<I, S>,
6774
+ effect: Effect.Effect<NoInfer<S>, E2, R2>
6775
+ ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | Exclude<R, I>>
6783
6776
  /**
6784
6777
  * Provides the stream with the single service it requires. If the stream
6785
6778
  * requires more than one service use `Stream.provideContext` instead.
@@ -6787,11 +6780,11 @@ export const provideServiceEffect: {
6787
6780
  * @since 2.0.0
6788
6781
  * @category context
6789
6782
  */
6790
- <A, E, R, T extends Context.Tag<any, any>, E2, R2>(
6783
+ <A, E, R, I, S, E2, R2>(
6791
6784
  self: Stream<A, E, R>,
6792
- tag: T,
6793
- effect: Effect.Effect<Context.Tag.Service<T>, E2, R2>
6794
- ): Stream<A, E | E2, R2 | Exclude<R, Context.Tag.Identifier<T>>>
6785
+ tag: Context.Tag<I, S>,
6786
+ effect: Effect.Effect<NoInfer<S>, E2, R2>
6787
+ ): Stream<A, E2 | E, R2 | Exclude<R, I>>
6795
6788
  } = internal.provideServiceEffect
6796
6789
 
6797
6790
  /**
@@ -6809,10 +6802,10 @@ export const provideServiceStream: {
6809
6802
  * @since 2.0.0
6810
6803
  * @category context
6811
6804
  */
6812
- <T extends Context.Tag<any, any>, E2, R2>(
6813
- tag: T,
6814
- stream: Stream<Context.Tag.Service<T>, E2, R2>
6815
- ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | Exclude<R, Context.Tag.Identifier<T>>>
6805
+ <I, S, E2, R2>(
6806
+ tag: Context.Tag<I, S>,
6807
+ stream: Stream<NoInfer<S>, E2, R2>
6808
+ ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E2 | E, R2 | Exclude<R, I>>
6816
6809
  /**
6817
6810
  * Provides the stream with the single service it requires. If the stream
6818
6811
  * requires more than one service use `Stream.provideContext` instead.
@@ -6820,11 +6813,11 @@ export const provideServiceStream: {
6820
6813
  * @since 2.0.0
6821
6814
  * @category context
6822
6815
  */
6823
- <A, E, R, T extends Context.Tag<any, any>, E2, R2>(
6816
+ <A, E, R, I, S, E2, R2>(
6824
6817
  self: Stream<A, E, R>,
6825
- tag: T,
6826
- stream: Stream<Context.Tag.Service<T>, E2, R2>
6827
- ): Stream<A, E | E2, R2 | Exclude<R, Context.Tag.Identifier<T>>>
6818
+ tag: Context.Tag<I, S>,
6819
+ stream: Stream<NoInfer<S>, E2, R2>
6820
+ ): Stream<A, E2 | E, R2 | Exclude<R, I>>
6828
6821
  } = internal.provideServiceStream
6829
6822
 
6830
6823
  /**
@@ -10028,21 +10021,21 @@ export const updateService: {
10028
10021
  * @since 2.0.0
10029
10022
  * @category context
10030
10023
  */
10031
- <T extends Context.Tag<any, any>>(
10032
- tag: T,
10033
- f: (service: Context.Tag.Service<T>) => Context.Tag.Service<T>
10034
- ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, T | R>
10024
+ <I, S>(
10025
+ tag: Context.Tag<I, S>,
10026
+ f: (service: NoInfer<S>) => NoInfer<S>
10027
+ ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, I | R>
10035
10028
  /**
10036
10029
  * Updates the specified service within the context of the `Stream`.
10037
10030
  *
10038
10031
  * @since 2.0.0
10039
10032
  * @category context
10040
10033
  */
10041
- <A, E, R, T extends Context.Tag<any, any>>(
10034
+ <A, E, R, I, S>(
10042
10035
  self: Stream<A, E, R>,
10043
- tag: T,
10044
- f: (service: Context.Tag.Service<T>) => Context.Tag.Service<T>
10045
- ): Stream<A, E, R | T>
10036
+ tag: Context.Tag<I, S>,
10037
+ f: (service: NoInfer<S>) => NoInfer<S>
10038
+ ): Stream<A, E, I | R>
10046
10039
  } = internal.updateService
10047
10040
 
10048
10041
  /**
package/src/Trie.ts CHANGED
@@ -34,7 +34,7 @@ export type TypeId = typeof TypeId
34
34
  * @since 2.0.0
35
35
  * @category models
36
36
  */
37
- export interface Trie<in out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
37
+ export interface Trie<out Value> extends Iterable<[string, Value]>, Equal, Pipeable, Inspectable {
38
38
  readonly [TypeId]: {
39
39
  readonly _Value: Covariant<Value>
40
40
  }
@@ -145,7 +145,7 @@ export const insert: {
145
145
  * @since 2.0.0
146
146
  * @category mutations
147
147
  */
148
- <V>(key: string, value: V): (self: Trie<V>) => Trie<V>
148
+ <V1>(key: string, value: V1): <V>(self: Trie<V>) => Trie<V | V1>
149
149
  /**
150
150
  * Insert a new entry in the `Trie`.
151
151
  *
@@ -169,7 +169,7 @@ export const insert: {
169
169
  * @since 2.0.0
170
170
  * @category mutations
171
171
  */
172
- <V>(self: Trie<V>, key: string, value: V): Trie<V>
172
+ <V1, V>(self: Trie<V>, key: string, value: V1): Trie<V | V1>
173
173
  } = TR.insert
174
174
 
175
175
  /**
@@ -1605,7 +1605,7 @@ export const modify: {
1605
1605
  * @since 2.0.0
1606
1606
  * @category mutations
1607
1607
  */
1608
- <V>(key: string, f: (v: V) => V): (self: Trie<V>) => Trie<V>
1608
+ <V1, V>(key: string, f: (v: V) => V1): (self: Trie<V>) => Trie<V1 | V>
1609
1609
  /**
1610
1610
  * Updates the value of the specified key within the `Trie` if it exists.
1611
1611
  *
@@ -1627,7 +1627,7 @@ export const modify: {
1627
1627
  * @since 2.0.0
1628
1628
  * @category mutations
1629
1629
  */
1630
- <V>(self: Trie<V>, key: string, f: (v: V) => V): Trie<V>
1630
+ <V1, V>(self: Trie<V>, key: string, f: (v: V) => V1): Trie<V | V1>
1631
1631
  } = TR.modify
1632
1632
 
1633
1633
  /**
@@ -1760,7 +1760,7 @@ export const insertMany: {
1760
1760
  * @since 2.0.0
1761
1761
  * @category mutations
1762
1762
  */
1763
- <V>(iter: Iterable<[string, V]>): (self: Trie<V>) => Trie<V>
1763
+ <V1>(iter: Iterable<[string, V1]>): <V>(self: Trie<V>) => Trie<V | V1>
1764
1764
  /**
1765
1765
  * Insert multiple entries in the `Trie` at once.
1766
1766
  *
@@ -1790,5 +1790,5 @@ export const insertMany: {
1790
1790
  * @since 2.0.0
1791
1791
  * @category mutations
1792
1792
  */
1793
- <V>(self: Trie<V>, iter: Iterable<[string, V]>): Trie<V>
1793
+ <V1, V>(self: Trie<V>, iter: Iterable<[string, V1]>): Trie<V | V1>
1794
1794
  } = TR.insertMany
package/src/index.ts CHANGED
@@ -447,6 +447,31 @@ export * as Mailbox from "./Mailbox.js"
447
447
  export * as ManagedRuntime from "./ManagedRuntime.js"
448
448
 
449
449
  /**
450
+ * The `effect/match` module provides a type-safe pattern matching system for
451
+ * TypeScript. Inspired by functional programming, it simplifies conditional
452
+ * logic by replacing verbose if/else or switch statements with a structured and
453
+ * expressive API.
454
+ *
455
+ * This module supports matching against types, values, and discriminated unions
456
+ * while enforcing exhaustiveness checking to ensure all cases are handled.
457
+ *
458
+ * Although pattern matching is not yet a native JavaScript feature,
459
+ * `effect/match` offers a reliable implementation that is available today.
460
+ *
461
+ * **How Pattern Matching Works**
462
+ *
463
+ * Pattern matching follows a structured process:
464
+ *
465
+ * - **Creating a matcher**: Define a `Matcher` that operates on either a
466
+ * specific `Match.type` or `Match.value`.
467
+ *
468
+ * - **Defining patterns**: Use combinators such as `Match.when`, `Match.not`,
469
+ * and `Match.tag` to specify matching conditions.
470
+ *
471
+ * - **Completing the match**: Apply a finalizer such as `Match.exhaustive`,
472
+ * `Match.orElse`, or `Match.option` to determine how unmatched cases should
473
+ * be handled.
474
+ *
450
475
  * @since 1.0.0
451
476
  */
452
477
  export * as Match from "./Match.js"
@@ -23,6 +23,7 @@ import * as Ref from "../Ref.js"
23
23
  import * as Scope from "../Scope.js"
24
24
  import type * as SingleProducerAsyncInput from "../SingleProducerAsyncInput.js"
25
25
  import type * as Tracer from "../Tracer.js"
26
+ import type * as Types from "../Types.js"
26
27
  import * as executor from "./channel/channelExecutor.js"
27
28
  import type * as ChannelState from "./channel/channelState.js"
28
29
  import * as mergeDecision from "./channel/mergeDecision.js"
@@ -1960,22 +1961,22 @@ export const pipeToOrFail = dual<
1960
1961
 
1961
1962
  /** @internal */
1962
1963
  export const provideService = dual<
1963
- <T extends Context.Tag<any, any>>(
1964
- tag: T,
1965
- service: Context.Tag.Service<T>
1964
+ <I, S>(
1965
+ tag: Context.Tag<I, S>,
1966
+ service: Types.NoInfer<S>
1966
1967
  ) => <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
1967
1968
  self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
1968
- ) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Context.Tag.Identifier<T>>>,
1969
- <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env, T extends Context.Tag<any, any>>(
1969
+ ) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, I>>,
1970
+ <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env, I, S>(
1970
1971
  self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
1971
- tag: T,
1972
- service: Context.Tag.Service<T>
1973
- ) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Context.Tag.Identifier<T>>>
1974
- >(3, <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env, T extends Context.Tag<any, any>>(
1972
+ tag: Context.Tag<I, S>,
1973
+ service: Types.NoInfer<S>
1974
+ ) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, I>>
1975
+ >(3, <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env, I, S>(
1975
1976
  self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
1976
- tag: T,
1977
- service: Context.Tag.Service<T>
1978
- ): Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Context.Tag.Identifier<T>>> => {
1977
+ tag: Context.Tag<I, S>,
1978
+ service: Types.NoInfer<S>
1979
+ ): Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, I>> => {
1979
1980
  return core.flatMap(
1980
1981
  context<any>(),
1981
1982
  (context) => core.provideContext(self, Context.add(context, tag, service))
@@ -2089,31 +2090,28 @@ export const scopedWith = <A, E, R>(
2089
2090
  unwrapScoped(Effect.map(Effect.scope, (scope) => core.flatMap(core.fromEffect(f(scope)), core.write)))
2090
2091
 
2091
2092
  /** @internal */
2092
- export const service = <T extends Context.Tag<any, any>>(
2093
- tag: T
2094
- ): Channel.Channel<never, unknown, never, unknown, Context.Tag.Service<T>, unknown, Context.Tag.Identifier<T>> =>
2095
- core.fromEffect(tag)
2093
+ export const service = <I, S>(
2094
+ tag: Context.Tag<I, S>
2095
+ ): Channel.Channel<never, unknown, never, unknown, S, unknown, I> => core.fromEffect(tag)
2096
2096
 
2097
2097
  /** @internal */
2098
- export const serviceWith = <T extends Context.Tag<any, any>>(tag: T) =>
2098
+ export const serviceWith = <I, S>(tag: Context.Tag<I, S>) =>
2099
2099
  <OutDone>(
2100
- f: (resource: Context.Tag.Service<T>) => OutDone
2101
- ): Channel.Channel<never, unknown, never, unknown, OutDone, unknown, Context.Tag.Identifier<T>> => map(service(tag), f)
2100
+ f: (resource: Types.NoInfer<S>) => OutDone
2101
+ ): Channel.Channel<never, unknown, never, unknown, OutDone, unknown, I> => map(service(tag), f)
2102
2102
 
2103
2103
  /** @internal */
2104
2104
  export const serviceWithChannel =
2105
- <T extends Context.Tag<any, any>>(tag: T) =>
2105
+ <I, S>(tag: Context.Tag<I, S>) =>
2106
2106
  <Env, InErr, InElem, InDone, OutErr, OutElem, OutDone>(
2107
- f: (resource: Context.Tag.Service<T>) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
2108
- ): Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env | Context.Tag.Identifier<T>> =>
2109
- core.flatMap(service(tag), f)
2107
+ f: (resource: Types.NoInfer<S>) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
2108
+ ): Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env | I> => core.flatMap(service(tag), f)
2110
2109
 
2111
2110
  /** @internal */
2112
- export const serviceWithEffect = <T extends Context.Tag<any, any>>(tag: T) =>
2111
+ export const serviceWithEffect = <I, S>(tag: Context.Tag<I, S>) =>
2113
2112
  <Env, OutErr, OutDone>(
2114
- f: (resource: Context.Tag.Service<T>) => Effect.Effect<OutDone, OutErr, Env>
2115
- ): Channel.Channel<never, unknown, OutErr, unknown, OutDone, unknown, Env | Context.Tag.Identifier<T>> =>
2116
- mapEffect(service(tag), f)
2113
+ f: (resource: Types.NoInfer<S>) => Effect.Effect<OutDone, OutErr, Env>
2114
+ ): Channel.Channel<never, unknown, OutErr, unknown, OutDone, unknown, Env | I> => mapEffect(service(tag), f)
2117
2115
 
2118
2116
  /** @internal */
2119
2117
  export const splitLines = <Err, Done>(): Channel.Channel<
@@ -2334,22 +2332,22 @@ export const unwrapScopedWith = <OutElem, InElem, OutErr, InErr, OutDone, InDone
2334
2332
 
2335
2333
  /** @internal */
2336
2334
  export const updateService = dual<
2337
- <T extends Context.Tag<any, any>>(
2338
- tag: T,
2339
- f: (resource: Context.Tag.Service<T>) => Context.Tag.Service<T>
2335
+ <I, S>(
2336
+ tag: Context.Tag<I, S>,
2337
+ f: (resource: Types.NoInfer<S>) => Types.NoInfer<S>
2340
2338
  ) => <OutElem, OutErr, InErr, OutDone, InDone, R>(
2341
2339
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, R>
2342
- ) => Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, T | R>,
2343
- <OutElem, OutErr, InErr, OutDone, InDone, R, T extends Context.Tag<any, any>>(
2340
+ ) => Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, I | R>,
2341
+ <OutElem, OutErr, InErr, OutDone, InDone, R, I, S>(
2344
2342
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, R>,
2345
- tag: T,
2346
- f: (resource: Context.Tag.Service<T>) => Context.Tag.Service<T>
2347
- ) => Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, T | R>
2348
- >(3, <OutElem, OutErr, InErr, OutDone, InDone, R, T extends Context.Tag<any, any>>(
2343
+ tag: Context.Tag<I, S>,
2344
+ f: (resource: Types.NoInfer<S>) => Types.NoInfer<S>
2345
+ ) => Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, I | R>
2346
+ >(3, <OutElem, OutErr, InErr, OutDone, InDone, R, I, S>(
2349
2347
  self: Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, R>,
2350
- tag: T,
2351
- f: (resource: Context.Tag.Service<T>) => Context.Tag.Service<T>
2352
- ): Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, R | T> =>
2348
+ tag: Context.Tag<I, S>,
2349
+ f: (resource: Types.NoInfer<S>) => Types.NoInfer<S>
2350
+ ): Channel.Channel<OutElem, unknown, OutErr, InErr, OutDone, InDone, R | I> =>
2353
2351
  mapInputContext(self, (context: Context.Context<R>) =>
2354
2352
  Context.merge(
2355
2353
  context,