Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (16 sloc) 552 Bytes
module Helpers
( conduitAeson
) where
import Prelude
import Data.Aeson (json, FromJSON (..))
import Data.Aeson.Types (parseEither)
import Data.Conduit (ResumableSource, ($$+-))
import Data.Conduit.Attoparsec (sinkParser)
import Control.Monad.Trans.Resource (MonadThrow)
import Data.ByteString (ByteString)
conduitAeson :: (FromJSON a, Monad m, MonadThrow m)
=> ResumableSource m ByteString
-> m a
conduitAeson source = do
jsonValue <- source $$+- sinkParser json
either fail return $ parseEither parseJSON jsonValue