Using Generators Directly in Effect Service Methods

How did I not know that this worked? Is it intentional? I don't see it in documentation, and it's much cleaner than what I was doing before:

class MyService extends Effect.Service<MyService>()(
  "MyService",
  {
    effect: Effect.gen(function*() {
      const terminal = yield* Terminal.Terminal

      return {
        *sayHello(name: string) {
          yield* terminal.display(`Hello, ${name}`)
        }
      }
    }
  }
) {}


Whereas I have been doing this for a long time:

class MyService extends Effect.Service<MyService>()(
  "MyService",
  {
    effect: Effect.gen(function*() {
      const terminal = yield* Terminal.Terminal

      return {
        sayHello(name: string) {
          return Effect.gen(this, function*() {
            yield* terminal.display(`Hello, ${name}`)
          }
        }
      }
    }
  }
) {}
Was this page helpful?