effect 3.14.21 → 3.15.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 (108) hide show
  1. package/dist/cjs/Brand.js +8 -0
  2. package/dist/cjs/Brand.js.map +1 -1
  3. package/dist/cjs/Cause.js +8 -1
  4. package/dist/cjs/Cause.js.map +1 -1
  5. package/dist/cjs/ConfigError.js.map +1 -1
  6. package/dist/cjs/Effect.js.map +1 -1
  7. package/dist/cjs/Either.js +36 -1
  8. package/dist/cjs/Either.js.map +1 -1
  9. package/dist/cjs/Function.js +2 -2
  10. package/dist/cjs/Function.js.map +1 -1
  11. package/dist/cjs/Layer.js +8 -1
  12. package/dist/cjs/Layer.js.map +1 -1
  13. package/dist/cjs/MutableHashMap.js.map +1 -1
  14. package/dist/cjs/MutableList.js.map +1 -1
  15. package/dist/cjs/Pipeable.js +25 -1
  16. package/dist/cjs/Pipeable.js.map +1 -1
  17. package/dist/cjs/Record.js +26 -1
  18. package/dist/cjs/Record.js.map +1 -1
  19. package/dist/cjs/Schema.js +14 -5
  20. package/dist/cjs/Schema.js.map +1 -1
  21. package/dist/cjs/Stream.js +23 -2
  22. package/dist/cjs/Stream.js.map +1 -1
  23. package/dist/cjs/internal/configError.js +12 -0
  24. package/dist/cjs/internal/configError.js.map +1 -1
  25. package/dist/cjs/internal/core-effect.js +17 -1
  26. package/dist/cjs/internal/core-effect.js.map +1 -1
  27. package/dist/cjs/internal/stream.js +62 -2
  28. package/dist/cjs/internal/stream.js.map +1 -1
  29. package/dist/cjs/internal/version.js +1 -1
  30. package/dist/cjs/internal/version.js.map +1 -1
  31. package/dist/dts/Brand.d.ts +7 -0
  32. package/dist/dts/Brand.d.ts.map +1 -1
  33. package/dist/dts/Cause.d.ts +7 -0
  34. package/dist/dts/Cause.d.ts.map +1 -1
  35. package/dist/dts/ConfigError.d.ts +2 -0
  36. package/dist/dts/ConfigError.d.ts.map +1 -1
  37. package/dist/dts/Effect.d.ts +25 -363
  38. package/dist/dts/Effect.d.ts.map +1 -1
  39. package/dist/dts/Either.d.ts +35 -0
  40. package/dist/dts/Either.d.ts.map +1 -1
  41. package/dist/dts/Function.d.ts +2 -2
  42. package/dist/dts/Function.d.ts.map +1 -1
  43. package/dist/dts/Layer.d.ts +6 -0
  44. package/dist/dts/Layer.d.ts.map +1 -1
  45. package/dist/dts/MutableHashMap.d.ts +1 -1
  46. package/dist/dts/MutableHashMap.d.ts.map +1 -1
  47. package/dist/dts/MutableList.d.ts +1 -1
  48. package/dist/dts/MutableList.d.ts.map +1 -1
  49. package/dist/dts/Pipeable.d.ts +30 -1
  50. package/dist/dts/Pipeable.d.ts.map +1 -1
  51. package/dist/dts/Record.d.ts +86 -0
  52. package/dist/dts/Record.d.ts.map +1 -1
  53. package/dist/dts/Schema.d.ts.map +1 -1
  54. package/dist/dts/Stream.d.ts +36 -0
  55. package/dist/dts/Stream.d.ts.map +1 -1
  56. package/dist/dts/Types.d.ts +11 -0
  57. package/dist/dts/Types.d.ts.map +1 -1
  58. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  59. package/dist/dts/internal/stream.d.ts.map +1 -1
  60. package/dist/esm/Brand.js +8 -1
  61. package/dist/esm/Brand.js.map +1 -1
  62. package/dist/esm/Cause.js +7 -0
  63. package/dist/esm/Cause.js.map +1 -1
  64. package/dist/esm/ConfigError.js.map +1 -1
  65. package/dist/esm/Effect.js.map +1 -1
  66. package/dist/esm/Either.js +35 -0
  67. package/dist/esm/Either.js.map +1 -1
  68. package/dist/esm/Function.js +2 -2
  69. package/dist/esm/Function.js.map +1 -1
  70. package/dist/esm/Layer.js +6 -0
  71. package/dist/esm/Layer.js.map +1 -1
  72. package/dist/esm/MutableHashMap.js.map +1 -1
  73. package/dist/esm/MutableList.js.map +1 -1
  74. package/dist/esm/Pipeable.js +23 -0
  75. package/dist/esm/Pipeable.js.map +1 -1
  76. package/dist/esm/Record.js +25 -0
  77. package/dist/esm/Record.js.map +1 -1
  78. package/dist/esm/Schema.js +14 -5
  79. package/dist/esm/Schema.js.map +1 -1
  80. package/dist/esm/Stream.js +21 -0
  81. package/dist/esm/Stream.js.map +1 -1
  82. package/dist/esm/internal/configError.js +12 -0
  83. package/dist/esm/internal/configError.js.map +1 -1
  84. package/dist/esm/internal/core-effect.js +17 -1
  85. package/dist/esm/internal/core-effect.js.map +1 -1
  86. package/dist/esm/internal/stream.js +58 -0
  87. package/dist/esm/internal/stream.js.map +1 -1
  88. package/dist/esm/internal/version.js +1 -1
  89. package/dist/esm/internal/version.js.map +1 -1
  90. package/package.json +1 -1
  91. package/src/Brand.ts +9 -1
  92. package/src/Cause.ts +8 -0
  93. package/src/ConfigError.ts +2 -0
  94. package/src/Effect.ts +54 -377
  95. package/src/Either.ts +107 -0
  96. package/src/Function.ts +2 -2
  97. package/src/Layer.ts +11 -0
  98. package/src/MutableHashMap.ts +1 -1
  99. package/src/MutableList.ts +1 -1
  100. package/src/Pipeable.ts +51 -1
  101. package/src/Record.ts +120 -0
  102. package/src/Schema.ts +19 -8
  103. package/src/Stream.ts +40 -0
  104. package/src/Types.ts +13 -0
  105. package/src/internal/configError.ts +12 -0
  106. package/src/internal/core-effect.ts +70 -106
  107. package/src/internal/stream.ts +68 -0
  108. package/src/internal/version.ts +1 -1
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.14.21";
1
+ let moduleVersion = "3.15.0";
2
2
  export const getCurrentVersion = () => moduleVersion;
