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
@@ -45,7 +45,7 @@ import * as Scheduler from "./Scheduler.js";
45
45
  import type * as Scope from "./Scope.js";
46
46
  import type * as Supervisor from "./Supervisor.js";
47
47
  import type * as Tracer from "./Tracer.js";
48
- import type { Concurrency, Contravariant, Covariant, NoExcessProperties, NoInfer, NotFunction } from "./Types.js";
48
+ import type { Concurrency, Contravariant, Covariant, EqualsWith, NoExcessProperties, NoInfer, NotFunction } from "./Types.js";
49
49
  import type * as Unify from "./Unify.js";
50
50
  import { type YieldWrap } from "./Utils.js";
51
51
  /**
@@ -6763,13 +6763,13 @@ export declare const catchTag: {
6763
6763
  * @since 2.0.0
6764
6764
  * @category Error handling
6765
6765
  */
6766
- <K extends E extends {
6766
+ <E, const K extends RA.NonEmptyReadonlyArray<E extends {
6767
6767
  _tag: string;
6768
- } ? E["_tag"] : never, E, A1, E1, R1>(k: K, f: (e: NoInfer<Extract<E, {
6769
- _tag: K;
6770
- }>>) => Effect<A1, E1, R1>): <A, R>(self: Effect<A, E, R>) => Effect<A1 | A, E1 | Exclude<E, {
6771
- _tag: K;
6772
- }>, R1 | R>;
6768
+ } ? E["_tag"] : never>, A1, E1, R1>(...args: [...tags: K, f: (e: Extract<NoInfer<E>, {
6769
+ _tag: K[number];
6770
+ }>) => Effect<A1, E1, R1>]): <A, R>(self: Effect<A, E, R>) => Effect<A | A1, Exclude<E, {
6771
+ _tag: K[number];
6772
+ }> | E1, R | R1>;
6773
6773
  /**
6774
6774
  * Catches and handles specific errors by their `_tag` field, which is used as a
6775
6775
  * discriminator.
@@ -6827,13 +6827,13 @@ export declare const catchTag: {
6827
6827
  * @since 2.0.0
6828
6828
  * @category Error handling
6829
6829
  */
6830
- <A, E, R, K extends E extends {
6830
+ <A, E, R, const K extends RA.NonEmptyReadonlyArray<E extends {
6831
6831
  _tag: string;
6832
- } ? E["_tag"] : never, R1, E1, A1>(self: Effect<A, E, R>, k: K, f: (e: Extract<E, {
6833
- _tag: K;
6834
- }>) => Effect<A1, E1, R1>): Effect<A | A1, E1 | Exclude<E, {
6835
- _tag: K;
6836
- }>, R | R1>;
6832
+ } ? E["_tag"] : never>, R1, E1, A1>(self: Effect<A, E, R>, ...args: [...tags: K, f: (e: Extract<NoInfer<E>, {
6833
+ _tag: K[number];
6834
+ }>) => Effect<A1, E1, R1>]): Effect<A | A1, Exclude<E, {
6835
+ _tag: K[number];
6836
+ }> | E1, R | R1>;
6837
6837
  };
6838
6838
  /**
6839
6839
  * Handles multiple errors in a single block of code using their `_tag` field.
@@ -8852,51 +8852,7 @@ export declare const liftPredicate: {
8852
8852
  * @category Condition Checking
8853
8853
  * @since 3.4.0
8854
8854
  */
