effect-io-ai

Package: effect
Module: Context

Context.get

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 })

See

Signature

declare 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; }

Source

Since v2.0.0