module Imm.Hooks where
import Imm.Feed
import Imm.Logger
import Imm.Prelude
import Imm.Pretty
import Control.Monad.Free.Class
data HooksF next
= OnNewElement Feed FeedElement next
deriving(Functor)
data CoHooksF m a = CoHooksF
{ onNewElementH :: Feed -> FeedElement -> m a
} deriving(Functor)
instance Monad m => PairingM (CoHooksF m) HooksF m where
pairM p (CoHooksF f) (OnNewElement feed element next) = do
a <- f feed element
p a next
onNewElement :: (MonadFree f m, LoggerF :<: f, HooksF :<: f) => Feed -> FeedElement -> m ()
onNewElement feed element = do
logDebug $ "Unread element:" <+> textual (getTitle element)
liftF . inj $ OnNewElement feed element ()