Import
import { provideService } from "@typed/guard";Signatures
export declare const provideService: {
<Id, S>(tag: Context.Service<Id, S>, service: S): <I, O, E, R>(guard: GuardInput<I, O, E, R>) => Guard<I, O, E, Exclude<R, Id>>;
<I, O, E, R, Id, S>(guard: GuardInput<I, O, E, R>, tag: Context.Service<Id, S>, service: S): Guard<I, O, E, Exclude<R, Id>>;
};Why
Targeted service provision removes only the selected identifier from the Guard environment.
Ownership and lifetime
This combinator acquires no resources and reuses the supplied service for each invocation.
Examples
import { provideService } from "@typed/guard"
import type { Guard } from "@typed/guard"
import { Context, Effect, Option } from "effect"
const Flag = Context.Service<{ readonly enabled: boolean }>("Flag")
const requiresFlag: Guard<boolean, boolean, never, Context.Service.Identifier<typeof Flag>> = (input) => Effect.map(Effect.service(Flag), ({ enabled }) => enabled && input ? Option.some(input) : Option.none())
const guard = provideService(requiresFlag, Flag, { enabled: true })