Hyperlinkv0.8.0-beta.28

Effect

Effect.bindconsteffect/Effect.ts:1341
<N extends string, A extends Record<string, any>, B, E2, R2>(
  name: N,
  f: (a: NoInfer<A>) => Effect<B, E2, R2>
): <E, R>(
  self: Effect<A, E, R>
) => Effect<Simplify<Omit<A, N> & Record<N, B>>, E | E2, R | R2>
<A extends Record<string, any>, E, R, B, E2, R2, N extends string>(
  self: Effect<A, E, R>,
  name: N,
  f: (a: NoInfer<A>) => Effect<B, E2, R2>
): Effect<Simplify<Omit<A, N> & Record<N, B>>, E | E2, R | R2>

Adds an Effect value to the do notation record under a given name.

When to use

Use to sequence an effectful step in a do-notation pipeline when that step depends on fields already accumulated in the record and its success value should be stored under a name.

Details

The function receives the current record, runs the returned effect after the input effect succeeds, and inserts its success value under name. The resulting effect combines the error and service requirements of both steps.

Gotchas

Binding a name that already exists replaces that field in the resulting record.

do notationDobindTogen
Source effect/Effect.ts:134113 lines
export const bind: {
  <N extends string, A extends Record<string, any>, B, E2, R2>(
    name: N,
    f: (a: NoInfer<A>) => Effect<B, E2, R2>
  ): <E, R>(
    self: Effect<A, E, R>
  ) => Effect<Simplify<Omit<A, N> & Record<N, B>>, E | E2, R | R2>
  <A extends Record<string, any>, E, R, B, E2, R2, N extends string>(
    self: Effect<A, E, R>,
    name: N,
    f: (a: NoInfer<A>) => Effect<B, E2, R2>
  ): Effect<Simplify<Omit<A, N> & Record<N, B>>, E | E2, R | R2>
} = internal.bind