on master help sign in
Add unary instances to Monoid newtypes
ac1c0bfOleg Grenrus
Data/Aeson/Types/Instances.hs+45−9
@@ -1616,39 +1616,75 @@ instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1616 <*> parseJSONElemAtIndex 14 ary
1616 <*> parseJSONElemAtIndex 14 ary
1617 {-# INLINE parseJSON #-}
1617 {-# INLINE parseJSON #-}
1618
1618
1619+instance ToJSON1 Dual where
1620+ liftToJSON to = to . getDual
1621+ {-# INLINE liftToJSON #-}
1622+
1623+ liftToEncoding to = to . getDual
1624+ {-# INLINE liftToEncoding #-}
1625+
1619instance ToJSON a => ToJSON (Dual a) where
1626instance ToJSON a => ToJSON (Dual a) where
1620− toJSON = toJSON . getDual
1627+ toJSON = toJSON1
1621 {-# INLINE toJSON #-}
1628 {-# INLINE toJSON #-}
1622
1629
1623− toEncoding = toEncoding . getDual
1630+ toEncoding = toEncoding1
1624 {-# INLINE toEncoding #-}
1631 {-# INLINE toEncoding #-}
1625
1632
1633+instance FromJSON1 Dual where
1634+ liftParseJSON p = fmap Dual . p
1635+ {-# INLINE liftParseJSON #-}
1636+
1626instance FromJSON a => FromJSON (Dual a) where
1637instance FromJSON a => FromJSON (Dual a) where
1627− parseJSON = fmap Dual . parseJSON
1638+ parseJSON = parseJSON1
1628 {-# INLINE parseJSON #-}
1639 {-# INLINE parseJSON #-}
1629
1640
1641+
1642+instance ToJSON1 First where
1643+ liftToJSON to = liftToJSON to . getFirst
1644+ {-# INLINE liftToJSON #-}
1645+
1646+ liftToEncoding to = liftToEncoding to . getFirst
1647+ {-# INLINE liftToEncoding #-}
1648+
1630instance ToJSON a => ToJSON (First a) where
1649instance ToJSON a => ToJSON (First a) where
1631− toJSON = toJSON . getFirst
1650+ toJSON = toJSON1
1632 {-# INLINE toJSON #-}
1651 {-# INLINE toJSON #-}
1633
1652
1634− toEncoding = toEncoding . getFirst
1653+ toEncoding = toEncoding1
1635 {-# INLINE toEncoding #-}
1654 {-# INLINE toEncoding #-}
1636
1655
1656+instance FromJSON1 First where
1657+ liftParseJSON p = fmap First . liftParseJSON p
1658+ {-# INLINE liftParseJSON #-}
1659+
1637instance FromJSON a => FromJSON (First a) where
1660instance FromJSON a => FromJSON (First a) where
1638− parseJSON = fmap First . parseJSON
1661+ parseJSON = parseJSON1
1639 {-# INLINE parseJSON #-}
1662 {-# INLINE parseJSON #-}
1640
1663
1664+
1665+instance ToJSON1 Last where
1666+ liftToJSON to = liftToJSON to . getLast
1667+ {-# INLINE liftToJSON #-}
1668+
1669+ liftToEncoding to = liftToEncoding to . getLast
1670+ {-# INLINE liftToEncoding #-}
1671+
1641instance ToJSON a => ToJSON (Last a) where
1672instance ToJSON a => ToJSON (Last a) where
1642− toJSON = toJSON . getLast
1673+ toJSON = toJSON1
1643 {-# INLINE toJSON #-}
1674 {-# INLINE toJSON #-}
1644
1675
1645− toEncoding = toEncoding . getLast
1676+ toEncoding = toEncoding1
1646 {-# INLINE toEncoding #-}
1677 {-# INLINE toEncoding #-}
1647
1678
1679+instance FromJSON1 Last where
1680+ liftParseJSON p = fmap Last . liftParseJSON p
1681+ {-# INLINE liftParseJSON #-}
1682+
1648instance FromJSON a => FromJSON (Last a) where
1683instance FromJSON a => FromJSON (Last a) where
1649− parseJSON = fmap Last . parseJSON
1684+ parseJSON = parseJSON1
1650 {-# INLINE parseJSON #-}
1685 {-# INLINE parseJSON #-}
1651
1686
1687+
1652instance ToJSON Version where
1688instance ToJSON Version where
1653 toJSON = toJSON . showVersion
1689 toJSON = toJSON . showVersion
1654 {-# INLINE toJSON #-}
1690 {-# INLINE toJSON #-}