these 1.0.1 → 1.1
raw patch · 5 files changed
+28/−274 lines, 5 filesdep −QuickCheckdep −aesondep −semigroupoids
Dependencies removed: QuickCheck, aeson, semigroupoids, unordered-containers
Files
- CHANGELOG.md +6/−0
- src/Data/Functor/These.hs +0/−72
- src/Data/These.hs +4/−168
- src/Data/These/Combinators.hs +4/−4
- these.cabal +14/−30
CHANGELOG.md view
@@ -1,3 +1,9 @@+# 1.1++- Reverse dependency with `aeson`.+ - The `QuickCheck` instances are moved into `quickcheck-instances`+ - The `semigroupoids` instances are gone for now.+ # 1.0.1 - add `partitionEithersNE :: NonEmpty (Either a b) -> These (NonEmpty a) (NonEmpty b)`
src/Data/Functor/These.hs view
@@ -45,20 +45,6 @@ import Data.Typeable (Typeable) #endif -#ifdef MIN_VERSION_aeson-import Data.Aeson- (FromJSON (..), FromJSON1 (..), ToJSON (..), ToJSON1 (..), (.=))-import qualified Data.Aeson as Aeson-import qualified Data.Aeson.Encoding as Aeson (pair)-import qualified Data.HashMap.Strict as HM-#endif--#ifdef MIN_VERSION_QuickCheck-import Test.QuickCheck- (Arbitrary (..), Arbitrary1 (..), arbitrary1, liftShrink2, oneof,- shrink1)-#endif- ------------------------------------------------------------------------------- -- These1 -------------------------------------------------------------------------------@@ -220,62 +206,4 @@ -- | This instance is available only with @deepseq >= 1.4.3.0@ instance (NFData1 f, NFData1 g, NFData a) => NFData (These1 f g a) where rnf = rnf1-#endif------------------------------------------------------------------------------------ aeson----------------------------------------------------------------------------------#ifdef MIN_VERSION_aeson-instance (ToJSON1 f, ToJSON1 g) => ToJSON1 (These1 f g) where- liftToJSON tx tl (This1 a) = Aeson.object [ "This" .= liftToJSON tx tl a ]- liftToJSON tx tl (That1 b) = Aeson.object [ "That" .= liftToJSON tx tl b ]- liftToJSON tx tl (These1 a b) = Aeson.object [ "This" .= liftToJSON tx tl a, "That" .= liftToJSON tx tl b ]-- liftToEncoding tx tl (This1 a) = Aeson.pairs $ Aeson.pair "This" (liftToEncoding tx tl a)- liftToEncoding tx tl (That1 b) = Aeson.pairs $ Aeson.pair "That" (liftToEncoding tx tl b)- liftToEncoding tx tl (These1 a b) = Aeson.pairs $- Aeson.pair "This" (liftToEncoding tx tl a) `mappend`- Aeson.pair "That" (liftToEncoding tx tl b)--instance (FromJSON1 f, FromJSON1 g) => FromJSON1 (These1 f g) where- liftParseJSON px pl = Aeson.withObject "These1" (p . HM.toList)- where- p [("This", a), ("That", b)] = These1 <$> liftParseJSON px pl a <*> liftParseJSON px pl b- p [("That", b), ("This", a)] = These1 <$> liftParseJSON px pl a <*> liftParseJSON px pl b- p [("This", a)] = This1 <$> liftParseJSON px pl a- p [("That", b)] = That1 <$> liftParseJSON px pl b- p _ = fail "Expected object with 'This' and 'That' keys only"--instance (ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (These1 f g a) where- toJSON = Aeson.toJSON1- toEncoding = Aeson.toEncoding1--instance (FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (These1 f g a) where- parseJSON = Aeson.parseJSON1-#endif------------------------------------------------------------------------------------ QuickCheck----------------------------------------------------------------------------------#ifdef MIN_VERSION_QuickCheck-instance (Arbitrary1 f, Arbitrary1 g) => Arbitrary1 (These1 f g) where- liftArbitrary arb = oneof- [ This1 <$> liftArbitrary arb- , That1 <$> liftArbitrary arb- , These1 <$> liftArbitrary arb <*> liftArbitrary arb- ]-- liftShrink shr (This1 x) = This1 <$> liftShrink shr x- liftShrink shr (That1 y) = That1 <$> liftShrink shr y- liftShrink shr (These1 x y) =- [ This1 x, That1 y ] ++- [ These1 x' y'- | (x', y') <- liftShrink2 (liftShrink shr) (liftShrink shr) (x, y)- ]--instance (Arbitrary1 f, Arbitrary1 g, Arbitrary a) => Arbitrary (These1 f g a) where- arbitrary = arbitrary1- shrink = shrink1 #endif
src/Data/These.hs view
@@ -46,33 +46,11 @@ import GHC.Generics (Generic1) #endif -#ifdef MIN_VERSION_aeson-import Data.Aeson (FromJSON (..), ToJSON (..), (.=))--import qualified Data.Aeson as Aeson-import qualified Data.Aeson.Encoding as Aeson (pair)-import qualified Data.HashMap.Strict as HM-#endif- #ifdef MIN_VERSION_assoc import Data.Bifunctor.Assoc (Assoc (..)) import Data.Bifunctor.Swap (Swap (..)) #endif -#ifdef MIN_VERSION_semigroupoids-import Data.Functor.Bind (Apply (..), Bind (..))-import Data.Semigroup.Bifoldable (Bifoldable1 (..))-import Data.Semigroup.Bitraversable (Bitraversable1 (..))-#endif--#ifdef MIN_VERSION_QuickCheck-import Test.QuickCheck- (Arbitrary (..), Arbitrary1 (..), Arbitrary2 (..), CoArbitrary (..),- arbitrary1, oneof, shrink1)-import Test.QuickCheck.Function (Function (..), functionMap)-#endif-- -- $setup -- >>> import Control.Lens @@ -164,10 +142,10 @@ -- @since 1.0.1 partitionEithersNE :: NonEmpty (Either a b) -> These (NonEmpty a) (NonEmpty b) partitionEithersNE (x :| xs) = case (x, ls, rs) of- (Left y, ys, []) -> This (y :| ys)- (Left y, ys, (z:zs)) -> These (y :| ys) (z :| zs)- (Right z, [], zs) -> That (z :| zs)- (Right z, (y:ys), zs) -> These (y :| ys) (z :| zs)+ (Left y, ys, []) -> This (y :| ys)+ (Left y, ys, z:zs) -> These (y :| ys) (z :| zs)+ (Right z, [], zs) -> That (z :| zs)+ (Right z, y:ys, zs) -> These (y :| ys) (z :| zs) where (ls, rs) = partitionEithers xs @@ -331,145 +309,3 @@ 1 -> That <$> get 2 -> These <$> get <*> get _ -> fail "Invalid These index"------------------------------------------------------------------------------------ semigroupoids----------------------------------------------------------------------------------#ifdef MIN_VERSION_semigroupoids-instance Bifoldable1 These where- bifold1 = these id id (<>)--instance Bitraversable1 These where- bitraverse1 f _ (This x) = This <$> f x- bitraverse1 _ g (That x) = That <$> g x- bitraverse1 f g (These x y) = These <$> f x <.> g y--instance (Semigroup a) => Bind (These a) where- This a >>- _ = This a- That x >>- k = k x- These a x >>- k = case k x of- This b -> This (a <> b)- That y -> These a y- These b y -> These (a <> b) y--instance (Semigroup a) => Apply (These a) where- This a <.> _ = This a- That _ <.> This b = This b- That f <.> That x = That (f x)- That f <.> These b x = These b (f x)- These a _ <.> This b = This (a <> b)- These a f <.> That x = These a (f x)- These a f <.> These b x = These (a <> b) (f x)-#endif------------------------------------------------------------------------------------ aeson----------------------------------------------------------------------------------#ifdef MIN_VERSION_aeson---- | @since 0.7.1-instance (ToJSON a, ToJSON b) => ToJSON (These a b) where- toJSON (This a) = Aeson.object [ "This" .= a ]- toJSON (That b) = Aeson.object [ "That" .= b ]- toJSON (These a b) = Aeson.object [ "This" .= a, "That" .= b ]-- toEncoding (This a) = Aeson.pairs $ "This" .= a- toEncoding (That b) = Aeson.pairs $ "That" .= b- toEncoding (These a b) = Aeson.pairs $ "This" .= a <> "That" .= b---- | @since 0.7.1-instance (FromJSON a, FromJSON b) => FromJSON (These a b) where- parseJSON = Aeson.withObject "These a b" (p . HM.toList)- where- p [("This", a), ("That", b)] = These <$> parseJSON a <*> parseJSON b- p [("That", b), ("This", a)] = These <$> parseJSON a <*> parseJSON b- p [("This", a)] = This <$> parseJSON a- p [("That", b)] = That <$> parseJSON b- p _ = fail "Expected object with 'This' and 'That' keys only"---- | @since 0.7.2-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)---- | @since 0.7.2-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)---- | @since 0.7.2-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"---- | @since 0.7.2-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------------------------------------------------------------------------------------ QuickCheck----------------------------------------------------------------------------------#ifdef MIN_VERSION_QuickCheck--- | @since 0.7.4-instance Arbitrary2 These where- liftArbitrary2 arbA arbB = oneof- [ This <$> arbA- , That <$> arbB- , These <$> arbA <*> arbB- ]-- liftShrink2 shrA _shrB (This x) = This <$> shrA x- liftShrink2 _shrA shrB (That y) = That <$> shrB y- liftShrink2 shrA shrB (These x y) =- [This x, That y] ++ [These x' y' | (x', y') <- liftShrink2 shrA shrB (x, y)]---- | @since 0.7.4-instance (Arbitrary a) => Arbitrary1 (These a) where- liftArbitrary = liftArbitrary2 arbitrary- liftShrink = liftShrink2 shrink---- | @since 0.7.1-instance (Arbitrary a, Arbitrary b) => Arbitrary (These a b) where- arbitrary = arbitrary1- shrink = shrink1---- | @since 0.7.1-instance (Function a, Function b) => Function (These a b) where- function = functionMap g f- where- g (This a) = Left a- g (That b) = Right (Left b)- g (These a b) = Right (Right (a, b))-- f (Left a) = This a- f (Right (Left b)) = That b- f (Right (Right (a, b))) = These a b---- | @since 0.7.1-instance (CoArbitrary a, CoArbitrary b) => CoArbitrary (These a b)-#endif
src/Data/These/Combinators.hs view
@@ -1,5 +1,5 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP #-} -- | This module provides -- -- * specialised versions of class members e.g. 'bitraverseThese'@@ -83,9 +83,9 @@ import Prelude () import Prelude.Compat -import Data.Bifunctor (bimap, first, second)-import Data.Bitraversable (bitraverse)-import Data.Maybe (isJust, mapMaybe)+import Data.Bifunctor (bimap, first, second)+import Data.Bitraversable (bitraverse)+import Data.Maybe (isJust, mapMaybe) import Data.These #ifdef MIN_VERSION_assoc
these.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: these-version: 1.0.1+version: 1.1 synopsis: An either-or-both data type. homepage: https://github.com/isomorphism/these license: BSD3@@ -31,32 +31,27 @@ * <http://hackage.haskell.org/package/monad-chronicle monad-chronicle> For transformers variant of @These@. tested-with:- GHC ==7.4.2 || ==7.6.3 || ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1+ GHC ==7.4.2+ || ==7.6.3+ || ==7.8.4+ || ==7.10.3+ || ==8.0.2+ || ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.3+ || ==8.10.1+ , GHCJS ==8.4 source-repository head type: git location: https://github.com/isomorphism/these.git -flag aeson- description: Build with aeson dependency- manual: True- default: True- flag assoc description: Build with assoc dependency manual: True default: True -flag semigroupoids- description: Build with semigroupoids dependency- manual: True- default: True--flag QuickCheck- description: Build with QuickCheck dependency- manual: True- default: True- library default-language: Haskell2010 ghc-options: -Wall@@ -72,13 +67,13 @@ -- ghc boot libs build-depends:- base >=4.5.1.0 && <4.13+ base >=4.5.1.0 && <4.15 , binary >=0.5.1.0 && <0.10 , deepseq >=1.3.0.0 && <1.5 -- other dependencies build-depends:- base-compat >=0.10.5 && <0.11+ base-compat >=0.10.5 && <0.12 , hashable >=1.2.7.0 && <1.4 if impl(ghc <7.5)@@ -97,16 +92,5 @@ if impl(ghc >=7.10) build-depends: transformers >=0.4.2.0 - if flag(aeson)- build-depends:- aeson >=1.4.2.0 && <1.5- , unordered-containers >=0.2.8.0 && <0.3- if flag(assoc) build-depends: assoc >=1 && <1.1-- if flag(semigroupoids)- build-depends: semigroupoids >=5.3.2 && <5.4-- if flag(quickcheck)- build-depends: QuickCheck >=2.12.6.1 && <2.14