effect 4.0.0-beta.0 → 4.0.0-beta.2

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/Effect.d.ts CHANGED
@@ -4704,6 +4704,33 @@ export declare const catchIf: {
4704
4704
  */
4705
4705
  <A, E, R, Result extends Filter.ResultOrBool, A2, E2, R2, A3 = never, E3 = Filter.Fail<E, Result>, R3 = never>(self: Effect<A, E, R>, filter: Filter.OrPredicate<NoInfer<E>, Result>, f: (e: Filter.Pass<E, Result>) => Effect<A2, E2, R2>, orElse?: ((e: Filter.Fail<E, Result>) => Effect<A3, E3, R3>) | undefined): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>;
4706
4706
  };
4707
+ /**
4708
+ * Catches `NoSuchElementError` failures and converts them to `Option.none`.
4709
+ *
4710
+ * Success values become `Option.some`, `NoSuchElementError` becomes
4711
+ * `Option.none`, and all other errors are preserved.
4712
+ *
4713
+ * @example
4714
+ * ```ts
4715
+ * import { Effect, Option } from "effect"
4716
+ *
4717
+ * const some = Effect.fromNullishOr(1).pipe(Effect.catchNoSuchElement)
4718
+ * const none = Effect.fromNullishOr(null).pipe(Effect.catchNoSuchElement)
4719
+ *
4720
+ * Effect.runPromise(some).then(console.log) // { _id: 'Option', _tag: 'Some', value: 1 }
4721
+ * Effect.runPromise(none).then(console.log) // { _id: 'Option', _tag: 'None' }
4722
+ * ```
4723
+ *
4724
+ * **Previously Known As**
4725
+ *
4726
+ * This API replaces the following from Effect 3.x:
4727
+ *
4728
+ * - `Effect.optionFromOptional`
4729
+ *
4730
+ * @since 2.0.0
4731
+ * @category Error Handling
4732
+ */
4733
+ export declare const catchNoSuchElement: <A, E, R>(self: Effect<A, E, R>) => Effect<Option<A>, Exclude<E, Cause.NoSuchElementError>, R>;
4707
4734
  /**
4708
4735
  * Recovers from specific failures based on a predicate.
4709
4736
  *
@@ -7433,6 +7460,32 @@ export declare const filter: {
7433
7460
  * @category Filtering
7434
7461
  */
7435
7462
  <A>(predicate: Predicate.Predicate<NoInfer<A>>): (elements: Iterable<A>) => Effect<Array<A>>;
7463
+ /**
7464
+ * Filters elements of an iterable using a predicate, refinement, effectful
7465
+ * predicate, or `Filter.FilterEffect`.
7466
+ *
7467
+ * @example
7468
+ * ```ts
7469
+ * import { Effect, Filter, Result } from "effect"
7470
+ *
7471
+ * // Sync predicate
7472
+ * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
7473
+ *
7474
+ * // Effectful predicate
7475
+ * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
7476
+ *
7477
+ * // FilterEffect
7478
+ * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
7479
+ * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
7480
+ * )
7481
+ * ```
7482
+ *
7483
+ * @since 2.0.0
7484
+ * @category Filtering
7485
+ */
7486
+ <A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>, options?: {
7487
+ readonly concurrency?: Concurrency | undefined;
7488
+ }): (elements: Iterable<A>) => Effect<Array<B>>;
7436
7489
  /**
7437
7490
  * Filters elements of an iterable using a predicate, refinement, effectful
7438
7491
  * predicate, or `Filter.FilterEffect`.
@@ -7533,6 +7586,30 @@ export declare const filter: {
7533
7586
  * @category Filtering
7534
7587
  */
7535
7588
  <A>(elements: Iterable<A>, predicate: Predicate.Predicate<A>): Effect<Array<A>>;
7589
+ /**
7590
+ * Filters elements of an iterable using a predicate, refinement, effectful
7591
+ * predicate, or `Filter.FilterEffect`.
7592
+ *
7593
+ * @example
7594
+ * ```ts
7595
+ * import { Effect, Filter, Result } from "effect"
7596
+ *
7597
+ * // Sync predicate
7598
+ * const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
7599
+ *
7600
+ * // Effectful predicate
7601
+ * const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
7602
+ *
7603
+ * // FilterEffect
7604
+ * const mapped = Effect.filter([1, 2, 3, 4], (n) =>
7605
+ * Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
7606
+ * )
7607
+ * ```
7608
+ *
7609
+ * @since 2.0.0
7610
+ * @category Filtering
7611
+ */
7612
+ <A, B, X>(elements: Iterable<A>, filter: Filter.Filter<NoInfer<A>, B, X>): Effect<Array<B>>;
7536
7613
  /**
7537
7614
  * Filters elements of an iterable using a predicate, refinement, effectful
7538
7615
  * predicate, or `Filter.FilterEffect`.