Default Services
Effect comes equipped with five pre-built services:
type DefaultServices = Clock | ConfigProvider | Console | Random | Tracer
When we employ these services, there’s no need to explicitly provide their implementations. Effect automatically supplies live versions of these services to our effects, sparing us from manual setup.
1import { import Effect
Effect, import Clock
Clock, import Console
Console } from "effect"2
3const const program: Effect.Effect<void, never, never>
program = import Effect
Effect.const gen: <YieldWrap<Effect.Effect<void, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<void, never, never>>, void, never>) => Effect.Effect<...> (+1 overload)
gen(function* () {4 const const now: number
now = yield* import Clock
Clock.const currentTimeMillis: Effect.Effect<number, never, never>
currentTimeMillis5 yield* import Console
Console.const log: (...args: ReadonlyArray<any>) => Effect.Effect<void>
log(`Application started at ${new var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date(const now: number
now)}`)6})
As you can observe, even if our program utilizes both Clock
and Console
, the Requirements
parameter, representing the services required for the effect to execute, remains set to never
.
Effect takes care of handling these services seamlessly for us.