    module Data.Yaml.Extended
        ( module Data.Yaml
        , toString
        , toList
        ) where

    import qualified Data.Text   as T
    import qualified Data.Vector as V
    import           Data.Yaml
    import           Data.Scientific

    toString :: Value -> Maybe String
    toString :: Value -> Maybe String
    toString (String Text
    t)     = String -> Maybe String
    forall a. a -> Maybe a
    Just (Text -> String
    T.unpack Text
    t)
    toString (Bool   Bool
    True)  = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    "true"
    toString (Bool   Bool
    False) = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    "false"
    -- | Make sure that numeric fields containing integer numbers are shown as
    -- | integers (i.e., "42" instead of "42.0").
    toString (Number Scientific
    d) | Scientific -> Bool
    isInteger Scientific
    d = String -> Maybe String
    forall a. a -> Maybe a
    Just (FPFormat -> Maybe Int -> Scientific -> String
    formatScientific FPFormat
    Fixed (Int -> Maybe Int
    forall a. a -> Maybe a
    Just Int
    0) Scientific
    d)
                        | Bool
    otherwise   = String -> Maybe String
    forall a. a -> Maybe a
    Just (Scientific -> String
    forall a. Show a => a -> String
    show Scientific
    d)
    toString Value
    _              = Maybe String
    forall a. Maybe a
    Nothing

    toList :: Value -> Maybe [Value]
    toList :: Value -> Maybe [Value]
    toList (Array Array
    a) = [Value] -> Maybe [Value]
    forall a. a -> Maybe a
    Just (Array -> [Value]
    forall a. Vector a -> [a]
    V.toList Array
    a)
    toList Value
    _         = Maybe [Value]
    forall a. Maybe a
    Nothing