File: Extended.hs

package info (click to toggle)
haskell-hakyll 4.16.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 928 kB
  • sloc: haskell: 6,504; xml: 44; makefile: 9
file content (24 lines) | stat: -rw-r--r-- 754 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 (String t)     = Just (T.unpack t)
toString (Bool   True)  = Just "true"
toString (Bool   False) = Just "false"
-- | Make sure that numeric fields containing integer numbers are shown as
-- | integers (i.e., "42" instead of "42.0").
toString (Number d) | isInteger d = Just (formatScientific Fixed (Just 0) d)
                    | otherwise   = Just (show d)
toString _              = Nothing

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