Hyperlinkv0.8.0-beta.28

Context

Context.getconsteffect/Context.ts:927
<Services, I extends Services, S>(service: Key<I, S>): (
  self: Context<Services>
) => S
<Services, I extends Services, S>(
  self: Context<Services>,
  service: Key<I, S>
): S

Gets a service from the context that corresponds to the given key.

When to use

Use when you need type-checked access to a service already included in the context type.

Example (Getting a service from a context)

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

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

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

assert.deepStrictEqual(Context.get(context, Timeout), { TIMEOUT: 5000 })
Source effect/Context.ts:9274 lines
export const get: {
  <Services, I extends Services, S>(service: Key<I, S>): (self: Context<Services>) => S
  <Services, I extends Services, S>(self: Context<Services>, service: Key<I, S>): S
} = getUnsafe
Referenced by 15 symbols