diff --git a/src/Data/Validation.hs b/src/Data/Validation.hs index 7e19153..c1f6338 100644 --- a/src/Data/Validation.hs +++ b/src/Data/Validation.hs @@ -59,7 +59,6 @@ import Data.Functor(Functor(fmap)) import Data.Functor.Alt(Alt(())) import Data.Functor.Apply(Apply((<.>))) import Data.List.NonEmpty (NonEmpty) -import Data.Monoid(Monoid(mappend, mempty)) import Data.Ord(Ord) import Data.Semigroup(Semigroup((<>))) import Data.Traversable(Traversable(traverse)) @@ -164,10 +163,10 @@ appValidation :: -> Validation err a appValidation m (Failure e1) (Failure e2) = Failure (e1 `m` e2) -appValidation _ (Failure _) (Success a2) = - Success a2 -appValidation _ (Success a1) (Failure _) = - Success a1 +appValidation _ (Failure e1) (Success _) = + Failure e1 +appValidation _ (Success _) (Failure e2) = + Failure e2 appValidation _ (Success a1) (Success _) = Success a1 {-# INLINE appValidation #-} @@ -177,14 +176,6 @@ instance Semigroup e => Semigroup (Validation e a) where appValidation (<>) {-# INLINE (<>) #-} -instance Monoid e => Monoid (Validation e a) where - mappend = - appValidation mappend - {-# INLINE mappend #-} - mempty = - Failure mempty - {-# INLINE mempty #-} - instance Swapped Validation where swapped = iso diff --git a/test/hedgehog_tests.hs b/test/hedgehog_tests.hs index 3a4e6a8..60553ee 100644 --- a/test/hedgehog_tests.hs +++ b/test/hedgehog_tests.hs @@ -18,9 +18,6 @@ main = do result <- checkParallel $ Group "Validation" [ ("prop_semigroup", prop_semigroup) - , ("prop_monoid_assoc", prop_monoid_assoc) - , ("prop_monoid_left_id", prop_monoid_left_id) - , ("prop_monoid_right_id", prop_monoid_right_id) ] unless result $ @@ -44,19 +41,3 @@ mkAssoc f = prop_semigroup :: Property prop_semigroup = mkAssoc (<>) - -prop_monoid_assoc :: Property -prop_monoid_assoc = mkAssoc mappend - -prop_monoid_left_id :: Property -prop_monoid_left_id = - property $ do - x <- forAll testGen - (mempty `mappend` x) === x - -prop_monoid_right_id :: Property -prop_monoid_right_id = - property $ do - x <- forAll testGen - (x `mappend` mempty) === x - diff --git a/test/hunit_tests.hs b/test/hunit_tests.hs index 2e2340f..67b7d23 100644 --- a/test/hunit_tests.hs +++ b/test/hunit_tests.hs @@ -9,6 +9,7 @@ import Control.Lens ((#)) import Control.Monad (when) import Data.Foldable (length) import Data.Proxy (Proxy (Proxy)) +import Data.Semigroup(Semigroup((<>))) import Data.Validation (Validation (Success, Failure), Validate, _Failure, _Success, ensure, orElse, validate, validation, validationNel) import System.Exit (exitFailure) @@ -111,6 +112,38 @@ testValidateNothing = option = Nothing :: Maybe Int in TestCase (assertEqual "testValidateFalse" subject expected) +testMappendNY :: Test +testMappendNY = + let v1 = Failure [three] + v2 = Success seven + subject = v1 <> v2 + expected = Failure [three] + in TestCase (assertEqual "Failure <> Success" subject expected) + +testMappendYN :: Test +testMappendYN = + let v1 = Success three + v2 = Failure [seven] + subject = v1 <> v2 + expected = Failure [seven] + in TestCase (assertEqual "Success <> Failure" subject expected) + +testMappendYY :: Test +testMappendYY = + let v1 = Success three + v2 = Success seven + subject = v1 <> v2 :: Validation [Int] Int + expected = Success three + in TestCase (assertEqual "Success <> Success" subject expected) + +testMappendNN :: Test +testMappendNN = + let v1 = Failure [three] + v2 = Failure [seven] + subject = v1 <> v2 :: Validation [Int] Int + expected = Failure [three, seven] + in TestCase (assertEqual "Failure <> Failure" subject expected) + tests :: Test tests = let eitherP :: Proxy Either @@ -123,7 +156,7 @@ tests = , testEnsureLeftJust , testEnsureRightNothing , testEnsureRightJust - , testEnsureRightJust' + , testEnsureRightJust' , testOrElseLeft , testOrElseRight ] @@ -138,6 +171,10 @@ tests = , testValidateNothing , testValidateJust , testValidateJust' + , testMappendNY + , testMappendYY + , testMappendNN + , testMappendYN ] ++ eithers ++ validations where