8855
- <A, B extends A, E>(refinement: Refinement<A, B>, orFailWith: (a: A) => E): (a: A) => Effect<B, E>;
8856
- /**
8857
- * Transforms a `Predicate` function into an `Effect` returning the input value if the predicate returns `true`
8858
- * or failing with specified error if the predicate fails
8859
- *
8860
- * **Example**
8861
- *
8862
- * ```ts
8863
- * import { Effect } from "effect"
8864
- *
8865
- * const isPositive = (n: number): boolean => n > 0
8866
- *
8867
- * // succeeds with `1`
8868
- * Effect.liftPredicate(1, isPositive, n => `${n} is not positive`)
8869
- *
8870
- * // fails with `"0 is not positive"`
8871
- * Effect.liftPredicate(0, isPositive, n => `${n} is not positive`)
8872
- * ```
8873
- *
8874
- * @category Condition Checking
8875
- * @since 3.4.0
8876
- */
8877
- <B extends A, E, A = B>(predicate: Predicate<A>, orFailWith: (a: A) => E): (a: B) => Effect<B, E>;
8878
- /**
8879
- * Transforms a `Predicate` function into an `Effect` returning the input value if the predicate returns `true`
8880
- * or failing with specified error if the predicate fails
8881
- *
8882
- * **Example**
8883
- *
8884
- * ```ts
8885
- * import { Effect } from "effect"
8886
- *
8887
- * const isPositive = (n: number): boolean => n > 0
8888
- *
8889
- * // succeeds with `1`
8890
- * Effect.liftPredicate(1, isPositive, n => `${n} is not positive`)
8891
- *
8892
- * // fails with `"0 is not positive"`
8893
- * Effect.liftPredicate(0, isPositive, n => `${n} is not positive`)
8894
- * ```
8895
- *
8896
- * @category Condition Checking
8897
- * @since 3.4.0
8898
- */
8899
- <A, E, B extends A>(self: A, refinement: Refinement<A, B>, orFailWith: (a: A) => E): Effect<B, E>;
8855
+ <T extends A, E, B extends T = T, A = T>(predicate: Refinement<T, B> | Predicate<T>, orFailWith: (a: EqualsWith<T, B, A, Exclude<A, B>>) => E): (a: A) => Effect<EqualsWith<T, B, A, B>, E>;
8900
8856
  /**
8901
8857
  * Transforms a `Predicate` function into an `Effect` returning the input value if the predicate returns `true`
8902
8858
  * or failing with specified error if the predicate fails
@@ -8918,7 +8874,7 @@ export declare const liftPredicate: {
8918
8874
  * @category Condition Checking
8919
8875
  * @since 3.4.0
8920
8876
  */
8921
- <B extends A, E, A = B>(self: B, predicate: Predicate<A>, orFailWith: (a: A) => E): Effect<B, E>;
8877
+ <A, E, B extends A = A>(self: A, predicate: Refinement<A, B> | Predicate<A>, orFailWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => E): Effect<B, E>;
8922
8878
  };
8923
8879
  /**
8924
8880
  * Replaces the value inside an effect with a constant value.
@@ -15570,43 +15526,7 @@ export declare const filterOrDie: {
15570
15526
  * @since 2.0.0
15571
15527
  * @category Filtering
15572
15528
  */
15573
- <A, B extends A>(refinement: Refinement<NoInfer<A>, B>, orDieWith: (a: NoInfer<A>) => unknown): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>;
15574
- /**
15575
- * Filters an effect, dying with a custom defect if the predicate fails.
15576
- *
15577
- * **Details**
15578
- *
15579
- * This function applies a predicate to the result of an effect. If the
15580
- * predicate evaluates to `false`, the effect dies with a custom defect
15581
- * generated by the `orDieWith` function.
15582
- *
15583
- * **When to Use**
15584
- *
15585
- * This is useful for enforcing constraints on values and treating violations as
15586
- * fatal program errors.
15587
- *
15588
- * @since 2.0.0
15589
- * @category Filtering
15590
- */
15591
- <A>(predicate: Predicate<NoInfer<A>>, orDieWith: (a: NoInfer<A>) => unknown): <E, R>(self: Effect<A, E, R>) => Effect<A, E, R>;
15592
- /**
15593
- * Filters an effect, dying with a custom defect if the predicate fails.
15594
- *
15595
- * **Details**
15596
- *
15597
- * This function applies a predicate to the result of an effect. If the
15598
- * predicate evaluates to `false`, the effect dies with a custom defect
15599
- * generated by the `orDieWith` function.
15600
- *
15601
- * **When to Use**
15602
- *
15603
- * This is useful for enforcing constraints on values and treating violations as
15604
- * fatal program errors.
15605
- *
15606
- * @since 2.0.0
15607
- * @category Filtering
15608
- */
15609
- <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Refinement<A, B>, orDieWith: (a: A) => unknown): Effect<B, E, R>;
15529
+ <A, B extends A = A>(predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>, orDieWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => unknown): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>;
15610
15530
  /**
15611
15531
  * Filters an effect, dying with a custom defect if the predicate fails.
15612
15532
  *
@@ -15624,7 +15544,7 @@ export declare const filterOrDie: {
15624
15544
  * @since 2.0.0
15625
15545
  * @category Filtering
15626
15546
  */