3
3
  export const setCurrentVersion = version => {
4
4
  moduleVersion = version;
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":["moduleVersion","getCurrentVersion","setCurrentVersion","version"],"sources":["../../../src/internal/version.ts"],"sourcesContent":[null],"mappings":"AAAA,IAAIA,aAAa,GAAG,SAAS;AAE7B,OAAO,MAAMC,iBAAiB,GAAGA,CAAA,KAAMD,aAAa;AAEpD,OAAO,MAAME,iBAAiB,GAAIC,OAAe,IAAI;EACnDH,aAAa,GAAGG,OAAO;AACzB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"version.js","names":["moduleVersion","getCurrentVersion","setCurrentVersion","version"],"sources":["../../../src/internal/version.ts"],"sourcesContent":[null],"mappings":"AAAA,IAAIA,aAAa,GAAG,QAAQ;AAE5B,OAAO,MAAMC,iBAAiB,GAAGA,CAAA,KAAMD,aAAa;AAEpD,OAAO,MAAME,iBAAiB,GAAIC,OAAe,IAAI;EACnDH,aAAa,GAAGG,OAAO;AACzB,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "3.14.21",
3
+ "version": "3.15.0",
4
4
  "description": "The missing standard library for TypeScript, for writing production-grade software.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/Brand.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import * as Arr from "./Array.js"
20
20
  import * as Either from "./Either.js"
21
- import { identity } from "./Function.js"
21
+ import { identity, unsafeCoerce } from "./Function.js"
22
22
  import * as Option from "./Option.js"
23
23
  import type { Predicate } from "./Predicate.js"
24
24
  import type * as Types from "./Types.js"
@@ -350,3 +350,11 @@ export const all: <Brands extends readonly [Brand.Constructor<any>, ...Array<Bra
350
350
  is: (args: any): args is any => Either.isRight(either(args))
351
351
  })
352
352
  }
