Skip to content

Commit 328e907

Browse files
authored
Merge pull request #1044 from haskell/issue-983-down
Resolve #983. Add instances for Data.Ord.Down
2 parents 8b22d86 + b369630 commit 328e907

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ For the latest version of this document, please see [https://github.com/haskell/
3333
* Drop instances for `Number` from `attoparsec` package.
3434
* Improve `Arbitrary Value` instance.
3535
* Add instances for `URI` from `network-uri`.
36+
* add instances for `Down` from `Data.Ord`.
3637

3738
### 2.1.2.1
3839

src/Data/Aeson/Types/FromJSON.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import Data.Functor.Sum (Sum(..))
101101
import Data.Functor.These (These1 (..))
102102
import Data.Hashable (Hashable(..))
103103
import Data.List.NonEmpty (NonEmpty(..))
104+
import Data.Ord (Down (..))
104105
import Data.Ratio ((%), Ratio)
105106
import Data.Scientific (base10Exponent)
106107
import Data.Tagged (Tagged(..))
@@ -2307,6 +2308,20 @@ instance FromJSON Month where
23072308
instance FromJSONKey Month where
23082309
fromJSONKey = FromJSONKeyTextParser (Time.run Time.parseMonth)
23092310

2311+
-------------------------------------------------------------------------------
2312+
-- base Down
2313+
-------------------------------------------------------------------------------
2314+
2315+
-- | @since 2.2.0.0
2316+
instance FromJSON1 Down where
2317+
liftParseJSON _ p _ = coerce p
2318+
2319+
liftOmittedField = coerce
2320+
2321+
-- | @since 2.2.0.0
2322+
instance FromJSON a => FromJSON (Down a) where
2323+
parseJSON = parseJSON1
2324+
23102325
-------------------------------------------------------------------------------
23112326
-- base Monoid/Semigroup
23122327
-------------------------------------------------------------------------------

src/Data/Aeson/Types/ToJSON.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import Data.Functor.These (These1 (..))
7979
import Data.List (intersperse)
8080
import Data.List.NonEmpty (NonEmpty(..))
8181
import Data.Maybe (isNothing)
82+
import Data.Ord (Down (..))
8283
import Data.Ratio (Ratio, denominator, numerator)
8384
import Data.Tagged (Tagged(..))
8485
import Data.These (These (..))
@@ -2069,6 +2070,20 @@ toEncodingQuarterOfYear Q4 = E.unsafeToEncoding "\"q4\""
20692070
instance ToJSONKey QuarterOfYear where
20702071
toJSONKey = toJSONKeyTextEnc toEncodingQuarterOfYear
20712072

2073+
-------------------------------------------------------------------------------
2074+
-- base Down
2075+
-------------------------------------------------------------------------------
2076+
2077+
instance ToJSON1 Down where
2078+
liftToJSON _ t _ = coerce t
2079+
liftToEncoding _ t _ = coerce t
2080+
liftOmitField = coerce
2081+
2082+
instance ToJSON a => ToJSON (Down a) where
2083+
toJSON = toJSON1
2084+
toEncoding = toEncoding1
2085+
omitField = omitField1
2086+
20722087
-------------------------------------------------------------------------------
20732088
-- base Monoid/Semigroup
20742089
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)