15627
- <A, E, R>(self: Effect<A, E, R>, predicate: Predicate<A>, orDieWith: (a: A) => unknown): Effect<A, E, R>;
15547
+ <A, E, R, B extends A>(self: Effect<A, E, R>, predicate: Predicate<A> | Refinement<A, B>, orDieWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => unknown): Effect<B, E, R>;
15628
15548
  };
15629
15549
  /**
15630
15550
  * Filters an effect, dying with a custom message if the predicate fails.
@@ -15651,33 +15571,7 @@ export declare const filterOrDieMessage: {
15651
15571
  * @since 2.0.0
15652
15572
  * @category Filtering
15653
15573
  */
15654
- <A, B extends A>(refinement: Refinement<NoInfer<A>, B>, message: string): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>;
15655
- /**
15656
- * Filters an effect, dying with a custom message if the predicate fails.
15657
- *
15658
- * **Details**
15659
- *
15660
- * This function works like {@link filterOrDie} but allows you to specify a
15661
- * custom error message to describe the reason for the failure. The message is
15662
- * included in the defect when the predicate evaluates to `false`.
15663
- *
15664
- * @since 2.0.0
15665
- * @category Filtering
15666
- */
15667
- <A>(predicate: Predicate<NoInfer<A>>, message: string): <E, R>(self: Effect<A, E, R>) => Effect<A, E, R>;
15668
- /**
15669
- * Filters an effect, dying with a custom message if the predicate fails.
15670
- *
15671
- * **Details**
15672
- *
15673
- * This function works like {@link filterOrDie} but allows you to specify a
15674
- * custom error message to describe the reason for the failure. The message is
15675
- * included in the defect when the predicate evaluates to `false`.
15676
- *
15677
- * @since 2.0.0
15678
- * @category Filtering
15679
- */
15680
- <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Refinement<A, B>, message: string): Effect<B, E, R>;
15574
+ <A, B extends A = A>(predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>, message: string): <E, R>(self: Effect<A, E, R>) => Effect<B, E, R>;
15681
15575
  /**
15682
15576
  * Filters an effect, dying with a custom message if the predicate fails.
15683
15577
  *
@@ -15690,7 +15584,7 @@ export declare const filterOrDieMessage: {
15690
15584
  * @since 2.0.0
15691
15585
  * @category Filtering
15692
15586
  */
15693
- <A, E, R>(self: Effect<A, E, R>, predicate: Predicate<A>, message: string): Effect<A, E, R>;
15587
+ <A, E, R, B extends A = A>(self: Effect<A, E, R>, predicate: Predicate<A> | Refinement<A, B>, message: string): Effect<B, E, R>;
15694
15588
  };
15695
15589
  /**
15696
15590
  * Filters an effect, providing an alternative effect if the predicate fails.
@@ -15719,35 +15613,7 @@ export declare const filterOrElse: {
15719
15613
  * @since 2.0.0
15720
15614
  * @category Filtering
15721
15615
  */
