on master help sign in
Rename Pairable (ugh) to KeyValue (better-ish)
9ac92bdBryan O'Sullivan
Data/Aeson.hs+1−1
@@ -54,6 +54,7 @@ module Data.Aeson
54 , Result(..)
54 , Result(..)
55 , fromJSON
55 , fromJSON
56 , ToJSON(..)
56 , ToJSON(..)
57+ , KeyValue(..)
57 -- ** Generic JSON classes
58 -- ** Generic JSON classes
58 , GFromJSON(..)
59 , GFromJSON(..)
59 , GToJSON(..)
60 , GToJSON(..)
@@ -68,7 +69,6 @@ module Data.Aeson
68 , withScientific
69 , withScientific
69 , withBool
70 , withBool
70 -- * Constructors and accessors
71 -- * Constructors and accessors
71− , Pairable(..)
72 , series
72 , series
73 , (.:)
73 , (.:)
74 , (.:?)
74 , (.:?)
Data/Aeson/Types.hs+1−1
@@ -31,6 +31,7 @@ module Data.Aeson.Types
31 , parseEither
31 , parseEither
32 , parseMaybe
32 , parseMaybe
33 , ToJSON(..)
33 , ToJSON(..)
34+ , KeyValue(..)
34 , modifyFailure
35 , modifyFailure
35 , JSONPath
36 , JSONPath
36 , formatError
37 , formatError
@@ -50,7 +51,6 @@ module Data.Aeson.Types
50 , withBool
51 , withBool
51
52
52 -- * Constructors and accessors
53 -- * Constructors and accessors
53− , Pairable(..)
54 , series
54 , series
55 , (.:)
55 , (.:)
56 , (.:?)
56 , (.:?)
Data/Aeson/Types/Class.hs+4−3
@@ -23,7 +23,7 @@ module Data.Aeson.Types.Class
23 , genericToEncoding
23 , genericToEncoding
24 , genericParseJSON
24 , genericParseJSON
25 -- * Object key-value pairs
25 -- * Object key-value pairs
26− , Pairable(..)
26+ , KeyValue(..)
27 ) where
27 ) where
28
28
29import Data.Text (Text)
29import Data.Text (Text)
@@ -199,5 +199,6 @@ class FromJSON a where
199 default parseJSON :: (Generic a, GFromJSON (Rep a)) => Value -> Parser a
199 default parseJSON :: (Generic a, GFromJSON (Rep a)) => Value -> Parser a
200 parseJSON = genericParseJSON defaultOptions
200 parseJSON = genericParseJSON defaultOptions
201
201
202+-- | A key-value pair for a JSON object.
202−class Pairable t where
203+class KeyValue t where
203− (.=) :: ToJSON a => Text -> a -> t
204+ (.=) :: ToJSON v => Text -> v -> t
Data/Aeson/Types/Instances.hs+3−3
@@ -24,6 +24,7 @@ module Data.Aeson.Types.Instances
24 -- ** Core JSON classes
24 -- ** Core JSON classes
25 FromJSON(..)
25 FromJSON(..)
26 , ToJSON(..)
26 , ToJSON(..)
27+ , KeyValue(..)
27 -- ** Generic JSON classes
28 -- ** Generic JSON classes
28 , GFromJSON(..)
29 , GFromJSON(..)
29 , GToJSON(..)
30 , GToJSON(..)
@@ -46,7 +47,6 @@ module Data.Aeson.Types.Instances
46 , (.:)
47 , (.:)
47 , (.:?)
48 , (.:?)
48 , (.!=)
49 , (.!=)
49− , Pairable(..)
50 , series
50 , series
51 , typeMismatch
51 , typeMismatch
52 ) where
52 ) where
@@ -1424,11 +1424,11 @@ withBool _ f (Bool arr) = f arr
1424withBool expected _ v = typeMismatch expected v
1424withBool expected _ v = typeMismatch expected v
1425{-# INLINE withBool #-}
1425{-# INLINE withBool #-}
1426
1426
1427−instance Pairable Pair where
1427+instance KeyValue Pair where
1428 name .= value = (name, toJSON value)
1428 name .= value = (name, toJSON value)
1429 {-# INLINE (.=) #-}
1429 {-# INLINE (.=) #-}
1430
1430
1431−instance Pairable Series where
1431+instance KeyValue Series where
1432 name .= value = Value (E.text name <> B.char7 ':' <> toEncoding value)
1432 name .= value = Value (E.text name <> B.char7 ':' <> toEncoding value)
1433 {-# INLINE (.=) #-}
1433 {-# INLINE (.=) #-}
1434
1434