on master help sign in
Nicer docs
a27dc9dMichael Snoyman
Data/Yaml.hs+16−12
@@ -26,8 +26,18 @@ module Data.Yaml {-# WARNING "GHCJS is not supported yet (will break at runtime
26#else
26#else
27module Data.Yaml
27module Data.Yaml
28#endif
28#endif
29+ ( -- * Encoding
30+ encode
31+ , encodeFile
32+ -- * Decoding
33+ , decodeEither'
34+ , decodeFileEither
35+ , decodeThrow
36+ , decodeFileThrow
37+ -- ** More control over decoding
38+ , decodeHelper
29− ( -- * Types
39+ -- * Types
30− Value (..)
40+ , Value (..)
31 , Parser
41 , Parser
32 , Object
42 , Object
33 , Array
43 , Array
@@ -55,19 +65,10 @@ module Data.Yaml
55 -- * Classes
65 -- * Classes
56 , ToJSON (..)
66 , ToJSON (..)
57 , FromJSON (..)
67 , FromJSON (..)
58− -- * Encoding/decoding
68+ -- * Deprecated
59− , encode
60− , encodeFile
61 , decode
69 , decode
62 , decodeFile
70 , decodeFile
63− -- ** Better error information
64 , decodeEither
71 , decodeEither
65− , decodeEither'
66− , decodeFileEither
67− , decodeThrow
68− , decodeFileThrow
69− -- ** More control over decoding
70− , decodeHelper
71 ) where
72 ) where
72#if !MIN_VERSION_base(4,8,0)
73#if !MIN_VERSION_base(4,8,0)
73import Control.Applicative((<$>))
74import Control.Applicative((<$>))
@@ -103,11 +104,13 @@ import Data.Yaml.Internal
103import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
104import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
104import qualified Text.Libyaml as Y
105import qualified Text.Libyaml as Y
105
106
107+-- | Encode a value into its YAML representation.
106encode :: ToJSON a => a -> ByteString
108encode :: ToJSON a => a -> ByteString
107encode obj = unsafePerformIO $ runConduitRes
109encode obj = unsafePerformIO $ runConduitRes
108 $ CL.sourceList (objToEvents $ toJSON obj)
110 $ CL.sourceList (objToEvents $ toJSON obj)
109 .| Y.encode
111 .| Y.encode
110
112
113+-- | Encode a value into its YAML representation and save to the given file.
111encodeFile :: ToJSON a => FilePath -> a -> IO ()
114encodeFile :: ToJSON a => FilePath -> a -> IO ()
112encodeFile fp obj = runConduitRes
115encodeFile fp obj = runConduitRes
113 $ CL.sourceList (objToEvents $ toJSON obj)
116 $ CL.sourceList (objToEvents $ toJSON obj)
@@ -208,6 +211,7 @@ decodeThrow = either throwM return . decodeEither'
208decodeFileThrow :: (MonadIO m, FromJSON a) => FilePath -> m a
211decodeFileThrow :: (MonadIO m, FromJSON a) => FilePath -> m a
209decodeFileThrow f = liftIO $ decodeFileEither f >>= either throwIO return
212decodeFileThrow f = liftIO $ decodeFileEither f >>= either throwIO return
210
213
214+-- | Construct a new 'Value' from a list of 'Value's.
211array :: [Value] -> Value
215array :: [Value] -> Value
212array = Array . V.fromList
216array = Array . V.fromList
213
217