15722
- <A, B extends A, C, E2, R2>(refinement: Refinement<NoInfer<A>, B>, orElse: (a: NoInfer<A>) => Effect<C, E2, R2>): <E, R>(self: Effect<A, E, R>) => Effect<B | C, E2 | E, R2 | R>;
15723
- /**
15724
- * Filters an effect, providing an alternative effect if the predicate fails.
15725
- *
15726
- * **Details**
15727
- *
15728
- * This function applies a predicate to the result of an effect. If the
15729
- * predicate evaluates to `false`, it executes the `orElse` effect instead. The
15730
- * `orElse` effect can produce an alternative value or perform additional
15731
- * computations.
15732
- *
15733
- * @since 2.0.0
15734
- * @category Filtering
15735
- */
15736
- <A, B, E2, R2>(predicate: Predicate<NoInfer<A>>, orElse: (a: NoInfer<A>) => Effect<B, E2, R2>): <E, R>(self: Effect<A, E, R>) => Effect<A | B, E2 | E, R2 | R>;
15737
- /**
15738
- * Filters an effect, providing an alternative effect if the predicate fails.
15739
- *
15740
- * **Details**
15741
- *
15742
- * This function applies a predicate to the result of an effect. If the
15743
- * predicate evaluates to `false`, it executes the `orElse` effect instead. The
15744
- * `orElse` effect can produce an alternative value or perform additional
15745
- * computations.
15746
- *
15747
- * @since 2.0.0
15748
- * @category Filtering
15749
- */
15750
- <A, E, R, B extends A, C, E2, R2>(self: Effect<A, E, R>, refinement: Refinement<A, B>, orElse: (a: A) => Effect<C, E2, R2>): Effect<B | C, E | E2, R | R2>;
15616
+ <A, C, E2, R2, B extends A = A>(predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>, orElse: (a: EqualsWith<A, B, NoInfer<A>, Exclude<NoInfer<A>, B>>) => Effect<C, E2, R2>): <E, R>(self: Effect<A, E, R>) => Effect<B | C, E2 | E, R2 | R>;
15751
15617
  /**
15752
15618
  * Filters an effect, providing an alternative effect if the predicate fails.
15753
15619
  *
@@ -15761,7 +15627,7 @@ export declare const filterOrElse: {
15761
15627
  * @since 2.0.0
15762
15628
  * @category Filtering
15763
15629
  */
15764
- <A, E, R, B, E2, R2>(self: Effect<A, E, R>, predicate: Predicate<A>, orElse: (a: A) => Effect<B, E2, R2>): Effect<A | B, E | E2, R | R2>;
15630
+ <A, E, R, C, E2, R2, B extends A = A>(self: Effect<A, E, R>, predicate: Predicate<A> | Refinement<A, B>, orElse: (a: EqualsWith<A, B, A, Exclude<A, B>>) => Effect<C, E2, R2>): Effect<B | C, E | E2, R | R2>;
15765
15631
  };
15766
15632
  /**
15767
15633
  * Filters an effect, failing with a custom error if the predicate fails.
@@ -15864,211 +15730,7 @@ export declare const filterOrFail: {
15864
15730
  * @since 2.0.0
15865
15731
  * @category Filtering
15866
15732
  */
15867
- <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>;
15868
- /**
15869
- * Filters an effect, failing with a custom error if the predicate fails.
15870
- *
15871
- * **Details**
15872
- *
15873
- * This function applies a predicate to the result of an effect. If the
15874
- * predicate evaluates to `false`, the effect fails with a custom error
15875
- * generated by the `orFailWith` function.
15876
- *
15877
- * **When to Use**
15878
- *
15879
- * This is useful for enforcing constraints and treating violations as
15880
- * recoverable errors.
15881
- *
15882
- * **Providing a Guard**
15883
- *
15884
- * In addition to the filtering capabilities discussed earlier, you have the
15885
- * option to further refine and narrow down the type of the success channel by
15886
- * providing a [user-defined type
15887
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
15888
- * Let's explore this concept through an example:
15889
- *
15890
- * **Example**
15891
- *
15892
- * ```ts
15893
- * import { Effect, pipe } from "effect"
15894
- *
15895
- * // Define a user interface
15896
- * interface User {
15897
- * readonly name: string
15898
- * }
15899
- *
15900
- * // Simulate an asynchronous authentication function
15901
- * declare const auth: () => Promise<User | null>
15902
- *
15903
- * const program = pipe(
15904
- * Effect.promise(() => auth()),
15905
- * // Use filterOrFail with a custom type guard to ensure user is not null
15906
- * Effect.filterOrFail(
15907
- * (user): user is User => user !== null, // Type guard
15908
- * () => new Error("Unauthorized")
15909
- * ),
15910
- * // 'user' now has the type `User` (not `User | null`)
15911
- * Effect.andThen((user) => user.name)
15912
- * )
15913
- * ```
15914
- *
15915
- * @since 2.0.0
15916
- * @category Filtering
15917
- */
15918
- <A, E2>(predicate: Predicate<NoInfer<A>>, orFailWith: (a: NoInfer<A>) => E2): <E, R>(self: Effect<A, E, R>) => Effect<A, E2 | E, R>;
15919
- /**
15920
- * Filters an effect, failing with a custom error if the predicate fails.
15921
- *
15922
- * **Details**
15923
- *
15924
- * This function applies a predicate to the result of an effect. If the
15925
- * predicate evaluates to `false`, the effect fails with a custom error
15926
- * generated by the `orFailWith` function.
15927
- *
15928
- * **When to Use**
15929
- *
15930
- * This is useful for enforcing constraints and treating violations as
15931
- * recoverable errors.
15932
- *
15933
- * **Providing a Guard**
15934
- *
15935
- * In addition to the filtering capabilities discussed earlier, you have the
15936
- * option to further refine and narrow down the type of the success channel by
15937
- * providing a [user-defined type
15938
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
15939
- * Let's explore this concept through an example:
15940
- *
15941
- * **Example**
15942
- *
15943
- * ```ts
15944
- * import { Effect, pipe } from "effect"
15945
- *
15946
- * // Define a user interface
15947
- * interface User {
15948
- * readonly name: string
15949
- * }
15950
- *
15951
- * // Simulate an asynchronous authentication function
15952
- * declare const auth: () => Promise<User | null>
15953
- *
15954
- * const program = pipe(
15955
- * Effect.promise(() => auth()),
15956
- * // Use filterOrFail with a custom type guard to ensure user is not null
15957
- * Effect.filterOrFail(
15958
- * (user): user is User => user !== null, // Type guard
15959
- * () => new Error("Unauthorized")
15960
- * ),
15961
- * // 'user' now has the type `User` (not `User | null`)
15962
- * Effect.andThen((user) => user.name)
15963
- * )
15964
- * ```
15965
- *
15966
- * @since 2.0.0
15967
- * @category Filtering
15968
- */
15969
- <A, B extends A>(refinement: Refinement<NoInfer<A>, B>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementException | E, R>;
15970
- /**
15971
- * Filters an effect, failing with a custom error if the predicate fails.
15972
- *
15973
- * **Details**
15974
- *
15975
- * This function applies a predicate to the result of an effect. If the
15976
- * predicate evaluates to `false`, the effect fails with a custom error
15977
- * generated by the `orFailWith` function.
15978
- *
15979
- * **When to Use**
15980
- *
15981
- * This is useful for enforcing constraints and treating violations as
15982
- * recoverable errors.
15983
- *
15984
- * **Providing a Guard**
15985
- *
15986
- * In addition to the filtering capabilities discussed earlier, you have the
15987
- * option to further refine and narrow down the type of the success channel by
15988
- * providing a [user-defined type
15989
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
15990
- * Let's explore this concept through an example:
15991
- *
15992
- * **Example**
15993
- *
15994
- * ```ts
15995
- * import { Effect, pipe } from "effect"
15996
- *
15997
- * // Define a user interface
15998
- * interface User {
15999
- * readonly name: string
16000
- * }
16001
- *
16002
- * // Simulate an asynchronous authentication function
16003
- * declare const auth: () => Promise<User | null>
16004
- *
16005
- * const program = pipe(
16006
- * Effect.promise(() => auth()),
16007
- * // Use filterOrFail with a custom type guard to ensure user is not null
16008
- * Effect.filterOrFail(
16009
- * (user): user is User => user !== null, // Type guard
16010
- * () => new Error("Unauthorized")
16011
- * ),
16012
- * // 'user' now has the type `User` (not `User | null`)
16013
- * Effect.andThen((user) => user.name)
16014
- * )
16015
- * ```
16016
- *
16017
- * @since 2.0.0
16018
- * @category Filtering
16019
- */
16020
- <A>(predicate: Predicate<NoInfer<A>>): <E, R>(self: Effect<A, E, R>) => Effect<A, Cause.NoSuchElementException | E, R>;
16021
- /**
16022
- * Filters an effect, failing with a custom error if the predicate fails.
16023
- *
16024
- * **Details**
16025
- *
16026
- * This function applies a predicate to the result of an effect. If the
16027
- * predicate evaluates to `false`, the effect fails with a custom error
16028
- * generated by the `orFailWith` function.
16029
- *
16030
- * **When to Use**
16031
- *
16032
- * This is useful for enforcing constraints and treating violations as
16033
- * recoverable errors.
16034
- *
16035
- * **Providing a Guard**
16036
- *
16037
- * In addition to the filtering capabilities discussed earlier, you have the
16038
- * option to further refine and narrow down the type of the success channel by
16039
- * providing a [user-defined type
16040
- * guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates).
16041
- * Let's explore this concept through an example:
16042
- *
16043
- * **Example**
16044
- *
16045
- * ```ts
16046
- * import { Effect, pipe } from "effect"
16047
- *
16048
- * // Define a user interface
16049
- * interface User {
16050
- * readonly name: string
16051
- * }
16052
- *
16053
- * // Simulate an asynchronous authentication function
16054
- * declare const auth: () => Promise<User | null>
16055
- *
16056
- * const program = pipe(
16057
- * Effect.promise(() => auth()),
16058
- * // Use filterOrFail with a custom type guard to ensure user is not null
16059
- * Effect.filterOrFail(
16060
- * (user): user is User => user !== null, // Type guard
16061
- * () => new Error("Unauthorized")
16062
- * ),
16063
- * // 'user' now has the type `User` (not `User | null`)
16064
- * Effect.andThen((user) => user.name)
16065
- * )
16066
- * ```
16067
- *
16068
- * @since 2.0.0
16069
- * @category Filtering
16070
- */
16071
- <A, E, R, B extends A, E2>(self: Effect<A, E, R>, refinement: Refinement<A, B>, orFailWith: (a: A) => E2): Effect<B, E | E2, R>;
15733
+ <A, E2, B extends A = A>(predicate: Predicate<NoInfer<A>> | Refinement<NoInfer<A>, B>, orFailWith: (a: EqualsWith<A, B, NoInfer<A>, Exclude<NoInfer<A>, B>>) => E2): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>;
16072
15734
  /**
16073
15735
  * Filters an effect, failing with a custom error if the predicate fails.
16074
15736
  *
@@ -16119,7 +15781,7 @@ export declare const filterOrFail: {
16119
15781
  * @since 2.0.0
16120
15782
  * @category Filtering
16121
15783
  */
16122
- <A, E, R, E2>(self: Effect<A, E, R>, predicate: Predicate<A>, orFailWith: (a: A) => E2): Effect<A, E | E2, R>;
15784
+ <A, E, R, E2, B extends A = A>(self: Effect<A, E, R>, predicate: Predicate<A> | Refinement<A, B>, orFailWith: (a: EqualsWith<A, B, A, Exclude<A, B>>) => E2): Effect<B, E2 | E, R>;
16123
15785
  /**
16124
15786
  * Filters an effect, failing with a custom error if the predicate fails.
16125
15787
  *
@@ -16170,7 +15832,7 @@ export declare const filterOrFail: {
16170
15832
  * @since 2.0.0
16171
15833
  * @category Filtering
16172
15834
  */
16173
- <A, E, R, B extends A>(self: Effect<A, E, R>, refinement: Refinement<A, B>): Effect<B, E | Cause.NoSuchElementException, R>;
15835
+ <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>;
16174
15836
  /**
16175
15837
  * Filters an effect, failing with a custom error if the predicate fails.
16176
15838
  *
@@ -16221,7 +15883,7 @@ export declare const filterOrFail: {
16221
15883
  * @since 2.0.0
16222
15884
  * @category Filtering
16223
15885
  */
16224
- <A, E, R>(self: Effect<A, E, R>, predicate: Predicate<A>): Effect<A, E | Cause.NoSuchElementException, R>;
15886
+ <A, E, R, B extends A = A>(self: Effect<A, E, R>, predicate: Predicate<A> | Refinement<A, B>): Effect<B, E | Cause.NoSuchElementException, R>;
16225
15887
  };
16226
15888
  /**
16227
15889
  * Filters an effect with an effectful predicate, falling back to an alternative