353
+
354
+ /**
355
+ * Retrieves the unbranded value from a `Brand` instance.
356
+ *
357
+ * @since 3.15.0
358
+ * @category getters
359
+ */
360
+ export const unbranded: <A extends Brand<any>>(branded: A) => Brand.Unbranded<A> = unsafeCoerce
package/src/Cause.ts CHANGED
@@ -1911,6 +1911,14 @@ export const isRuntimeException: (u: unknown) => u is RuntimeException = core.is
1911
1911
  */
1912
1912
  export const TimeoutException: new(message?: string | undefined) => TimeoutException = core.TimeoutException
1913
1913
 
1914
+ /**
1915
+ * Checks if a given unknown value is a `TimeoutException`.
1916
+ *
1917
+ * @since 3.15.0
1918
+ * @category Guards
1919
+ */
1920
+ export const isTimeoutException: (u: unknown) => u is TimeoutException = core.isTimeoutException
1921
+
1914
1922
  /**
1915
1923
  * Creates an instance of `UnknownException`, an error object used to handle
1916
1924
  * unknown errors such as those from rejected promises.
@@ -76,6 +76,7 @@ export interface And extends ConfigError.Proto {
76
76
  readonly _op: "And"
77
77
  readonly left: ConfigError
78
78
  readonly right: ConfigError
79
+ readonly message: string
79
80
  }
80
81
 
81
82
  /**
@@ -86,6 +87,7 @@ export interface Or extends ConfigError.Proto {
86
87
  readonly _op: "Or"
87
88
  readonly left: ConfigError
88
89
  readonly right: ConfigError
90
+ readonly message: string
89
91
  }
90
92
 
91
93
  /**
package/src/Effect.ts CHANGED
@@ -60,7 +60,15 @@ import * as Scheduler from "./Scheduler.js"
60
60
  import type * as Scope from "./Scope.js"
61
61
  import type * as Supervisor from "./Supervisor.js"
62
62
  import type * as Tracer from "./Tracer.js"
63
- import type { Concurrency, Contravariant, Covariant, NoExcessProperties, NoInfer, NotFunction } from "./Types.js"
63
+ import type {
64
+ Concurrency,
65
+ Contravariant,
66
+ Covariant,
67
+ EqualsWith,
68
+ NoExcessProperties,
69
+ NoInfer,
70
+ NotFunction
71
+ } from "./Types.js"
64
72
  import type * as Unify from "./Unify.js"
65
73
  import { isGeneratorFunction, type YieldWrap } from "./Utils.js"
66
74
 
@@ -7303,7 +7311,9 @@ export const catchTag: {
7303
7311
  * @since 2.0.0
7304
7312
  * @category Error handling
7305
7313
  */
7306
- <K extends E extends { _tag: string } ? E["_tag"] : never, E, A1, E1, R1>(k: K, f: (e: NoInfer<Extract<E, { _tag: K }>>) => Effect<A1, E1, R1>): <A, R>(self: Effect<A, E, R>) => Effect<A1 | A, E1 | Exclude<E, { _tag: K }>, R1 | R>
7314
+ <E, const K extends RA.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, A1, E1, R1>(
7315
+ ...args: [...tags: K, f: (e: Extract<NoInfer<E>, { _tag: K[number] }>) => Effect<A1, E1, R1>]
7316
+ ): <A, R>(self: Effect<A, E, R>) => Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>
7307
7317
  /**
7308
7318
  * Catches and handles specific errors by their `_tag` field, which is used as a
7309
7319
  * discriminator.
@@ -7361,11 +7371,10 @@ export const catchTag: {
7361
7371
  * @since 2.0.0
7362
7372
  * @category Error handling
7363
7373
  */
7364
- <A, E, R, K extends E extends { _tag: string } ? E["_tag"] : never, R1, E1, A1>(
7374
+ <A, E, R, const K extends RA.NonEmptyReadonlyArray<E extends { _tag: string } ? E["_tag"] : never>, R1, E1, A1>(
7365
7375
  self: Effect<A, E, R>,
7366
- k: K,
7367
- f: (e: Extract<E, { _tag: K }>) => Effect<A1, E1, R1>
7368
- ): Effect<A | A1, E1 | Exclude<E, { _tag: K }>, R | R1>
7376
+ ...args: [...tags: K, f: (e: Extract<NoInfer<E>, { _tag: K[number] }>) => Effect<A1, E1, R1>]
7377
+ ): Effect<A | A1, Exclude<E, { _tag: K[number] }> | E1, R | R1>
7369
7378
  } = effect.catchTag
