ganeti

Safe HaskellNone

Ganeti.Utils.Validate

Description

A validation monad and corresponding utilities

The monad allows code to emit errors during checking.

Synopsis

Documentation

newtype ValidationMonadT m a Source

Monad for running validation checks.

Constructors

ValidationMonad 

Fields

runValidationMonad :: WriterT (Seq String) m a
 

Instances

Monad m => Monad (ValidationMonadT m) 
Functor m => Functor (ValidationMonadT m) 
Applicative m => Applicative (ValidationMonadT m) 

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, Error e) => (a, [String]) -> m aSource

evalValidate :: (MonadError e m, Error e) => ValidationMonad a -> m aSource

Runs a validation action and if there are errors, combine them into an exception.

evalValidateT :: (MonadError e m, Error 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.

validate' :: Validatable a => a -> ValidationMonad aSource

Run validation and return the original value as well. the original value.