@@ -7,7 +7,6 @@ module Data.Yaml.Pretty
77 , Config
88 , getConfCompare
99 , setConfCompare
10− , setConfComparePos
1110 , getConfDropNull
1211 , setConfDropNull
1312 , defConfig
@@ -51,7 +50,7 @@ type Key = Text
5150-- |
5251-- @since 0.8.13
5352data Config = Config
54− { confCompare :: JSONPath -> Text -> Text -> Ordering -- ^ Function used to sort keys in objects
53+ { confCompare :: Text -> Text -> Ordering -- ^ Function used to sort keys in objects
5554 , confDropNull :: Bool -- ^ Drop null values from objects
5655 }
5756
@@ -63,20 +62,14 @@ defConfig = Config mempty False
6362
6463-- |
6564-- @since 0.8.13
66−getConfCompare :: Config -> JSONPath -> Text -> Text -> Ordering
65+getConfCompare :: Config -> Text -> Text -> Ordering
6766getConfCompare = confCompare
6867
6968-- | Sets ordering for object keys
7069--
7170-- @since 0.8.13
7271setConfCompare :: (Text -> Text -> Ordering) -> Config -> Config
73−setConfCompare cmp c = c { confCompare = \_ps -> cmp }
74−
75−-- | Set ordering for object keys that depends on location of object in the document.
76−--
77−-- @since 0.11.9
78−setConfComparePos :: (JSONPath -> Text -> Text -> Ordering) -> Config -> Config
79−setConfComparePos cmp c = c { confCompare = cmp }
72+setConfCompare cmp c = c { confCompare = cmp }
8073
8174-- |
8275-- @since 0.8.24
@@ -90,17 +83,17 @@ setConfDropNull :: Bool -> Config -> Config
9083setConfDropNull m c = c { confDropNull = m }
9184
9285pretty :: Config -> Value -> YamlBuilder
93−pretty cfg = go []
94− where go ps (Object o) = let sort = sortBy (confCompare cfg (reverse ps) `on` fst)
95− select
96− | confDropNull cfg = HM.filter (/= Null)
97− | otherwise = id
98− in mapping (sort $ fmap (first toText) $ HM.toList $ HM.mapWithKey (\k -> go (Key (toText k): ps)) $ select o)
99− go ps (Array a) = array $ zipWith (\ix -> go (Index ix: ps)) [0..] (V.toList a)
100− go _ Null = null
101− go _ (String s) = string s
102− go _ (Number n) = scientific n
103− go _ (Bool b) = bool b
86+pretty cfg = go
87+ where go (Object o) = let sort = sortBy (confCompare cfg `on` fst)
88+ select
89+ | confDropNull cfg = HM.filter (/= Null)
90+ | otherwise = id
91+ in mapping (sort $ fmap (first toText) $ HM.toList $ HM.map go $ select o)
92+ go (Array a) = array (go <$> V.toList a)
93+ go Null = null
94+ go (String s) = string s
95+ go (Number n) = scientific n
96+ go (Bool b) = bool b
10497
10598-- | Configurable 'encode'.
10699--