on master help sign in
Revert the type of foldable to be the same it was
df96e86Oleg Grenrus
Data/Aeson/Encode/Functions.hs+1−11
@@ -7,9 +7,7 @@ module Data.Aeson.Encode.Functions
7 , builder'
7 , builder'
8 , char7
8 , char7
9 , encode
9 , encode
10− , foldable
11 , list
10 , list
12− , pairs
13 , encodeMap
11 , encodeMap
14 , encodeWithKey
12 , encodeWithKey
15 ) where
13 ) where
@@ -47,20 +45,12 @@ encode :: ToJSON a => a -> L.ByteString
47encode = B.toLazyByteString . builder
45encode = B.toLazyByteString . builder
48{-# INLINE encode #-}
46{-# INLINE encode #-}
49
47
50−-- | Encode a 'Foldable' as a JSON array.
51−foldable :: (Foldable t) => (a -> Encoding) -> t a -> Encoding
52−foldable to = list to . toList
53−{-# INLINE foldable #-}
54−
55brackets :: Char -> Char -> Series -> Encoding
48brackets :: Char -> Char -> Series -> Encoding
56brackets begin end (Value v) = Encoding $
49brackets begin end (Value v) = Encoding $
57 char7 begin <> fromEncoding v <> char7 end
50 char7 begin <> fromEncoding v <> char7 end
58brackets begin end Empty = Encoding (primBounded (ascii2 (begin,end)) ())
51brackets begin end Empty = Encoding (primBounded (ascii2 (begin,end)) ())
59
52
60−-- | Encode a series of key/value pairs, separated by commas.
53+
61−pairs :: Series -> Encoding
62−pairs = brackets '{' '}'
63−{-# INLINE pairs #-}
64
54
65encodeMap :: (k -> Encoding)
55encodeMap :: (k -> Encoding)
66 -> (v -> Encoding)
56 -> (v -> Encoding)
Data/Aeson/Types.hs+13−1
@@ -94,7 +94,19 @@ module Data.Aeson.Types
94 , defaultTaggedObject
94 , defaultTaggedObject
95 ) where
95 ) where
96
96
97−import Data.Aeson.Encode.Functions (foldable, pairs)
98import Data.Aeson.Types.Generic ()
97import Data.Aeson.Types.Generic ()
99import Data.Aeson.Types.Instances
98import Data.Aeson.Types.Instances
100import Data.Aeson.Types.Internal
99import Data.Aeson.Types.Internal
100+
101+import Data.Foldable (Foldable, toList)
102+import Data.Aeson.Encode.Functions (brackets)
103+
104+-- | Encode a 'Foldable' as a JSON array.
105+foldable :: (Foldable t, ToJSON a) => t a -> Encoding
106+foldable = toEncoding . toList
107+{-# INLINE foldable #-}
108+
109+-- | Encode a series of key/value pairs, separated by commas.
110+pairs :: Series -> Encoding
111+pairs = brackets '{' '}'
112+{-# INLINE pairs #-}
Data/Aeson/Types/Instances.hs+5−4
@@ -90,7 +90,7 @@ module Data.Aeson.Types.Instances
90import Data.Aeson.Types.Instances.Tuple (tuple, (>*<))
90import Data.Aeson.Types.Instances.Tuple (tuple, (>*<))
91
91
92import Control.Applicative (Const(..))
92import Control.Applicative (Const(..))
93−import Data.Aeson.Encode.Functions (builder, builder', encode, foldable, list, encodeWithKey, encodeMap)
93+import Data.Aeson.Encode.Functions (builder, builder', encode, list, encodeWithKey, encodeMap)
94import Data.Aeson.Functions (mapHashKeyVal, mapKey, mapKeyVal)
94import Data.Aeson.Functions (mapHashKeyVal, mapKey, mapKeyVal)
95import Data.Aeson.Types.Class
95import Data.Aeson.Types.Class
96import Data.Aeson.Types.Internal
96import Data.Aeson.Types.Internal
@@ -128,6 +128,7 @@ import qualified Data.HashMap.Strict as H
128import qualified Data.HashSet as HashSet
128import qualified Data.HashSet as HashSet
129import qualified Data.IntMap as IntMap
129import qualified Data.IntMap as IntMap
130import qualified Data.IntSet as IntSet
130import qualified Data.IntSet as IntSet
131+import qualified Data.List.NonEmpty as NE
131import qualified Data.Map as M
132import qualified Data.Map as M
132import qualified Data.Scientific as Scientific
133import qualified Data.Scientific as Scientific
133import qualified Data.Sequence as Seq
134import qualified Data.Sequence as Seq
@@ -682,10 +683,10 @@ instance FromJSON Version where
682-------------------------------------------------------------------------------
683-------------------------------------------------------------------------------
683
684
684instance ToJSON1 NonEmpty where
685instance ToJSON1 NonEmpty where
685− liftToJSON to _ = listValue to . toList
686+ liftToJSON to _ = listValue to . NE.toList
686 {-# INLINE liftToJSON #-}
687 {-# INLINE liftToJSON #-}
687
688
688− liftToEncoding to _ = foldable to
689+ liftToEncoding to _ = listEncoding to . NE.toList
689 {-# INLINE liftToEncoding #-}
690 {-# INLINE liftToEncoding #-}
690
691
691instance (ToJSON a) => ToJSON (NonEmpty a) where
692instance (ToJSON a) => ToJSON (NonEmpty a) where
@@ -730,7 +731,7 @@ instance ToJSON1 Seq.Seq where
730 liftToJSON to _ = listValue to . toList
731 liftToJSON to _ = listValue to . toList
731 {-# INLINE liftToJSON #-}
732 {-# INLINE liftToJSON #-}
732
733
733− liftToEncoding to _ = foldable to
734+ liftToEncoding to _ = listEncoding to . toList
734 {-# INLINE liftToEncoding #-}
735 {-# INLINE liftToEncoding #-}
735
736
736instance (ToJSON a) => ToJSON (Seq.Seq a) where
737instance (ToJSON a) => ToJSON (Seq.Seq a) where