@@ -16,6 +16,7 @@ module Control.Monad.Validation
16 , vWarningL
16 , vWarningL
19 , mmSingleton
20 , mmSingleton
20 , setMempty
21 , setMempty
21 , neConcat
22 , neConcat
@@ -37,11 +38,14 @@ import Data.Foldable as F
37import Data.Functor
38import Data.Functor
38import Data.List as L
39import Data.List as L
39import Data.Map.Strict as M
40import Data.Map.Strict as M
41import Data.Text as T
41import Data.Text as T
42import Data.Vector as V
42import Data.Vector as V
43import Test.QuickCheck
43import Test.QuickCheck
45+#if MIN_VERSION_mtl(2,3,0)
47+import Control.Monad.Fix
46-- | Collects all thrown warnings in 'StateT' and errors
50-- | Collects all thrown warnings in 'StateT' and errors
47-- in 'ExceptT' into a single value using 'Monoid'.
51-- in 'ExceptT' into a single value using 'Monoid'.
@@ -85,7 +89,7 @@ instance (Ord k, Semigroup v) => Semigroup (MonoidMap k v) where
86instance (Ord k, Monoid v) => Monoid (MonoidMap k v) where
90instance (Ord k, Monoid v) => Monoid (MonoidMap k v) where
87 mempty = MonoidMap M.empty
91 mempty = MonoidMap M.empty
88− mappend = mmAppend
92+ mappend = (<>)
90instance (ToJSON k, ToJSON v) => ToJSON (MonoidMap k v) where
94instance (ToJSON k, ToJSON v) => ToJSON (MonoidMap k v) where
91 toJSON (MonoidMap m) = toJSON $ L.map toObj $ M.toList m
95 toJSON (MonoidMap m) = toJSON $ L.map toObj $ M.toList m
@@ -143,12 +147,12 @@ neConcat f a
143textErrors :: [Text] -> Maybe Text
147textErrors :: [Text] -> Maybe Text
144textErrors = neConcat (\a b -> a <> ", " <> b)
148textErrors = neConcat (\a b -> a <> ", " <> b)
146−-- | Returns 'mempty' instead of error if no warnings have occured.
150+-- | Returns 'mempty' instead of error if no warnings have occurred.
147-- Returns 'Nothing' as the second element of tuple if computation was
151-- Returns 'Nothing' as the second element of tuple if computation was
148-- interrupted by 'vError'.
152-- interrupted by 'vError'.
150-- Returns all concatenated errors and warnings and the result if no
154-- Returns all concatenated errors and warnings and the result if no
151−-- errors have occured (warnings could have occured).
155+-- errors have occurred (warnings could have occurred).
154-- runValidationT $ do
158-- runValidationT $ do
@@ -174,7 +178,7 @@ runValidationT (ValidationT m) = do
174 Right a -> (warnings, Just a)
178 Right a -> (warnings, Just a)
176-- | Like 'runValidationT' but doesn't return the result
180-- | Like 'runValidationT' but doesn't return the result
177−-- if any warning has occured.
181+-- if any warning has occurred.
180-- runValidationTEither $ do
184-- runValidationTEither $ do
@@ -285,3 +289,12 @@ vZoomL
285 -> ValidationT a m x
289 -> ValidationT a m x
286 -> ValidationT b m x
290 -> ValidationT b m x
287vZoomL l = vZoom (setMempty l)
291vZoomL l = vZoom (setMempty l)
293+-- | Turn any warnings the have occurred into errors.
295+ :: (Monad m, Monoid a, Eq a)
296+ => ValidationT a m x
297+ -> ValidationT a m x
299+ err <- lift $ runValidationTEither m
300+ either vError return err