on master help sign in
Add decodeThrow, decodeFileThrow helper functions
c3d043bDaniel Firth
ChangeLog.md+4
@@ -1,3 +1,7 @@
1+## 0.8.31
2+
3+* Add `decodeThrow` and `decodeFileThrow` convenience functions.
4+
1## 0.8.30
5## 0.8.30
2
6
3* Removed `AppSettings` mentioned in `loadYamlSettings` error message.
7* Removed `AppSettings` mentioned in `loadYamlSettings` error message.
Data/Yaml.hs+16
@@ -64,6 +64,8 @@ module Data.Yaml
64 , decodeEither
64 , decodeEither
65 , decodeEither'
65 , decodeEither'
66 , decodeFileEither
66 , decodeFileEither
67+ , decodeThrow
68+ , decodeFileThrow
67 -- ** More control over decoding
69 -- ** More control over decoding
68 , decodeHelper
70 , decodeHelper
69 ) where
71 ) where
@@ -71,6 +73,8 @@ module Data.Yaml
71import Control.Applicative((<$>))
73import Control.Applicative((<$>))
72#endif
74#endif
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
192
196
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+
193array :: [Value] -> Value
209array :: [Value] -> Value
194array = Array . V.fromList
210array = Array . V.fromList
195
211
yaml.cabal+1−1
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.8.30
2+version: 0.8.31
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov