module Polysemy.Reader.Compact where
import Polysemy
import Polysemy.Reader
import Data.Compact
runReaderWithCompacted
:: forall r i a
. Member (Embed IO) r
=> i
-> Sem (Reader i ': r) a
-> Sem r a
runReaderWithCompacted i sem = do
compacted <- embed (compactWithSharing i)
runReaderWithExistingCompacted compacted sem
{-# INLINE runReaderWithCompacted #-}
runReaderWithExistingCompacted
:: forall r i a
. Member (Embed IO) r
=> Compact i
-> Sem (Reader i ': r) a
-> Sem r a
runReaderWithExistingCompacted i = interpretH $ \case
Ask -> pureT (getCompact i)
Local f m -> do
mm <- runT m
let transformed = f (getCompact i)
raise $ runReaderWithCompacted transformed mm
{-# INLINE runReaderWithExistingCompacted #-}