on master help sign in
Revert the type of foldable to be the same it was
commitdf96e86a93b1605ae85324caee896b972ec61c58 authorOleg Grenrus <oleg.grenrus@iki.fi> dateThu 2 Jun 2016, 18:00 (10 years ago) parentc8b7105
3 files changed+19−16
Data/Aeson/Encode/Functions.hs+1−11 Data/Aeson/Types.hs+13−1 Data/Aeson/Types/Instances.hs+5−4
Data/Aeson/Encode/Functions.hs+1−11
@@ -7,9 +7,7 @@ module Data.Aeson.Encode.Functions
77 , builder'
88 , char7
99 , encode
10− , foldable
1110 , list
12− , pairs
1311 , encodeMap
1412 , encodeWithKey
1513 ) where
@@ -47,20 +45,12 @@ encode :: ToJSON a => a -> L.ByteString
4745encode = B.toLazyByteString . builder
4846{-# INLINE encode #-}
4947
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−
5548brackets :: Char -> Char -> Series -> Encoding
5649brackets begin end (Value v) = Encoding $
5750 char7 begin <> fromEncoding v <> char7 end
5851brackets begin end Empty = Encoding (primBounded (ascii2 (begin,end)) ())
5952
60−-- | Encode a series of key/value pairs, separated by commas.
61−pairs :: Series -> Encoding
62−pairs = brackets '{' '}'
63−{-# INLINE pairs #-}
53+
6454
6555encodeMap :: (k -> Encoding)
6656 -> (v -> Encoding)
Data/Aeson/Types.hs+13−1
@@ -94,7 +94,19 @@ module Data.Aeson.Types
9494 , defaultTaggedObject
9595 ) where
9696
97−import Data.Aeson.Encode.Functions (foldable, pairs)
9897import Data.Aeson.Types.Generic ()
9998import Data.Aeson.Types.Instances
10099import 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
9090import Data.Aeson.Types.Instances.Tuple (tuple, (>*<))
9191
9292import 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)
9494import Data.Aeson.Functions (mapHashKeyVal, mapKey, mapKeyVal)
9595import Data.Aeson.Types.Class
9696import Data.Aeson.Types.Internal
@@ -128,6 +128,7 @@ import qualified Data.HashMap.Strict as H
128128import qualified Data.HashSet as HashSet
129129import qualified Data.IntMap as IntMap
130130import qualified Data.IntSet as IntSet
131+import qualified Data.List.NonEmpty as NE
131132import qualified Data.Map as M
132133import qualified Data.Scientific as Scientific
133134import qualified Data.Sequence as Seq
@@ -682,10 +683,10 @@ instance FromJSON Version where
682683-------------------------------------------------------------------------------
683684
684685instance ToJSON1 NonEmpty where
685− liftToJSON to _ = listValue to . toList
686+ liftToJSON to _ = listValue to . NE.toList
686687 {-# INLINE liftToJSON #-}
687688
688− liftToEncoding to _ = foldable to
689+ liftToEncoding to _ = listEncoding to . NE.toList
689690 {-# INLINE liftToEncoding #-}
690691
691692instance (ToJSON a) => ToJSON (NonEmpty a) where
@@ -730,7 +731,7 @@ instance ToJSON1 Seq.Seq where
730731 liftToJSON to _ = listValue to . toList
731732 {-# INLINE liftToJSON #-}
732733
733− liftToEncoding to _ = foldable to
734+ liftToEncoding to _ = listEncoding to . toList
734735 {-# INLINE liftToEncoding #-}
735736
736737instance (ToJSON a) => ToJSON (Seq.Seq a) where