From 7f4e7c0ee00e10b9c4db4ff6ba65f0490b0bb672 Mon Sep 17 00:00:00 2001 From: iko Date: Thu, 2 Jul 2020 22:54:51 +0300 Subject: [PATCH 1/2] Added promoting warnings to errors --- src/Control/Monad/Validation.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Control/Monad/Validation.hs b/src/Control/Monad/Validation.hs index 293cb40..9cb3141 100644 --- a/src/Control/Monad/Validation.hs +++ b/src/Control/Monad/Validation.hs @@ -16,6 +16,7 @@ module Control.Monad.Validation , vWarningL , vZoom , vZoomL + , vPromote , mmSingleton , setMempty , neConcat @@ -143,12 +144,12 @@ neConcat f a textErrors :: [Text] -> Maybe Text textErrors = neConcat (\a b -> a <> ", " <> b) --- | Returns 'mempty' instead of error if no warnings have occured. +-- | Returns 'mempty' instead of error if no warnings have occurred. -- Returns 'Nothing' as the second element of tuple if computation was -- interrupted by 'vError'. -- -- Returns all concatenated errors and warnings and the result if no --- errors have occured (warnings could have occured). +-- errors have occurred (warnings could have occurred). -- -- >>> :{ -- runValidationT $ do @@ -174,7 +175,7 @@ runValidationT (ValidationT m) = do Right a -> (warnings, Just a) -- | Like 'runValidationT' but doesn't return the result --- if any warning has occured. +-- if any warning has occurred. -- -- >>> :{ -- runValidationTEither $ do @@ -285,3 +286,12 @@ vZoomL -> ValidationT a m x -> ValidationT b m x vZoomL l = vZoom (setMempty l) + +-- | Turn any warnings the have occurred into errors. +vPromote + :: (Monad m, Monoid a, Eq a) + => ValidationT a m x + -> ValidationT a m x +vPromote m = do + err <- lift $ runValidationTEither m + either vError return err From ea290fa224171b67ad9ca653a40a3c2e20e46f5e Mon Sep 17 00:00:00 2001 From: iko Date: Thu, 2 Jul 2020 23:07:07 +0300 Subject: [PATCH 2/2] Bumped version --- validationt.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validationt.cabal b/validationt.cabal index 21fbe1f..2930eab 100644 --- a/validationt.cabal +++ b/validationt.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: validationt -version: 0.3.0 +version: 0.3.1 synopsis: Straightforward validation monad. description: Convenient solution for validating web forms and APIs. homepage: https://github.com/typeable/validationt