Safe Haskell | None |
---|
A validation monad and corresponding utilities
The monad allows code to emit errors during checking.
Synopsis
- 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 String m => (a, [String]) -> m a
- evalValidate :: MonadError String m => ValidationMonad a -> m a
- evalValidateT :: MonadError String m => 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.
ValidationMonad | |
|
Instances
Monad m => Monad (ValidationMonadT m) # | |
Defined in Ganeti.Utils.Validate (>>=) :: ValidationMonadT m a -> (a -> ValidationMonadT m b) -> ValidationMonadT m b (>>) :: ValidationMonadT m a -> ValidationMonadT m b -> ValidationMonadT m b return :: a -> ValidationMonadT m a | |
Functor m => Functor (ValidationMonadT m) # | |
Defined in Ganeti.Utils.Validate fmap :: (a -> b) -> ValidationMonadT m a -> ValidationMonadT m b (<$) :: a -> ValidationMonadT m b -> ValidationMonadT m a | |
Applicative m => Applicative (ValidationMonadT m) # | |
Defined in Ganeti.Utils.Validate pure :: a -> ValidationMonadT m a (<*>) :: ValidationMonadT m (a -> b) -> ValidationMonadT m a -> ValidationMonadT m b liftA2 :: (a -> b -> c) -> ValidationMonadT m a -> ValidationMonadT m b -> ValidationMonadT m c (*>) :: ValidationMonadT m a -> ValidationMonadT m b -> ValidationMonadT m b (<*) :: ValidationMonadT m a -> ValidationMonadT m b -> ValidationMonadT m a |
type ValidationMonad = ValidationMonadT Identity Source #
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 String m => (a, [String]) -> m a Source #
A helper function for throwing an exception if a list of errors is non-empty.
evalValidate :: MonadError String m => ValidationMonad a -> m a Source #
Runs a validation action and if there are errors, combine them into an exception.
evalValidateT :: MonadError String m => ValidationMonadT m a -> m a Source #
Runs a validation action and if there are errors, combine them into an exception.
class Validatable a where Source #
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.
validate :: a -> ValidationMonad () Source #
Instances
Validatable LogicalVolume # | Check the constraints for VG/LV names (except the |
Defined in Ganeti.Objects.Disk validate :: LogicalVolume -> ValidationMonad () Source # |
validate' :: Validatable a => a -> ValidationMonad a Source #
Run validation and return the original value as well. the original value.