git.iko.soy/typeable/validationt
on master help sign in
Added promoting warnings to errors
7f4e7c0iko
src/Control/Monad/Validation.hs+13−3
@@ -16,6 +16,7 @@ module Control.Monad.Validation
16 , vWarningL
16 , vWarningL
17 , vZoom
17 , vZoom
18 , vZoomL
18 , vZoomL
19+ , vPromote
19 , mmSingleton
20 , mmSingleton
20 , setMempty
21 , setMempty
21 , neConcat
22 , neConcat
@@ -143,12 +144,12 @@ neConcat f a
143textErrors :: [Text] -> Maybe Text
144textErrors :: [Text] -> Maybe Text
144textErrors = neConcat (\a b -> a <> ", " <> b)
145textErrors = neConcat (\a b -> a <> ", " <> b)
145
146
146−-- | Returns 'mempty' instead of error if no warnings have occured.
147+-- | Returns 'mempty' instead of error if no warnings have occurred.
147-- Returns 'Nothing' as the second element of tuple if computation was
148-- Returns 'Nothing' as the second element of tuple if computation was
148-- interrupted by 'vError'.
149-- interrupted by 'vError'.
149--
150--
150-- Returns all concatenated errors and warnings and the result if no
151-- Returns all concatenated errors and warnings and the result if no
151−-- errors have occured (warnings could have occured).
152+-- errors have occurred (warnings could have occurred).
152--
153--
153-- >>> :{
154-- >>> :{
154-- runValidationT $ do
155-- runValidationT $ do
@@ -174,7 +175,7 @@ runValidationT (ValidationT m) = do
174 Right a -> (warnings, Just a)
175 Right a -> (warnings, Just a)
175
176
176-- | Like 'runValidationT' but doesn't return the result
177-- | Like 'runValidationT' but doesn't return the result
177−-- if any warning has occured.
178+-- if any warning has occurred.
178--
179--
179-- >>> :{
180-- >>> :{
180-- runValidationTEither $ do
181-- runValidationTEither $ do
@@ -285,3 +286,12 @@ vZoomL
285 -> ValidationT a m x
286 -> ValidationT a m x
286 -> ValidationT b m x
287 -> ValidationT b m x
287vZoomL l = vZoom (setMempty l)
288vZoomL l = vZoom (setMempty l)
289+
290+-- | Turn any warnings the have occurred into errors.
291+vPromote
292+ :: (Monad m, Monoid a, Eq a)
293+ => ValidationT a m x
294+ -> ValidationT a m x
295+vPromote m = do
296+ err <- lift $ runValidationTEither m
297+ either vError return err