7370
7379
 
7371
7380
  /**
@@ -9433,51 +9442,10 @@ export const liftPredicate: {
9433
9442
  * @category Condition Checking
9434
9443
  * @since 3.4.0
9435
9444
  */
9436
- <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Effect<B, E>
9437
- /**
9438
- * Transforms a `Predicate` function into an `Effect` returning the input value if the predicate returns `true`
9439
- * or failing with specified error if the predicate fails
9440
- *
9441
- * **Example**
9442
- *
9443
- * ```ts
9444
- * import { Effect } from "effect"
9445
- *
9446
- * const isPositive = (n: number): boolean => n > 0
9447
- *
9448
- * // succeeds with `1`
9449
- * Effect.liftPredicate(1, isPositive, n => `${n} is not positive`)
9450
- *
9451
- * // fails with `"0 is not positive"`
9452
- * Effect.liftPredicate(0, isPositive, n => `${n} is not positive`)
9453
- * ```
9454
- *
9455
- * @category Condition Checking
9456
- * @since 3.4.0
9457
- */
9458
- <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Effect<B, E>
9459
- /**
9460
- * Transforms a `Predicate` function into an `Effect` returning the input value if the predicate returns `true`
9461
- * or failing with specified error if the predicate fails
9462
- *
9463
- * **Example**
9464
- *
9465
- * ```ts
9466
- * import { Effect } from "effect"
9467
- *
9468
- * const isPositive = (n: number): boolean => n > 0
9469
- *
9470
- * // succeeds with `1`
9471
- * Effect.liftPredicate(1, isPositive, n => `${n} is not positive`)
9472
- *
9473
- * // fails with `"0 is not positive"`
9474
- * Effect.liftPredicate(0, isPositive, n => `${n} is not positive`)
9475
- * ```
9476
- *
9477
- * @category Condition Checking
9478
- * @since 3.4.0
9479
- */
9480
- <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Effect<B, E>
9445
+ <T extends A, E, B extends T = T, A = T>(
9446
+ predicate: Refinement<T, B> | Predicate<T>,
9447
+ orFailWith: (a: EqualsWith<T, B, A, Exclude<A, B>>) => E
9448
+ ): (a: A) => Effect<EqualsWith<T, B, A, B>, E>
9481
9449
  /**
9482
9450
  * Transforms a `Predicate` function into an `Effect` returning the input value if the predicate returns `true`
9483
9451
  * or failing with specified error if the predicate fails
@@ -9499,7 +9467,11 @@ export const liftPredicate: {
9499
9467
  * @category Condition Checking
9500
9468
  * @since 3.4.0
9501
9469
  */
9502
- <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Effect<B, E>
9470
+ <A, E, B extends A = A>(
9471
+ self: A,
9472
+ predicate: Refinement<A, B> | Predicate<A>,
9473
+ orFailWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => E
9474
+ ): Effect<B, E>
9503
9475
  } = effect.liftPredicate
9504
9476
 
9505
9477
  /**
@@ -16367,28 +16339,10 @@ export const filterOrDie: {
16367
16339
  * @since 2.0.0
16368
16340
  * @category Filtering
16369
16341
  */
