@@ -64,6 +64,8 @@ module Data.Yaml
6464 , decodeEither
6565 , decodeEither'
6666 , decodeFileEither
67+ , decodeThrow
68+ , decodeFileThrow
6769 -- ** More control over decoding
6870 , decodeHelper
6971 ) where
@@ -71,6 +73,8 @@ module Data.Yaml
7173import Control.Applicative((<$>))
7274#endif
7375import Control.Exception
76+import Control.Monad.IO.Class (MonadIO, liftIO)
77+import Control.Monad.Trans.Resource (MonadThrow, throwM)
7478import Data.Aeson
7579 ( Value (..), ToJSON (..), FromJSON (..), object
7680 , (.=) , (.:) , (.:?) , (.!=)
@@ -190,6 +194,18 @@ decodeEither' = either Left (either (Left . AesonException) Right)
190194 . decodeHelper
191195 . Y.decode
192196
197+-- | A version of 'decodeEither'' lifted to MonadThrow
198+--
199+-- Since 0.8.31
200+decodeThrow :: (MonadThrow m, FromJSON a) => ByteString -> m a
201+decodeThrow = either throwM return . decodeEither'
202+
203+-- | A version of 'decodeFileEither' lifted to MonadIO
204+--
205+-- Since 0.8.31
206+decodeFileThrow :: (MonadIO m, FromJSON a) => FilePath -> m a
207+decodeFileThrow f = liftIO $ decodeFileEither f >>= either throwIO return
208+
193209array :: [Value] -> Value
194210array = Array . V.fromList
195211