Hyperlinkv0.8.0-beta.28

Context

Context.mutateconsteffect/Context.ts:1267
<Services, B>(f: (context: Context<Services>) => Context<B>): <Services>(
  self: Context<Services>
) => Context<B>
<Services, B>(
  self: Context<Services>,
  f: (context: Context<Services>) => Context<B>
): Context<B>

Performs a series of mutations on a Context. Prevents unnecessary copying of the underlying map when multiple mutations are needed.

When to use

Use to apply several Context transformations in one callback while copying the underlying service map only once.

Source effect/Context.ts:126715 lines
export const mutate: {
  <Services, B>(
    f: (context: Context<Services>) => Context<B>
  ): <Services>(self: Context<Services>) => Context<B>
  <Services, B>(self: Context<Services>, f: (context: Context<Services>) => Context<B>): Context<B>
} = dual(
  2,
  <Services, B>(self: Context<Services>, f: (context: Context<Services>) => Context<B>): Context<B> => {
    const next = makeUnsafe<Services>(new Map(self.mapUnsafe))
    next.mutable = true
    const result = f(next)
    result.mutable = false
    return result
  }
)
Referenced by 1 symbols