Hyperlinkv0.8.0-beta.28

Context

Context.omitconsteffect/Context.ts:1239
<S extends ReadonlyArray<Key<any, any>>>(...keys: S): <Services>(
  self: Context<Services>
) => Context<Exclude<Services, Service.Identifier<S[number]>>>

Returns a new Context with the specified service keys removed.

When to use

Use when you want to remove a denylist of services from a Context.

Example (Omitting services from a context)

import { Context, Option, pipe } from "effect"
import * as assert from "node:assert"

const Port = Context.Service<{ PORT: number }>("Port")
const Timeout = Context.Service<{ TIMEOUT: number }>("Timeout")

const someContext = pipe(
  Context.make(Port, { PORT: 8080 }),
  Context.add(Timeout, { TIMEOUT: 5000 })
)

const context = pipe(someContext, Context.omit(Timeout))

assert.deepStrictEqual(
  Context.getOption(context, Port),
  Option.some({ PORT: 8080 })
)
assert.deepStrictEqual(Context.getOption(context, Timeout), Option.none())
filteringpick
export const omit = <S extends ReadonlyArray<Key<any, any>>>(
  ...keys: S
) =>
<Services>(self: Context<Services>): Context<Exclude<Services, Service.Identifier<S[number]>>> =>
  withMapUnsafe(self, (map) => {
    for (let i = 0; i < keys.length; i++) {
      map.delete(keys[i].key)
    }
  })
Referenced by 1 symbols