Yielding Class Instances in Effect Framework

I'm reading the docs and I'm a little confused by the services example.

// Create a 'Tag' for the 'Random' service
class Random extends Context.Tag("Random")<
  Random,
  {
    readonly next: Effect.Effect<number>
  }
>() {}
 
// Create a 'Tag' for the 'Logger' service
class Logger extends Context.Tag("Logger")<
  Logger,
  {
    readonly log: (message: string) => Effect.Effect<void>
  }
>() {}
 
const program = Effect.gen(function* () {
  // Acquire instances of the 'Random' and 'Logger' services
  const random = yield* Random // <----- What is this sorcery?
  const logger = yield* Logger // <----- What is this sorcery?
 
  // Generate a random number using the 'Random' service
  const randomNumber = yield* random.next
 
  // Log the random number using the 'Logger' service
  return yield* logger.log(String(randomNumber))
})


The part where you get instances of a class by yielding them looks like black magic.
What is this sorcery? Can someone explain how that works? 🧙🏻‍♂️
Was this page helpful?