-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Straightforward validation monad -- -- A simple data validation library. The main idea is to provide an easy -- way to validate web form data by aggregating errors for each field. @package validationt @version 0.3.0 module Control.Monad.Validation -- | Collects all thrown warnings in StateT and errors in -- ExceptT into a single value using Monoid. newtype ValidationT e m a ValidationT :: ExceptT e (StateT e m) a -> ValidationT e m a [unValidationT] :: ValidationT e m a -> ExceptT e (StateT e m) a -- | 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 occurred (warnings could have occurred). -- --
--   >>> :{
--    runValidationT $ do
--      vWarning ["warning1"]
--      vError ["error"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   (["error","warning1"],Nothing)
--   
-- --
--   >>> :{
--    runValidationT $ do
--      vWarning ["warning1"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   (["warning1","warning2"],Just 8)
--   
runValidationT :: (Monoid e, Monad m) => ValidationT e m a -> m (e, Maybe a) -- | Like runValidationT but doesn't return the result if any -- warning has occurred. -- --
--   >>> :{
--    runValidationTEither $ do
--      vWarning ["warning1"]
--      vError ["error"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   Left ["error","warning1"]
--   
-- --
--   >>> :{
--    runValidationTEither $ do
--      vWarning ["warning1"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   Left ["warning1","warning2"]
--   
runValidationTEither :: (Monoid e, Eq e, Monad m) => ValidationT e m a -> m (Either e a) -- | Like runValidationTEither, but takes an error handler instead -- of returning errors and warnings. -- --
--   >>> :{
--    handleValidationT (\_ -> return 11) $ do
--      vWarning ["warning1"]
--      vError ["error"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   11
--   
-- --
--   >>> :{
--    handleValidationT (\_ -> return 11) $ do
--      vWarning ["warning1"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   11
--   
handleValidationT :: (Monoid e, Monad m, Eq e) => (e -> m a) -> ValidationT e m a -> m a -- | Stops further execution and appends the given error. vError :: Monad m => e -> ValidationT e m a -- | Does not stop further execution and appends the given warning. vWarning :: (Monad m, Monoid e) => e -> ValidationT e m () -- | Like vError but allows you to use a setter to insert an error -- somewhere deeper into an empty (mempty) "e" from "ValidationT e -- m x", which is then combined with all gathered warnings. vErrorL :: (Monad m, Monoid e) => ASetter' e a -> a -> ValidationT e m x -- | Like vWarning but allows you to use a setter to insert an error -- somewhere deeper into an empty (mempty) "e" from "ValidationT e -- m x", which is then combined with all gathered warnings. vWarningL :: (Monad m, Monoid e) => ASetter' e a -> a -> ValidationT e m () -- | Allows you apply a transformation to the "e" in "ValidationT e m x". -- --
--   >>> :{
--   runValidationT . vZoom (Data.Map.singleton "password errors") $ do
--    vWarning ["warning1"]
--    vError ["error"]
--    vWarning ["warning2"]
--    return 8
--   :}
--   (fromList [("password errors",["error","warning1"])],Nothing)
--   
-- --
--   >>> :{
--    runValidationT . vZoom (Data.Map.singleton "password errors") $ do
--      vWarning ["warning1"]
--      vWarning ["warning2"]
--      return 8
--   :}
--   (fromList [("password errors",["warning1","warning2"])],Just 8)
--   
vZoom :: (Monad m, Monoid a, Monoid b) => (a -> b) -> ValidationT a m x -> ValidationT b m x -- | Like vZoom but takes a setter instead of a function. vZoomL :: (Monad m, Monoid a, Monoid b) => ASetter' b a -> ValidationT a m x -> ValidationT b m x -- | Turn any warnings the have occurred into errors. vPromote :: (Monad m, Monoid a, Eq a) => ValidationT a m x -> ValidationT a m x -- | Convenient for vZoom as first argument. Will prevent generation -- of map with mempty values. mmSingleton :: (Eq v, Monoid v, Ord k) => k -> v -> MonoidMap k v -- | Sets given value to mempty. setMempty :: Monoid s => ASetter' s a -> a -> s neConcat :: Foldable f => (a -> a -> a) -> f a -> Maybe a -- | Returns the strings, concatanated with ", " if the list is -- not empty. -- -- Returns Nothing if the list is empty -- --
--   >>> textErrors ["foo", "bar"]
--   Just "foo, bar"
--   
-- --
--   >>> textErrors ["foo"]
--   Just "foo"
--   
-- --
--   >>> textErrors []
--   Nothing
--   
textErrors :: [Text] -> Maybe Text _MonoidMap :: forall k_aaP3 v_aaP4 k_afwg v_afwh. Iso (MonoidMap k_afwg v_afwh) (MonoidMap k_aaP3 v_aaP4) (Map k_afwg v_afwh) (Map k_aaP3 v_aaP4) -- | Map with Monoid instance which mappend its values -- -- This can be used as the e in `ValidationT e m a` to provide -- different sets of errors and warnings for different keys. -- --
--   >>> :{
--     mconcat
--     [ MonoidMap $ M.fromList [(1, "foo"), (2, "hello, "), (3, "oh no")]
--     , MonoidMap $ M.fromList [(1, "bar"), (2, "world")]
--     ]
--   :}
--   MonoidMap (fromList [(1,"foobar"),(2,"hello, world"),(3,"oh no")])
--   
newtype MonoidMap k v MonoidMap :: Map k v -> MonoidMap k v instance GHC.Classes.Ord k => Control.Lens.At.Ixed (Control.Monad.Validation.MonoidMap k v) instance GHC.Classes.Ord k => Control.Lens.At.At (Control.Monad.Validation.MonoidMap k v) instance (GHC.Classes.Ord k, GHC.Base.Semigroup v) => GHC.Base.Semigroup (Control.Monad.Validation.MonoidMap k v) instance (GHC.Classes.Ord k, GHC.Base.Monoid v) => GHC.Base.Monoid (Control.Monad.Validation.MonoidMap k v) instance (Data.Aeson.Types.ToJSON.ToJSON k, Data.Aeson.Types.ToJSON.ToJSON v) => Data.Aeson.Types.ToJSON.ToJSON (Control.Monad.Validation.MonoidMap k v) instance (GHC.Classes.Ord k, Data.Aeson.Types.FromJSON.FromJSON k, Data.Aeson.Types.FromJSON.FromJSON v) => Data.Aeson.Types.FromJSON.FromJSON (Control.Monad.Validation.MonoidMap k v) instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (Control.Monad.Validation.ValidationT e m) instance Control.Monad.Trans.Control.MonadBaseControl b m => Control.Monad.Trans.Control.MonadBaseControl b (Control.Monad.Validation.ValidationT e m) instance (GHC.Base.Monad m, GHC.Base.Monoid e) => GHC.Base.MonadPlus (Control.Monad.Validation.ValidationT e m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.Validation.ValidationT e m) instance Data.Functor.Contravariant.Contravariant m => Data.Functor.Contravariant.Contravariant (Control.Monad.Validation.ValidationT e m) instance Control.Monad.Fail.MonadFail m => Control.Monad.Fail.MonadFail (Control.Monad.Validation.ValidationT e m) instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Control.Monad.Validation.ValidationT e m) instance (GHC.Base.Monad m, GHC.Base.Monoid e) => GHC.Base.Alternative (Control.Monad.Validation.ValidationT e m) instance Control.Monad.Base.MonadBase b m => Control.Monad.Base.MonadBase b (Control.Monad.Validation.ValidationT e m) instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (Control.Monad.Validation.ValidationT e m) instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (Control.Monad.Validation.ValidationT e m) instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.Validation.ValidationT e m) instance GHC.Base.Monad m => GHC.Base.Applicative (Control.Monad.Validation.ValidationT e m) instance GHC.Base.Functor m => GHC.Base.Functor (Control.Monad.Validation.ValidationT e m) instance Data.Foldable.Foldable (Control.Monad.Validation.MonoidMap k) instance (GHC.Classes.Ord k, Test.QuickCheck.Arbitrary.Arbitrary k, Test.QuickCheck.Arbitrary.Arbitrary v) => Test.QuickCheck.Arbitrary.Arbitrary (Control.Monad.Validation.MonoidMap k v) instance (GHC.Show.Show k, GHC.Show.Show v) => GHC.Show.Show (Control.Monad.Validation.MonoidMap k v) instance (GHC.Classes.Ord k, GHC.Classes.Ord v) => GHC.Classes.Ord (Control.Monad.Validation.MonoidMap k v) instance (GHC.Classes.Eq k, GHC.Classes.Eq v) => GHC.Classes.Eq (Control.Monad.Validation.MonoidMap k v) instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.Validation.ValidationT e)