Safe Haskell | None |
---|
Ganeti.Utils.Validate
Description
A validation monad and corresponding utilities
The monad allows code to emit errors during checking.
- newtype ValidationMonadT m a = ValidationMonad {
- runValidationMonad :: WriterT (Seq String) m a
- type ValidationMonad = ValidationMonadT Identity
- report :: Monad m => String -> ValidationMonadT m ()
- reportIf :: Monad m => Bool -> String -> ValidationMonadT m ()
- runValidateT :: Monad m => ValidationMonadT m a -> m (a, [String])
- runValidate :: ValidationMonad a -> (a, [String])
- execValidateT :: Monad m => ValidationMonadT m () -> m [String]
- execValidate :: ValidationMonad () -> [String]
- throwIfErrors :: (MonadError e m, FromString e) => (a, [String]) -> m a
- evalValidate :: (MonadError e m, FromString e) => ValidationMonad a -> m a
- evalValidateT :: (MonadError e m, FromString e) => ValidationMonadT m a -> m a
- class Validatable a where
- validate :: a -> ValidationMonad ()
- validate' :: Validatable a => a -> ValidationMonad a
Documentation
newtype ValidationMonadT m a Source
Monad for running validation checks.
Constructors
ValidationMonad | |
Fields
|
Instances
Monad m => Monad (ValidationMonadT m) | |
Functor m => Functor (ValidationMonadT m) | |
Applicative m => Applicative (ValidationMonadT m) |
type ValidationMonad = ValidationMonadT IdentitySource
report :: Monad m => String -> ValidationMonadT m ()Source
An utility function that emits a single message into a validation monad.
reportIf :: Monad m => Bool -> String -> ValidationMonadT m ()Source
An utility function that conditionally emits a message into
a validation monad.
It's a combination of when
and report
.
runValidateT :: Monad m => ValidationMonadT m a -> m (a, [String])Source
An utility function that runs a monadic validation action and returns the list of errors.
runValidate :: ValidationMonad a -> (a, [String])Source
An utility function that runs a monadic validation action and returns the list of errors.
execValidateT :: Monad m => ValidationMonadT m () -> m [String]Source
An utility function that runs a monadic validation action and returns the list of errors.
execValidate :: ValidationMonad () -> [String]Source
An utility function that runs a validation action and returns the list of errors.
throwIfErrors :: (MonadError e m, FromString e) => (a, [String]) -> m aSource
evalValidate :: (MonadError e m, FromString e) => ValidationMonad a -> m aSource
Runs a validation action and if there are errors, combine them into an exception.
evalValidateT :: (MonadError e m, FromString e) => ValidationMonadT m a -> m aSource
Runs a validation action and if there are errors, combine them into an exception.
class Validatable a whereSource
A typeclass for objects that can be validated. That is, they can perform an internal check and emit any errors encountered. Emiting no errors means the object is valid.
Methods
validate :: a -> ValidationMonad ()Source
Instances
Validatable LogicalVolume | Check the constraints for a VGLV names (except the \@\dev/@ check). |
validate' :: Validatable a => a -> ValidationMonad aSource
Run validation and return the original value as well. the original value.