@@ -64,6 +64,8 @@ module Data.Yaml
64 , decodeEither
64 , decodeEither
65 , decodeEither'
65 , decodeEither'
66 , decodeFileEither
66 , decodeFileEither
67 -- ** More control over decoding
69 -- ** More control over decoding
68 , decodeHelper
70 , decodeHelper
@@ -71,6 +73,8 @@ module Data.Yaml
71import Control.Applicative((<$>))
73import Control.Applicative((<$>))
73import Control.Exception
75import Control.Exception
76+import Control.Monad.IO.Class (MonadIO, liftIO)
77+import Control.Monad.Trans.Resource (MonadThrow, throwM)
74import Data.Aeson
78import Data.Aeson
75 ( Value (..), ToJSON (..), FromJSON (..), object
79 ( Value (..), ToJSON (..), FromJSON (..), object
76 , (.=) , (.:) , (.:?) , (.!=)
80 , (.=) , (.:) , (.:?) , (.!=)
@@ -190,6 +194,18 @@ decodeEither' = either Left (either (Left . AesonException) Right)
190 . decodeHelper
194 . decodeHelper
191 . Y.decode
195 . Y.decode
197+-- | A version of 'decodeEither'' lifted to MonadThrow
200+decodeThrow :: (MonadThrow m, FromJSON a) => ByteString -> m a
201+decodeThrow = either throwM return . decodeEither'
203+-- | A version of 'decodeFileEither' lifted to MonadIO
206+decodeFileThrow :: (MonadIO m, FromJSON a) => FilePath -> m a
207+decodeFileThrow f = liftIO $ decodeFileEither f >>= either throwIO return
193array :: [Value] -> Value
209array :: [Value] -> Value
194array = Array . V.fromList
210array = Array . V.fromList