@@ -26,7 +26,7 @@ import Data.Default
2626import Data.List (intersperse, sortOn, transpose)
2727import Data.List.NonEmpty (nonEmpty, NonEmpty(..))
2828import qualified Data.Map as M
29−import Data.Maybe (fromMaybe, mapMaybe)
29+import Data.Maybe (fromMaybe, mapMaybe, isNothing)
3030import qualified Data.Set as Set
3131import Data.Text (Text)
3232import qualified Data.Text as T
@@ -142,18 +142,17 @@ valToYaml (SimpleVal x)
142142 | otherwise =
143143 if hasNewlines x
144144 then hang 0 ("|" <> cr) x
145− else if fst $ foldr needsDoubleQuotes (False, True) x
145+ else if isNothing $ foldM needsDoubleQuotes True x
146146 then "\"" <> fmap escapeInDoubleQuotes x <> "\""
147147 else x
148148 where
149− needsDoubleQuotes t (positive, isFirst)
149+ needsDoubleQuotes isFirst t
150150 = if T.any isBadAnywhere t ||
151151 (isFirst && T.any isYamlPunct (T.take 1 t))
152− then (True, False)
153− else (positive, False)
152+ then Nothing
153+ else Just False
154154 isBadAnywhere '#' = True
155155 isBadAnywhere ':' = True
156− isBadAnywhere '`' = False
157156 isBadAnywhere _ = False
158157 hasNewlines NewLine = True
159158 hasNewlines BlankLines{} = True