effect 3.16.12 → 3.16.13
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.
- package/dist/cjs/Array.js +2 -2
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +8 -8
- package/dist/dts/Effect.d.ts +1 -121
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/esm/Array.js +2 -2
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +8 -8
- package/src/Effect.ts +1 -117
- package/src/internal/core-effect.ts +24 -11
- package/src/internal/version.ts +1 -1
package/src/Effect.ts
CHANGED
|
@@ -7265,64 +7265,6 @@ export const catchSomeDefect: {
|
|
|
7265
7265
|
* @category Error handling
|
|
7266
7266
|
*/
|
|
7267
7267
|
export const catchTag: {
|
|
7268
|
-
/**
|
|
7269
|
-
* Catches and handles specific errors by their `_tag` field, which is used as a
|
|
7270
|
-
* discriminator.
|
|
7271
|
-
*
|
|
7272
|
-
* **When to Use**
|
|
7273
|
-
*
|
|
7274
|
-
* `catchTag` is useful when your errors are tagged with a readonly `_tag` field
|
|
7275
|
-
* that identifies the error type. You can use this function to handle specific
|
|
7276
|
-
* error types by matching the `_tag` value. This allows for precise error
|
|
7277
|
-
* handling, ensuring that only specific errors are caught and handled.
|
|
7278
|
-
*
|
|
7279
|
-
* The error type must have a readonly `_tag` field to use `catchTag`. This
|
|
7280
|
-
* field is used to identify and match errors.
|
|
7281
|
-
*
|
|
7282
|
-
* **Example** (Handling Errors by Tag)
|
|
7283
|
-
*
|
|
7284
|
-
* ```ts
|
|
7285
|
-
* import { Effect, Random } from "effect"
|
|
7286
|
-
*
|
|
7287
|
-
* class HttpError {
|
|
7288
|
-
* readonly _tag = "HttpError"
|
|
7289
|
-
* }
|
|
7290
|
-
*
|
|
7291
|
-
* class ValidationError {
|
|
7292
|
-
* readonly _tag = "ValidationError"
|
|
7293
|
-
* }
|
|
7294
|
-
*
|
|
7295
|
-
* // ┌─── Effect<string, HttpError | ValidationError, never>
|
|
7296
|
-
* // ▼
|
|
7297
|
-
* const program = Effect.gen(function* () {
|
|
7298
|
-
* const n1 = yield* Random.next
|
|
7299
|
-
* const n2 = yield* Random.next
|
|
7300
|
-
* if (n1 < 0.5) {
|
|
7301
|
-
* yield* Effect.fail(new HttpError())
|
|
7302
|
-
* }
|
|
7303
|
-
* if (n2 < 0.5) {
|
|
7304
|
-
* yield* Effect.fail(new ValidationError())
|
|
7305
|
-
* }
|
|
7306
|
-
* return "some result"
|
|
7307
|
-
* })
|
|
7308
|
-
*
|
|
7309
|
-
* // ┌─── Effect<string, ValidationError, never>
|
|
7310
|
-
* // ▼
|
|
7311
|
-
* const recovered = program.pipe(
|
|
7312
|
-
* // Only handle HttpError errors
|
|
7313
|
-
* Effect.catchTag("HttpError", (_HttpError) =>
|
|
7314
|
-
* Effect.succeed("Recovering from HttpError")
|
|
7315
|
-
* )
|
|
7316
|
-
* )
|
|
7317
|
-
* ```
|
|
7318
|
-
*
|
|
7319
|
-
* @see {@link catchTags} for a version that allows you to handle multiple error
|
|
7320
|
-
* types at once.
|
|
7321
|
-
*
|
|
7322
|
-
* @since 2.0.0
|
|
7323
|
-
* @category Error handling
|
|
7324
|
-
*/
|
|
7325
|
-
<E, const K extends RA.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>>(...tags: K): <A, R>(self: Effect<A, E, R> & "missing error handler") => never
|
|
7326
7268
|
/**
|
|
7327
7269
|
* Catches and handles specific errors by their `_tag` field, which is used as a
|
|
7328
7270
|
* discriminator.
|
|
@@ -7440,65 +7382,7 @@ export const catchTag: {
|
|
|
7440
7382
|
* @since 2.0.0
|
|
7441
7383
|
* @category Error handling
|
|
7442
7384
|
*/
|
|
7443
|
-
<A, E, R, const K extends RA.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never
|
|
7444
|
-
/**
|
|
7445
|
-
* Catches and handles specific errors by their `_tag` field, which is used as a
|
|
7446
|
-
* discriminator.
|
|
7447
|
-
*
|
|
7448
|
-
* **When to Use**
|
|
7449
|
-
*
|
|
7450
|
-
* `catchTag` is useful when your errors are tagged with a readonly `_tag` field
|
|
7451
|
-
* that identifies the error type. You can use this function to handle specific
|
|
7452
|
-
* error types by matching the `_tag` value. This allows for precise error
|
|
7453
|
-
* handling, ensuring that only specific errors are caught and handled.
|
|
7454
|
-
*
|
|
7455
|
-
* The error type must have a readonly `_tag` field to use `catchTag`. This
|
|
7456
|
-
* field is used to identify and match errors.
|
|
7457
|
-
*
|
|
7458
|
-
* **Example** (Handling Errors by Tag)
|
|
7459
|
-
*
|
|
7460
|
-
* ```ts
|
|
7461
|
-
* import { Effect, Random } from "effect"
|
|
7462
|
-
*
|
|
7463
|
-
* class HttpError {
|
|
7464
|
-
* readonly _tag = "HttpError"
|
|
7465
|
-
* }
|
|
7466
|
-
*
|
|
7467
|
-
* class ValidationError {
|
|
7468
|
-
* readonly _tag = "ValidationError"
|
|
7469
|
-
* }
|
|
7470
|
-
*
|
|
7471
|
-
* // ┌─── Effect<string, HttpError | ValidationError, never>
|
|
7472
|
-
* // ▼
|
|
7473
|
-
* const program = Effect.gen(function* () {
|
|
7474
|
-
* const n1 = yield* Random.next
|
|
7475
|
-
* const n2 = yield* Random.next
|
|
7476
|
-
* if (n1 < 0.5) {
|
|
7477
|
-
* yield* Effect.fail(new HttpError())
|
|
7478
|
-
* }
|
|
7479
|
-
* if (n2 < 0.5) {
|
|
7480
|
-
* yield* Effect.fail(new ValidationError())
|
|
7481
|
-
* }
|
|
7482
|
-
* return "some result"
|
|
7483
|
-
* })
|
|
7484
|
-
*
|
|
7485
|
-
* // ┌─── Effect<string, ValidationError, never>
|
|
7486
|
-
* // ▼
|
|
7487
|
-
* const recovered = program.pipe(
|
|
7488
|
-
* // Only handle HttpError errors
|
|
7489
|
-
* Effect.catchTag("HttpError", (_HttpError) =>
|
|
7490
|
-
* Effect.succeed("Recovering from HttpError")
|
|
7491
|
-
* )
|
|
7492
|
-
* )
|
|
7493
|
-
* ```
|
|
7494
|
-
*
|
|
7495
|
-
* @see {@link catchTags} for a version that allows you to handle multiple error
|
|
7496
|
-
* types at once.
|
|
7497
|
-
*
|
|
7498
|
-
* @since 2.0.0
|
|
7499
|
-
* @category Error handling
|
|
7500
|
-
*/
|
|
7501
|
-
<A, E, R, const K extends RA.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, R1, E1, A1>(
|
|
7385
|
+
<A, E, R, const K extends RA.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, A1, E1, R1>(
|
|
7502
7386
|
self: Effect<A, E, R>,
|
|
7503
7387
|
...args: [...tags: K, f: (e: Extract<NoInfer<E>, { _tag: K[number] }>) => Effect<A1, E1, R1>]
|
|
7504
7388
|
): Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>
|
|
@@ -237,19 +237,32 @@ export const catchSomeDefect = dual<
|
|
|
237
237
|
|
|
238
238
|
/* @internal */
|
|
239
239
|
export const catchTag: {
|
|
240
|
-
<
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
<
|
|
241
|
+
E,
|
|
242
|
+
const K extends Arr.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>,
|
|
243
|
+
A1,
|
|
244
|
+
E1,
|
|
245
|
+
R1
|
|
246
|
+
>(
|
|
247
|
+
...args: [
|
|
248
|
+
...tags: K,
|
|
249
|
+
f: (e: Extract<Types.NoInfer<E>, { _tag: K[number] }>) => Effect.Effect<A1, E1, R1>
|
|
250
|
+
]
|
|
245
251
|
): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>
|
|
246
|
-
<
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
<
|
|
253
|
+
A,
|
|
254
|
+
E,
|
|
255
|
+
R,
|
|
256
|
+
const K extends Arr.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>,
|
|
257
|
+
A1,
|
|
258
|
+
E1,
|
|
259
|
+
R1
|
|
260
|
+
>(
|
|
251
261
|
self: Effect.Effect<A, E, R>,
|
|
252
|
-
...args: [
|
|
262
|
+
...args: [
|
|
263
|
+
...tags: K,
|
|
264
|
+
f: (e: Extract<Types.NoInfer<E>, { _tag: K[number] }>) => Effect.Effect<A1, E1, R1>
|
|
265
|
+
]
|
|
253
266
|
): Effect.Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>
|
|
254
267
|
} = dual(
|
|
255
268
|
(args: any) => core.isEffect(args[0]),
|
package/src/internal/version.ts
CHANGED