Commits

Bryan O'Sullivan committed 026e69a

Monoid instances.

Comments (0)

Files changed (1)

Data/Aeson/Types.hs

     , object
     ) where
 
-import Control.Monad (MonadPlus(..), ap, liftM)
 import Control.Arrow ((***))
 import Control.DeepSeq (NFData(..))
+import Control.Monad (MonadPlus(..), ap, liftM)
+import Data.Data (Data)
 import Data.Map (Map)
-import qualified Data.ByteString as B
-import qualified Data.ByteString.Lazy as LB
+import Data.Monoid (Dual(..), First(..), Last(..))
+import Data.Text (Text, pack, unpack)
 import Data.Text.Encoding (decodeUtf8, encodeUtf8)
-import Data.Text (Text, pack, unpack)
-import qualified Data.Text.Lazy as LT
 import Data.Time.Clock (UTCTime)
 import Data.Time.Format (formatTime, parseTime)
 import Data.Typeable (Typeable)
-import Data.Data (Data)
 import Data.Vector (Vector)
 import System.Locale (defaultTimeLocale)
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Lazy as LB
 import qualified Data.Map as M
 import qualified Data.Set as Set
+import qualified Data.Text.Lazy as LT
 import qualified Data.Vector as V
 
 -- | A JSON \"object\" (key\/value map).
     fromJSON _          = empty
     {-# INLINE fromJSON #-}
 
+instance ToJSON a => ToJSON (Dual a) where
+    toJSON = toJSON . getDual
+    {-# INLINE toJSON #-}
+
+instance FromJSON a => FromJSON (Dual a) where
+    fromJSON = liftM Dual . fromJSON
+    {-# INLINE fromJSON #-}
+
+instance ToJSON a => ToJSON (First a) where
+    toJSON = toJSON . getFirst
+    {-# INLINE toJSON #-}
+
+instance FromJSON a => FromJSON (First a) where
+    fromJSON = liftM First . fromJSON
+    {-# INLINE fromJSON #-}
+
+instance ToJSON a => ToJSON (Last a) where
+    toJSON = toJSON . getLast
+    {-# INLINE toJSON #-}
+
+instance FromJSON a => FromJSON (Last a) where
+    fromJSON = liftM Last . fromJSON
+    {-# INLINE fromJSON #-}
+
 -- | Transform one map into another.  The ordering of keys must be
 -- preserved.
 transformMap :: (Ord k1, Ord k2) => (k1 -> k2) -> (v1 -> v2)