module Imm.XML where
import Imm.Error
import Imm.Feed
import Imm.Prelude
import Control.Monad.Trans.Free
import URI.ByteString
data XmlParserF next
= ParseXml URI LByteString (Either SomeException Feed -> next)
deriving(Functor)
newtype CoXmlParserF m a = CoXmlParserF
{ parseXmlH :: URI -> LByteString -> m (Either SomeException Feed, a)
} deriving(Functor)
instance Monad m => PairingM (CoXmlParserF m) XmlParserF m where
pairM f (CoXmlParserF p) (ParseXml uri bytestring next) = do
(result, a) <- p uri bytestring
f a $ next result
parseXml :: (MonadFree f m, XmlParserF :<: f, MonadThrow m)
=> URI -> LByteString -> m Feed
parseXml uri bytestring = do
result <- liftF . inj $ ParseXml uri bytestring id
liftE result