16370
- <A, B extends A>(
16371
- refinement: Refinement<NoInfer<A>, B>,
16372
- orDieWith: (a: NoInfer<A>) => unknown
16342
+ <A, B extends A = A>(
16343
+ predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>,
16344
+ orDieWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => unknown
16373
16345
  ): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>
16374
- /**
16375
- * Filters an effect, dying with a custom defect if the predicate fails.
16376
- *
16377
- * **Details**
16378
- *
16379
- * This function applies a predicate to the result of an effect. If the
16380
- * predicate evaluates to `false`, the effect dies with a custom defect
16381
- * generated by the `orDieWith` function.
16382
- *
16383
- * **When to Use**
16384
- *
16385
- * This is useful for enforcing constraints on values and treating violations as
16386
- * fatal program errors.
16387
- *
16388
- * @since 2.0.0
16389
- * @category Filtering
16390
- */
16391
- <A>(predicate: Predicate<NoInfer<A>>, orDieWith: (a: NoInfer<A>) => unknown): <E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
16392
16346
  /**
16393
16347
  * Filters an effect, dying with a custom defect if the predicate fails.
16394
16348
  *
@@ -16408,31 +16362,9 @@ export const filterOrDie: {
16408
16362
  */
16409
16363
  <A, E, R, B extends A>(
16410
16364
  self: Effect<A, E, R>,
16411
- refinement: Refinement<A, B>,
16412
- orDieWith: (a: A) => unknown
16365
+ predicate: Predicate<A> | Refinement<A, B>,
16366
+ orDieWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => unknown
16413
16367
  ): Effect<B, E, R>
16414
- /**
16415
- * Filters an effect, dying with a custom defect if the predicate fails.
16416
- *
16417
- * **Details**
16418
- *
16419
- * This function applies a predicate to the result of an effect. If the
16420
- * predicate evaluates to `false`, the effect dies with a custom defect
16421
- * generated by the `orDieWith` function.
16422
- *
16423
- * **When to Use**
16424
- *
16425
- * This is useful for enforcing constraints on values and treating violations as
16426
- * fatal program errors.
16427
- *
16428
- * @since 2.0.0
16429
- * @category Filtering
16430
- */
16431
- <A, E, R>(
16432
- self: Effect<A, E, R>,
16433
- predicate: Predicate<A>,
16434
- orDieWith: (a: A) => unknown
16435
- ): Effect<A, E, R>
16436
16368
  } = effect.filterOrDie
16437
16369
 
16438
16370
  /**
@@ -16460,33 +16392,10 @@ export const filterOrDieMessage: {
16460
16392
  * @since 2.0.0
16461
16393
  * @category Filtering
16462
16394
  */
16463
- <A, B extends A>(refinement: Refinement<NoInfer<A>, B>, message: string): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>
16464
- /**
16465
- * Filters an effect, dying with a custom message if the predicate fails.
16466
- *
16467
- * **Details**
16468
- *
16469
- * This function works like {@link filterOrDie} but allows you to specify a
16470
- * custom error message to describe the reason for the failure. The message is
16471
- * included in the defect when the predicate evaluates to `false`.
16472
- *
16473
- * @since 2.0.0
16474
- * @category Filtering
16475
- */
16476
- <A>(predicate: Predicate<NoInfer<A>>, message: string): <E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
16477
- /**
16478
- * Filters an effect, dying with a custom message if the predicate fails.
16479
- *
16480
- * **Details**
16481
- *
16482
- * This function works like {@link filterOrDie} but allows you to specify a
16483
- * custom error message to describe the reason for the failure. The message is
16484
- * included in the defect when the predicate evaluates to `false`.
16485
- *
16486
- * @since 2.0.0
16487
- * @category Filtering
16488
- */
16489
- <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Refinement<A, B>, message: string): Effect<B, E, R>
16395
+ <A, B extends A = A>(
16396
+ predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>,
16397
+ message: string
16398
+ ): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>
16490
16399
  /**
16491
16400
  * Filters an effect, dying with a custom message if the predicate fails.
16492
16401
  *
@@ -16499,7 +16408,11 @@ export const filterOrDieMessage: {
16499
16408
  * @since 2.0.0
16500
16409
  * @category Filtering
16501
16410
  */
16502
- <A, E, R>(self: Effect<A, E, R>, predicate: Predicate<A>, message: string): Effect<A, E, R>
16411
+ <A, E, R, B extends A = A>(
16412
+ self: Effect<A, E, R>,
16413
+ predicate: Predicate<A> | Refinement<A, B>,
16414
+ message: string
16415
+ ): Effect<B, E, R>
16503
16416
  } = effect.filterOrDieMessage
16504
16417
 
16505
16418
  /**
@@ -16529,9 +16442,9 @@ export const filterOrElse: {
16529
16442
  * @since 2.0.0
16530
16443
  * @category Filtering
16531
16444
  */
