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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.