effect 3.16.11 → 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/Data.js.map +1 -1
- 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/Data.d.ts +14 -6
- package/dist/dts/Data.d.ts.map +1 -1
- 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/Data.js.map +1 -1
- 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/Data.ts +11 -6
- package/src/Effect.ts +1 -117
- package/src/internal/core-effect.ts +24 -11
- package/src/internal/version.ts +1 -1
package/src/Data.ts
CHANGED
|
@@ -361,15 +361,20 @@ export declare namespace TaggedEnum {
|
|
|
361
361
|
readonly $is: <Tag extends A["_tag"]>(tag: Tag) => (u: unknown) => u is Extract<A, { readonly _tag: Tag }>
|
|
362
362
|
readonly $match: {
|
|
363
363
|
<
|
|
364
|
-
Cases extends {
|
|
364
|
+
const Cases extends {
|
|
365
365
|
readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
|
|
366
366
|
}
|
|
367
|
-
>(
|
|
367
|
+
>(
|
|
368
|
+
cases: Cases & { [K in Exclude<keyof Cases, A["_tag"]>]: never }
|
|
369
|
+
): (value: A) => Unify<ReturnType<Cases[A["_tag"]]>>
|
|
368
370
|
<
|
|
369
|
-
Cases extends {
|
|
371
|
+
const Cases extends {
|
|
370
372
|
readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
|
|
371
373
|
}
|
|
372
|
-
>(
|
|
374
|
+
>(
|
|
375
|
+
value: A,
|
|
376
|
+
cases: Cases & { [K in Exclude<keyof Cases, A["_tag"]>]: never }
|
|
377
|
+
): Unify<ReturnType<Cases[A["_tag"]]>>
|
|
373
378
|
}
|
|
374
379
|
}
|
|
375
380
|
>
|
|
@@ -398,7 +403,7 @@ export declare namespace TaggedEnum {
|
|
|
398
403
|
) => any
|
|
399
404
|
}
|
|
400
405
|
>(
|
|
401
|
-
cases: Cases
|
|
406
|
+
cases: Cases & { [K in Exclude<keyof Cases, Z["taggedEnum"]["_tag"]>]: never }
|
|
402
407
|
): (self: TaggedEnum.Kind<Z, A, B, C, D>) => Unify<ReturnType<Cases[Z["taggedEnum"]["_tag"]]>>
|
|
403
408
|
<
|
|
404
409
|
A,
|
|
@@ -412,7 +417,7 @@ export declare namespace TaggedEnum {
|
|
|
412
417
|
}
|
|
413
418
|
>(
|
|
414
419
|
self: TaggedEnum.Kind<Z, A, B, C, D>,
|
|
415
|
-
cases: Cases
|
|
420
|
+
cases: Cases & { [K in Exclude<keyof Cases, Z["taggedEnum"]["_tag"]>]: never }
|
|
416
421
|
): Unify<ReturnType<Cases[Z["taggedEnum"]["_tag"]]>>
|
|
417
422
|
}
|
|
418
423
|
}
|
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