these 0.7.1 → 0.7.2
raw patch · 3 files changed
+47/−2 lines, 3 filesdep ~QuickCheckdep ~aeson
Dependency ranges changed: QuickCheck, aeson
Files
- CHANGELOG.md +4/−0
- Data/These.hs +41/−0
- these.cabal +2/−2
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.7.2++- Support `aeson-1`: add `FromJSON1`, `FromJSON2` `ToJSON1`, and `ToJSON2` `These` instances.+ # 0.7.1 - Add `AlignWithKey` in `Data.Align.Key` (added dependency `keys`)
Data/These.hs view
@@ -71,6 +71,9 @@ import qualified Data.HashMap.Strict as HM import qualified Data.Aeson as Aeson+#if MIN_VERSION_aeson(1,0,0)+import qualified Data.Aeson.Encoding as Aeson (pair)+#endif -- -------------------------------------------------------------------------- -- | The 'These' type represents values with two non-exclusive possibilities.@@ -320,6 +323,44 @@ p [("This", a)] = This <$> parseJSON a p [("That", b)] = That <$> parseJSON b p _ = fail "Expected object with 'This' and 'That' keys only"++#if MIN_VERSION_aeson(1,0,0)+instance Aeson.ToJSON2 These where+ liftToJSON2 toa _ _tob _ (This a) = Aeson.object [ "This" .= toa a ]+ liftToJSON2 _toa _ tob _ (That b) = Aeson.object [ "That" .= tob b ]+ liftToJSON2 toa _ tob _ (These a b) = Aeson.object [ "This" .= toa a, "That" .= tob b ]++ liftToEncoding2 toa _ _tob _ (This a) = Aeson.pairs $ Aeson.pair "This" (toa a)+ liftToEncoding2 _toa _ tob _ (That b) = Aeson.pairs $ Aeson.pair "That" (tob b)+ liftToEncoding2 toa _ tob _ (These a b) = Aeson.pairs $ Aeson.pair "This" (toa a) <> Aeson.pair "That" (tob b)++instance ToJSON a => Aeson.ToJSON1 (These a) where+ liftToJSON _tob _ (This a) = Aeson.object [ "This" .= a ]+ liftToJSON tob _ (That b) = Aeson.object [ "That" .= tob b ]+ liftToJSON tob _ (These a b) = Aeson.object [ "This" .= a, "That" .= tob b ]++ liftToEncoding _tob _ (This a) = Aeson.pairs $ "This" .= a+ liftToEncoding tob _ (That b) = Aeson.pairs $ Aeson.pair "That" (tob b)+ liftToEncoding tob _ (These a b) = Aeson.pairs $ "This" .= a <> Aeson.pair "That" (tob b)++instance Aeson.FromJSON2 These where+ liftParseJSON2 pa _ pb _ = Aeson.withObject "These a b" (p . HM.toList)+ where+ p [("This", a), ("That", b)] = These <$> pa a <*> pb b+ p [("That", b), ("This", a)] = These <$> pa a <*> pb b+ p [("This", a)] = This <$> pa a+ p [("That", b)] = That <$> pb b+ p _ = fail "Expected object with 'This' and 'That' keys only"++instance FromJSON a => Aeson.FromJSON1 (These a) where+ liftParseJSON pb _ = Aeson.withObject "These a b" (p . HM.toList)+ where+ p [("This", a), ("That", b)] = These <$> parseJSON a <*> pb b+ p [("That", b), ("This", a)] = These <$> parseJSON a <*> pb b+ p [("This", a)] = This <$> parseJSON a+ p [("That", b)] = That <$> pb b+ p _ = fail "Expected object with 'This' and 'That' keys only"+#endif instance (Arbitrary a, Arbitrary b) => Arbitrary (These a b) where arbitrary = oneof [ This <$> arbitrary
these.cabal view
@@ -1,5 +1,5 @@ Name: these-Version: 0.7.1+Version: 0.7.2 Synopsis: An either-or-both data type & a generalized 'zip with padding' typeclass Homepage: https://github.com/isomorphism/these License: BSD3@@ -36,7 +36,7 @@ Control.Monad.Trans.Chronicle Build-depends: base >= 4.4 && < 4.10,- aeson >= 0.7.0.4 && < 0.12,+ aeson >= 0.7.0.4 && < 1.1, bifunctors >= 0.1 && < 5.5, binary >= 0.5.0.2 && < 0.9, containers >= 0.4 && < 0.6,