Effect CommunityEC
Effect Community3y ago
5 replies
whatplan

The purpose of `Tag.of()` in `Effect.provideService`

What is the purpose of Tag.of()?

in Effect.provideService for example:
interface Random {
  readonly next: () => Effect.Effect<never, never, number>;
}
const Random = Context.Tag<Random>();
Effect.provideService(
  Random,
  // works
  Random.of({ next: () => Effect.succeed(Math.random()) })
  // just the value also works
  // { next: () => Effect.succeed(Math.random()) }
)

the source code is just
of(self: Service): Service {
    return self
}

So is it just a explicitness thing? Is it 'idiomatic' effect to always use Tag.of() when providing an instance of the tagged type?
Was this page helpful?