16532
- <A, B extends A, C, E2, R2>(
16533
- refinement: Refinement<NoInfer<A>, B>,
16534
- orElse: (a: NoInfer<A>) => Effect<C, E2, R2>
16445
+ <A, C, E2, R2, B extends A = A>(
16446
+ predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>,
16447
+ orElse: (a: EqualsWith<A, B, NoInfer<A>, Exclude<NoInfer<A>, B>>) => Effect<C, E2, R2>
16535
16448
  ): <E, R>(self: Effect<A, E, R>) => Effect<B | C, E2 | E, R2 | R>
16536
16449
  /**
16537
16450
  * Filters an effect, providing an alternative effect if the predicate fails.
@@ -16546,46 +16459,11 @@ export const filterOrElse: {
16546
16459
  * @since 2.0.0
16547
16460
  * @category Filtering
16548
16461
  */
16549
- <A, B, E2, R2>(
16550
- predicate: Predicate<NoInfer<A>>,
16551
- orElse: (a: NoInfer<A>) => Effect<B, E2, R2>
16552
- ): <E, R>(self: Effect<A, E, R>) => Effect<A | B, E2 | E, R2 | R>
16553
- /**
16554
- * Filters an effect, providing an alternative effect if the predicate fails.
16555
- *
16556
- * **Details**
16557
- *
16558
- * This function applies a predicate to the result of an effect. If the
16559
- * predicate evaluates to `false`, it executes the `orElse` effect instead. The
16560
- * `orElse` effect can produce an alternative value or perform additional
16561
- * computations.
16562
- *
16563
- * @since 2.0.0
16564
- * @category Filtering
16565
- */
16566
- <A, E, R, B extends A, C, E2, R2>(
16462
+ <A, E, R, C, E2, R2, B extends A = A>(
16567
16463
  self: Effect<A, E, R>,
16568
- refinement: Refinement<A, B>,
16569
- orElse: (a: A) => Effect<C, E2, R2>
16464
+ predicate: Predicate<A> | Refinement<A, B>,
16465
+ orElse: (a: EqualsWith<A, B, A, Exclude<A, B>>) => Effect<C, E2, R2>
16570
16466
  ): Effect<B | C, E | E2, R | R2>
16571
- /**
16572
- * Filters an effect, providing an alternative effect if the predicate fails.
16573
- *
16574
- * **Details**
16575
- *
16576
- * This function applies a predicate to the result of an effect. If the
16577
- * predicate evaluates to `false`, it executes the `orElse` effect instead. The
16578
- * `orElse` effect can produce an alternative value or perform additional
16579
- * computations.
16580
- *
16581
- * @since 2.0.0
16582
- * @category Filtering
16583
- */
16584
- <A, E, R, B, E2, R2>(
16585
- self: Effect<A, E, R>,
16586
- predicate: Predicate<A>,
16587
- orElse: (a: A) => Effect<B, E2, R2>
16588
- ): Effect<A | B, E | E2, R | R2>
16589
16467
  } = effect.filterOrElse
16590
16468
 
16591
16469
  /**
@@ -16689,7 +16567,10 @@ export const filterOrFail: {
16689
16567
  * @since 2.0.0
16690
16568
  * @category Filtering
16691
16569
  */
16692
- <A, B extends A, E2>(refinement: Refinement<NoInfer<A>, B>, orFailWith: (a: NoInfer<A>) => E2): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>
16570
+ <A, E2, B extends A = A>(
16571
+ predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>,
16572
+ orFailWith: (a: EqualsWith<A, B, NoInfer<A>, Exclude<NoInfer<A>, B>>) => E2
16573
+ ): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>
16693
16574
  /**
16694
16575
  * Filters an effect, failing with a custom error if the predicate fails.
16695
16576
  *
@@ -16740,215 +16621,11 @@ export const filterOrFail: {
16740
16621
  * @since 2.0.0
16741
16622
  * @category Filtering
16742
16623
  */
16743
- <A, E2>(predicate: Predicate<NoInfer<A>>, orFailWith: (a: NoInfer<A>) => E2): <E, R>(self: Effect<A, E, R>) => Effect<A, E2 | E, R>
16744
- /**
16745
- * Filters an effect, failing with a custom error if the predicate fails.
16746
- *
16747
- * **Details**
16748
- *
16749
- * This function applies a predicate to the result of an effect. If the
16750
- * predicate evaluates to `false`, the effect fails with a custom error
16751
- * generated by the `orFailWith` function.
16752
- *
16753
- * **When to Use**
16754
- *
16755
- * This is useful for enforcing constraints and treating violations as
16756
- * recoverable errors.
16757
- *
16758
- * **Providing a Guard**
16759
- *
16760
- * In addition to the filtering capabilities discussed earlier, you have the
16761
- * option to further refine and narrow down the type of the success channel by
16762
- * providing a [user-defined type
16763
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
16764
- * Let's explore this concept through an example:
16765
- *
16766
- * **Example**
16767
- *
16768
- * ```ts
16769
- * import { Effect, pipe } from "effect"
16770
- *
16771
- * // Define a user interface
16772
- * interface User {
16773
- * readonly name: string
16774
- * }
16775
- *
16776
- * // Simulate an asynchronous authentication function
16777
- * declare const auth: () => Promise<User | null>
16778
- *
16779
- * const program = pipe(
16780
- * Effect.promise(() => auth()),
16781
- * // Use filterOrFail with a custom type guard to ensure user is not null
16782
- * Effect.filterOrFail(
16783
- * (user): user is User => user !== null, // Type guard
16784
- * () => new Error("Unauthorized")
16785
- * ),
16786
- * // 'user' now has the type `User` (not `User | null`)
16787
- * Effect.andThen((user) => user.name)
16788
- * )
16789
- * ```
16790
- *
16791
- * @since 2.0.0
16792
- * @category Filtering
16793
- */
16794
- <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementException | E, R>
16795
- /**
16796
- * Filters an effect, failing with a custom error if the predicate fails.
16797
- *
16798
- * **Details**
16799
- *
16800
- * This function applies a predicate to the result of an effect. If the
16801
- * predicate evaluates to `false`, the effect fails with a custom error
16802
- * generated by the `orFailWith` function.
16803
- *
16804
- * **When to Use**
16805
- *
16806
- * This is useful for enforcing constraints and treating violations as
16807
- * recoverable errors.
16808
- *
16809
- * **Providing a Guard**
16810
- *
16811
- * In addition to the filtering capabilities discussed earlier, you have the
16812
- * option to further refine and narrow down the type of the success channel by
16813
- * providing a [user-defined type
16814
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
16815
- * Let's explore this concept through an example:
16816
- *
16817
- * **Example**
16818
- *
16819
- * ```ts
16820
- * import { Effect, pipe } from "effect"
16821
- *
16822
- * // Define a user interface
16823
- * interface User {
16824
- * readonly name: string
16825
- * }
16826
- *
16827
- * // Simulate an asynchronous authentication function
16828
- * declare const auth: () => Promise<User | null>
16829
- *
16830
- * const program = pipe(
16831
- * Effect.promise(() => auth()),
16832
- * // Use filterOrFail with a custom type guard to ensure user is not null
16833
- * Effect.filterOrFail(
16834
- * (user): user is User => user !== null, // Type guard
16835
- * () => new Error("Unauthorized")
16836
- * ),
16837
- * // 'user' now has the type `User` (not `User | null`)
16838
- * Effect.andThen((user) => user.name)
16839
- * )
16840
- * ```
16841
- *
16842
- * @since 2.0.0
16843
- * @category Filtering
16844
- */
16845
- <A>(predicate: Predicate<NoInfer<A>>): <E, R>(self: Effect<A, E, R>) => Effect<A, Cause.NoSuchElementException | E, R>
16846
- /**
16847
- * Filters an effect, failing with a custom error if the predicate fails.
16848
- *
16849
- * **Details**
16850
- *
16851
- * This function applies a predicate to the result of an effect. If the
16852
- * predicate evaluates to `false`, the effect fails with a custom error
16853
- * generated by the `orFailWith` function.
16854
- *
16855
- * **When to Use**
16856
- *
16857
- * This is useful for enforcing constraints and treating violations as
16858
- * recoverable errors.
16859
- *
16860
- * **Providing a Guard**
16861
- *
16862
- * In addition to the filtering capabilities discussed earlier, you have the
16863
- * option to further refine and narrow down the type of the success channel by
16864
- * providing a [user-defined type
16865
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
16866
- * Let's explore this concept through an example:
16867
- *
16868
- * **Example**
16869
- *
16870
- * ```ts
16871
- * import { Effect, pipe } from "effect"
16872
- *
16873
- * // Define a user interface
16874
- * interface User {
16875
- * readonly name: string
16876
- * }
16877
- *
16878
- * // Simulate an asynchronous authentication function
16879
- * declare const auth: () => Promise<User | null>
16880
- *
16881
- * const program = pipe(
16882
- * Effect.promise(() => auth()),
16883
- * // Use filterOrFail with a custom type guard to ensure user is not null
16884
- * Effect.filterOrFail(
16885
- * (user): user is User => user !== null, // Type guard
16886
- * () => new Error("Unauthorized")
16887
- * ),
16888
- * // 'user' now has the type `User` (not `User | null`)
16889
- * Effect.andThen((user) => user.name)
16890
- * )
16891
- * ```
16892
- *
16893
- * @since 2.0.0
16894
- * @category Filtering
16895
- */
16896
- <A, E, R, B extends A, E2>(
16624
+ <A, E, R, E2, B extends A = A>(
16897
16625
  self: Effect<A, E, R>,
16898
- refinement: Refinement<A, B>,
16899
- orFailWith: (a: A) => E2
16900
- ): Effect<B, E | E2, R>
16901
- /**
16902
- * Filters an effect, failing with a custom error if the predicate fails.
16903
- *
16904
- * **Details**
16905
- *
16906
- * This function applies a predicate to the result of an effect. If the
16907
- * predicate evaluates to `false`, the effect fails with a custom error
16908
- * generated by the `orFailWith` function.
16909
- *
16910
- * **When to Use**
16911
- *
16912
- * This is useful for enforcing constraints and treating violations as
16913
- * recoverable errors.
16914
- *
16915
- * **Providing a Guard**
16916
- *
16917
- * In addition to the filtering capabilities discussed earlier, you have the
16918
- * option to further refine and narrow down the type of the success channel by
16919
- * providing a [user-defined type
16920
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
16921
- * Let's explore this concept through an example:
16922
- *
16923
- * **Example**
16924
- *
16925
- * ```ts
16926
- * import { Effect, pipe } from "effect"
16927
- *
16928
- * // Define a user interface
16929
- * interface User {
16930
- * readonly name: string
16931
- * }
16932
- *
16933
- * // Simulate an asynchronous authentication function
16934
- * declare const auth: () => Promise<User | null>
16935
- *
16936
- * const program = pipe(
16937
- * Effect.promise(() => auth()),
16938
- * // Use filterOrFail with a custom type guard to ensure user is not null
16939
- * Effect.filterOrFail(
16940
- * (user): user is User => user !== null, // Type guard
16941
- * () => new Error("Unauthorized")
16942
- * ),
16943
- * // 'user' now has the type `User` (not `User | null`)
16944
- * Effect.andThen((user) => user.name)
16945
- * )
16946
- * ```
16947
- *
16948
- * @since 2.0.0
16949
- * @category Filtering
16950
- */
16951
- <A, E, R, E2>(self: Effect<A, E, R>, predicate: Predicate<A>, orFailWith: (a: A) => E2): Effect<A, E | E2, R>
16626
+ predicate: Predicate<A> | Refinement<A, B>,
16627
+ orFailWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => E2
16628
+ ): Effect<B, E2 | E, R>
16952
16629
  /**
16953
16630
  * Filters an effect, failing with a custom error if the predicate fails.
16954
16631
  *
@@ -16999,7 +16676,7 @@ export const filterOrFail: {
16999
16676
  * @since 2.0.0
17000
16677
  * @category Filtering
17001
16678
  */
17002
- <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Refinement<A, B>): Effect<B, E | Cause.NoSuchElementException, R>
16679
+ <A, B extends A = A>(predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementException | E, R>
17003
16680
  /**
17004
16681
  * Filters an effect, failing with a custom error if the predicate fails.
17005
16682
  *
@@ -17050,7 +16727,7 @@ export const filterOrFail: {
17050
16727
  * @since 2.0.0
17051
16728
  * @category Filtering
17052
16729
  */
17053
- <A, E, R>(self: Effect<A, E, R>, predicate: Predicate<A>): Effect<A, E | Cause.NoSuchElementException, R>
16730
+ <A, E, R, B extends A = A>(self: Effect<A, E, R>, predicate: Predicate<A> | Refinement<A, B>): Effect<B, E | Cause.NoSuchElementException, R>
17054
16731
  } = effect.filterOrFail
17055
16732
 
17056
16733
  /**