Effect CommunityEC
Effect Community3y ago
15 replies
Nomadin

Using `CacheTag` from `effect/io` in `Context.Tag`

One of my Layer depends on an arbitrary cache/storage implementation. I could define MyCache interface on my own and make it Context.Tag<MyCache> and use it in my Layer, but I wonder if I can put the
Cache
interface from effect/io into Context.Tag, rather than re-inventing the interface.

import { Cache, Layer, Effect } from 'effect'

const CacheTag = Context.Tag<Cache>();

const MyAwesomLayer = Layer.effect(
   pipe(
     CacheTag,
     Effect.map((cache) => /* magic */)
   )
)
Was this page helpful?