From 67ecff7ad383640bc73d64edc2506c7cc648a134 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 19 Jun 2017 11:57:23 +0200 Subject: Move src/ to lib/, put Init.hs in src/ --- lib/Data/List/Extended.hs | 15 +++++++++++++++ lib/Data/Yaml/Extended.hs | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 lib/Data/List/Extended.hs create mode 100644 lib/Data/Yaml/Extended.hs (limited to 'lib/Data') diff --git a/lib/Data/List/Extended.hs b/lib/Data/List/Extended.hs new file mode 100644 index 0000000..485cba8 --- /dev/null +++ b/lib/Data/List/Extended.hs @@ -0,0 +1,15 @@ +module Data.List.Extended + ( module Data.List + , breakWhen + ) where + +import Data.List + +-- | Like 'break', but can act on the entire tail of the list. +breakWhen :: ([a] -> Bool) -> [a] -> ([a], [a]) +breakWhen predicate = go [] + where + go buf [] = (reverse buf, []) + go buf (x : xs) + | predicate (x : xs) = (reverse buf, x : xs) + | otherwise = go (x : buf) xs diff --git a/lib/Data/Yaml/Extended.hs b/lib/Data/Yaml/Extended.hs new file mode 100644 index 0000000..c940ff7 --- /dev/null +++ b/lib/Data/Yaml/Extended.hs @@ -0,0 +1,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 -- cgit v1.2.3