on master help sign in
Cleanup primed functions
ddba960Oleg Grenrus
Data/Aeson/Encode/Functions.hs+7−21
@@ -7,9 +7,7 @@ module Data.Aeson.Encode.Functions
7 , char7
7 , char7
8 , encode
8 , encode
9 , foldable
9 , foldable
10− , foldable'
11 , list
10 , list
12− , list'
13 , pairs
11 , pairs
14 ) where
12 ) where
15
13
@@ -39,29 +37,17 @@ encode = B.toLazyByteString . builder
39{-# INLINE encode #-}
37{-# INLINE encode #-}
40
38
41-- | Encode a 'Foldable' as a JSON array.
39-- | Encode a 'Foldable' as a JSON array.
42−foldable :: (Foldable t, ToJSON a) => t a -> Encoding
40+foldable :: (Foldable t) => (a -> Encoding) -> t a -> Encoding
43−foldable = brackets '[' ']' . foldMap (Value . toEncoding)
41+foldable to = brackets '[' ']' . foldMap (Value . to)
44{-# INLINE foldable #-}
42{-# INLINE foldable #-}
45
43
46−-- | Encode a 'Foldable' as a JSON array.
47−foldable' :: (Foldable t) => (a -> Encoding) -> t a -> Encoding
48−foldable' to = brackets '[' ']' . foldMap (Value . to)
49−{-# INLINE foldable' #-}
50−
51−list :: (ToJSON a) => [a] -> Encoding
44+list :: (a -> Encoding) -> [a] -> Encoding
52−list [] = emptyArray_
45+list _ [] = emptyArray_
53−list (x:xs) = Encoding $
46+list to (x:xs) = Encoding $
54− char7 '[' <> builder x <> commas xs <> char7 ']'
47+ char7 '[' <> fromEncoding (to x) <> commas xs <> char7 ']'
55− where commas = foldr (\v vs -> char7 ',' <> builder v <> vs) mempty
48+ where commas = foldr (\v vs -> char7 ',' <> fromEncoding (to v) <> vs) mempty
56{-# INLINE list #-}
49{-# INLINE list #-}
57
50
58−list' :: (a -> Encoding) -> [a] -> Encoding
59−list' _ [] = emptyArray_
60−list' e (x:xs) = Encoding $
61− char7 '[' <> fromEncoding (e x) <> commas xs <> char7 ']'
62− where commas = foldr (\v vs -> char7 ',' <> fromEncoding (e v) <> vs) mempty
63−{-# INLINE list' #-}
64−
65brackets :: Char -> Char -> Series -> Encoding
51brackets :: Char -> Char -> Series -> Encoding
66brackets begin end (Value v) = Encoding $
52brackets begin end (Value v) = Encoding $
67 char7 begin <> fromEncoding v <> char7 end
53 char7 begin <> fromEncoding v <> char7 end
Data/Aeson/Types/Instances.hs+7−7
@@ -79,7 +79,7 @@ module Data.Aeson.Types.Instances
79import Data.Aeson.Types.Instances.Tuple (tuple, (>*<))
79import Data.Aeson.Types.Instances.Tuple (tuple, (>*<))
80
80
81import Control.Applicative (Const(..))
81import Control.Applicative (Const(..))
82−import Data.Aeson.Encode.Functions (brackets, builder, encode, foldable, foldable', list')
82+import Data.Aeson.Encode.Functions (brackets, builder, encode, foldable, list)
83import Data.Aeson.Functions (hashMapKey, mapHashKeyVal, mapKey, mapKeyVal)
83import Data.Aeson.Functions (hashMapKey, mapHashKeyVal, mapKey, mapKeyVal)
84import Data.Aeson.Types.Class
84import Data.Aeson.Types.Class
85import Data.Aeson.Types.Internal
85import Data.Aeson.Types.Internal
@@ -590,7 +590,7 @@ instance ToJSON1 NonEmpty where
590 liftToJSON to = liftToJSON to . toList
590 liftToJSON to = liftToJSON to . toList
591 {-# INLINE liftToJSON #-}
591 {-# INLINE liftToJSON #-}
592
592
593− liftToEncoding = foldable'
593+ liftToEncoding = foldable
594 {-# INLINE liftToEncoding #-}
594 {-# INLINE liftToEncoding #-}
595
595
596instance (ToJSON a) => ToJSON (NonEmpty a) where
596instance (ToJSON a) => ToJSON (NonEmpty a) where
@@ -615,7 +615,7 @@ instance ToJSON1 [] where
615 liftToJSON to = Array . V.fromList . map to
615 liftToJSON to = Array . V.fromList . map to
616 {-# INLINE liftToJSON #-}
616 {-# INLINE liftToJSON #-}
617
617
618− liftToEncoding = list'
618+ liftToEncoding = list
619 {-# INLINE liftToEncoding #-}
619 {-# INLINE liftToEncoding #-}
620
620
621instance (ToJSON a) => ToJSON [a] where
621instance (ToJSON a) => ToJSON [a] where
@@ -638,7 +638,7 @@ instance ToJSON1 Seq.Seq where
638 liftToJSON to = liftToJSON to . toList
638 liftToJSON to = liftToJSON to . toList
639 {-# INLINE liftToJSON #-}
639 {-# INLINE liftToJSON #-}
640
640
641− liftToEncoding = foldable'
641+ liftToEncoding = foldable
642 {-# INLINE liftToEncoding #-}
642 {-# INLINE liftToEncoding #-}
643
643
644instance (ToJSON a) => ToJSON (Seq.Seq a) where
644instance (ToJSON a) => ToJSON (Seq.Seq a) where
@@ -751,7 +751,7 @@ instance (ToJSON a) => ToJSON (HashSet.HashSet a) where
751 toJSON = toJSON . HashSet.toList
751 toJSON = toJSON . HashSet.toList
752 {-# INLINE toJSON #-}
752 {-# INLINE toJSON #-}
753
753
754− toEncoding = foldable
754+ toEncoding = foldable toEncoding
755 {-# INLINE toEncoding #-}
755 {-# INLINE toEncoding #-}
756
756
757instance (Eq a, Hashable a, FromJSON a) => FromJSON (HashSet.HashSet a) where
757instance (Eq a, Hashable a, FromJSON a) => FromJSON (HashSet.HashSet a) where
@@ -826,7 +826,7 @@ instance (ToJSON v, ToJSONKey k) => ToJSON (M.Map k v) where
826
826
827 toEncoding = case toJSONKey of
827 toEncoding = case toJSONKey of
828 ToJSONKeyText (_,f) -> encodeMap f M.minViewWithKey M.foldrWithKey
828 ToJSONKeyText (_,f) -> encodeMap f M.minViewWithKey M.foldrWithKey
829− ToJSONKeyValue (_,f) -> list' (pairEncoding f) . M.toList
829+ ToJSONKeyValue (_,f) -> list (pairEncoding f) . M.toList
830 where pairEncoding :: (k -> Encoding) -> (k, v) -> Encoding
830 where pairEncoding :: (k -> Encoding) -> (k, v) -> Encoding
831 pairEncoding f (a, b) = tuple $ fromEncoding (f a) >*< builder b
831 pairEncoding f (a, b) = tuple $ fromEncoding (f a) >*< builder b
832 {-# INLINE toEncoding #-}
832 {-# INLINE toEncoding #-}
@@ -852,7 +852,7 @@ instance (ToJSON v, ToJSONKey k) => ToJSON (H.HashMap k v) where
852
852
853 toEncoding = case toJSONKey of
853 toEncoding = case toJSONKey of
854 ToJSONKeyText (_,f) -> encodeWithKey f H.foldrWithKey
854 ToJSONKeyText (_,f) -> encodeWithKey f H.foldrWithKey
855− ToJSONKeyValue (_,f) -> list' (pairEncoding f) . H.toList
855+ ToJSONKeyValue (_,f) -> list (pairEncoding f) . H.toList
856 where pairEncoding :: (k -> Encoding) -> (k, v) -> Encoding
856 where pairEncoding :: (k -> Encoding) -> (k, v) -> Encoding
857 pairEncoding f (a, b) = tuple $ fromEncoding (f a) >*< builder b
857 pairEncoding f (a, b) = tuple $ fromEncoding (f a) >*< builder b
858 {-# INLINE toEncoding #-}
858 {-# INLINE toEncoding #-}