Hyperlinkv0.8.0-beta.28

Effect

Effect.mapBothEagerconsteffect/Effect.ts:15316
<E, E2, A, A2>(options: {
  readonly onFailure: (e: E) => E2
  readonly onSuccess: (a: A) => A2
}): <R>(self: Effect<A, E, R>) => Effect<A2, E2, R>
<A, E, R, E2, A2>(
  self: Effect<A, E, R>,
  options: {
    readonly onFailure: (e: E) => E2
    readonly onSuccess: (a: A) => A2
  }
): Effect<A2, E2, R>

Applies mapBoth eagerly when an effect is already resolved.

When to use

Use when an already-resolved effect should transform either success or failure immediately while pending effects still use regular channel mapping.

Details

Success effects apply onSuccess immediately, and failure effects apply onFailure immediately. Pending effects fall back to regular mapBoth behavior.

Example (Mapping both channels eagerly when possible)

import { Effect } from "effect"

// For resolved effects, the appropriate mapping is applied immediately
const success = Effect.succeed(5)
const mapped = Effect.mapBothEager(success, {
  onFailure: (err: string) => `Failed: ${err}`,
  onSuccess: (n: number) => n * 2
}) // onSuccess applied eagerly

const failure = Effect.fail("error")
const mappedError = Effect.mapBothEager(failure, {
  onFailure: (err: string) => `Failed: ${err}`,
  onSuccess: (n: number) => n * 2
}) // onFailure applied eagerly
eager
export const mapBothEager: {
  <E, E2, A, A2>(
    options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
  ): <R>(self: Effect<A, E, R>) => Effect<A2, E2, R>
  <A, E, R, E2, A2>(
    self: Effect<A, E, R>,
    options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
  ): Effect<A2, E2, R>
} = internal.mapBothEager
Referenced by 12 symbols