validate-input-0.5.0.0: Input validation combinator library
Safe HaskellNone
LanguageHaskell2010

Data.Validator

Synopsis

Core monad and runners

type ValidationM e = ValidationT e Identity Source #

The validation monad

data ValidationT e m a Source #

The validation monad transformer

Instances

Instances details
MonadTrans (ValidationT e) Source # 
Instance details

Defined in Data.Validator

Methods

lift :: Monad m => m a -> ValidationT e m a #

Monad m => Monad (ValidationT e m) Source # 
Instance details

Defined in Data.Validator

Methods

(>>=) :: ValidationT e m a -> (a -> ValidationT e m b) -> ValidationT e m b #

(>>) :: ValidationT e m a -> ValidationT e m b -> ValidationT e m b #

return :: a -> ValidationT e m a #

Functor m => Functor (ValidationT e m) Source # 
Instance details

Defined in Data.Validator

Methods

fmap :: (a -> b) -> ValidationT e m a -> ValidationT e m b #

(<$) :: a -> ValidationT e m b -> ValidationT e m a #

Monad m => Applicative (ValidationT e m) Source # 
Instance details

Defined in Data.Validator

Methods

pure :: a -> ValidationT e m a #

(<*>) :: ValidationT e m (a -> b) -> ValidationT e m a -> ValidationT e m b #

liftA2 :: (a -> b -> c) -> ValidationT e m a -> ValidationT e m b -> ValidationT e m c #

(*>) :: ValidationT e m a -> ValidationT e m b -> ValidationT e m b #

(<*) :: ValidationT e m a -> ValidationT e m b -> ValidationT e m a #

(Monad m, Monoid e) => Alternative (ValidationT e m) Source # 
Instance details

Defined in Data.Validator

Methods

empty :: ValidationT e m a #

(<|>) :: ValidationT e m a -> ValidationT e m a -> ValidationT e m a #

some :: ValidationT e m a -> ValidationT e m [a] #

many :: ValidationT e m a -> ValidationT e m [a] #

(Monad m, Monoid e) => MonadPlus (ValidationT e m) Source # 
Instance details

Defined in Data.Validator

Methods

mzero :: ValidationT e m a #

mplus :: ValidationT e m a -> ValidationT e m a -> ValidationT e m a #

type ValidationRule e a = ValidationRuleT e Identity a Source #

A validation rule. Combine using (>=>) or (<=<)

type ValidationRuleT e m a = TransValidationRuleT e m a a Source #

A validation rule. Combine using (>=>) or (<=<)

type TransValidationRule e a b = TransValidationRuleT e Identity a b Source #

A transforming validation rule. Combine using (>=>) or (<=<)

type TransValidationRuleT e m a b = a -> ValidationT e m b Source #

A transforming validation rule. Combine using (>=>) or (<=<)

runValidator :: TransValidationRule e a b -> a -> Either e b Source #

Run a validation on a type a

runValidatorT :: Monad m => TransValidationRuleT e m a b -> a -> m (Either e b) Source #

Run a validation on a type a

Combinators

(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #

Left-to-right composition of Kleisli arrows.

'(bs >=> cs) a' can be understood as the do expression

do b <- bs a
   cs b

(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c infixr 1 #

Right-to-left composition of Kleisli arrows. (>=>), with the arguments flipped.

Note how this operator resembles function composition (.):

(.)   ::            (b ->   c) -> (a ->   b) -> a ->   c
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c

Checks

minLength :: (Monad m, HasLength a) => Int64 -> e -> ValidationRuleT e m a Source #

Check that the value is at least N elements long

maxLength :: (Monad m, HasLength a) => Int64 -> e -> ValidationRuleT e m a Source #

Check that the value is at maxium N elements long

lengthBetween :: (Monad m, HasLength a) => Int64 -> Int64 -> e -> ValidationRuleT e m a Source #

Check that the value's length is between N and M

notEmpty :: (Monad m, HasLength a) => e -> ValidationRuleT e m a Source #

Specialized minLength with N = 1

largerThan :: (Monad m, Ord a) => a -> e -> ValidationRuleT e m a Source #

Check that a value is larger than N

smallerThan :: (Monad m, Ord a) => a -> e -> ValidationRuleT e m a Source #

Check that a value is smaller than N

valueBetween :: (Monad m, Ord a) => a -> a -> e -> ValidationRuleT e m a Source #

Check that a value is between M and N

matchesRegex :: (ConvertibleStrings SBS a, ConvertibleStrings a SBS, Monad m) => Regex -> e -> ValidationRuleT e m a Source #

Checks that a value matches a regular expression

conformsPred :: Monad m => (a -> Bool) -> e -> ValidationRuleT e m a Source #

Check that a value conforms a predicate

conformsPredM :: Monad m => (a -> m Bool) -> e -> ValidationRuleT e m a Source #

Check that a value conforms a predicate

Transforming checks

requiredValue :: Monad m => e -> TransValidationRuleT e m (Maybe a) a Source #

Check that an optional value is actually set to 'Just a'

nonEmptyList :: Monad m => e -> TransValidationRuleT e m [a] (NonEmpty a) Source #

Check that a list is not empty

conformsPredTrans :: Monad m => (a -> Maybe b) -> e -> TransValidationRuleT e m a b Source #

Do some check returning Nothing if the value is invalid and 'Just a' otherwise.

conformsPredTransM :: Monad m => (a -> m (Maybe b)) -> e -> TransValidationRuleT e m a b Source #

Do some check returning Nothing if the value is invalid and 'Just a' otherwise.

Helper classes and types

class HasLength a where Source #

All types that have a length, eg. String, '[a]', 'Vector a', etc.

Methods

getLength :: a -> Int64 Source #

Instances

Instances details
HasLength ByteString Source # 
Instance details

Defined in Data.Validator

HasLength ByteString Source # 
Instance details

Defined in Data.Validator

HasLength Text Source # 
Instance details

Defined in Data.Validator

Methods

getLength :: Text -> Int64 Source #

HasLength Text Source # 
Instance details

Defined in Data.Validator

Methods

getLength :: Text -> Int64 Source #

HasLength [a] Source # 
Instance details

Defined in Data.Validator

Methods

getLength :: [a] -> Int64 Source #

class ConvertibleStrings a b where #

Methods

convertString :: a -> b #

Instances

Instances details
ConvertibleStrings String String 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings String StrictByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings String LazyByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings String StrictText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings String LazyText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictByteString String 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictByteString StrictByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictByteString LazyByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictByteString StrictText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictByteString LazyText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyByteString String 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyByteString StrictByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyByteString LazyByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyByteString StrictText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyByteString LazyText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictText String 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictText StrictByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictText LazyByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictText StrictText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings StrictText LazyText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyText String 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyText StrictByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyText LazyByteString 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyText StrictText 
Instance details

Defined in Data.String.Conversions

ConvertibleStrings LazyText LazyText 
Instance details

Defined in Data.String.Conversions

data Int64 #

64-bit signed integer type

Instances

Instances details
Bounded Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Enum Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Eq Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Methods

(==) :: Int64 -> Int64 -> Bool #

(/=) :: Int64 -> Int64 -> Bool #

Integral Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Num Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Ord Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Methods

compare :: Int64 -> Int64 -> Ordering #

(<) :: Int64 -> Int64 -> Bool #

(<=) :: Int64 -> Int64 -> Bool #

(>) :: Int64 -> Int64 -> Bool #

(>=) :: Int64 -> Int64 -> Bool #

max :: Int64 -> Int64 -> Int64 #

min :: Int64 -> Int64 -> Int64 #

Read Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Real Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Methods

toRational :: Int64 -> Rational #

Show Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Methods

showsPrec :: Int -> Int64 -> ShowS #

show :: Int64 -> String #

showList :: [Int64] -> ShowS #

Ix Int64

Since: base-2.1

Instance details

Defined in GHC.Int

Bits Int64

Since: base-2.1

Instance details

Defined in GHC.Int

FiniteBits Int64

Since: base-4.6.0.0

Instance details

Defined in GHC.Int

Regular expression helpers

re :: QuasiQuoter #

A QuasiQuoter for regular expressions that does a compile time check.

mkRegexQQ :: [PCREOption] -> QuasiQuoter #

Returns a QuasiQuoter like re, but with given PCRE options.

data Regex #

An abstract pointer to a compiled PCRE Regex structure The structure allocated by the PCRE library will be deallocated automatically by the Haskell storage manager.

Instances

Instances details
Eq Regex 
Instance details

Defined in Text.Regex.PCRE.Light.Base

Methods

(==) :: Regex -> Regex -> Bool #

(/=) :: Regex -> Regex -> Bool #

Ord Regex 
Instance details

Defined in Text.Regex.PCRE.Light.Base

Methods

compare :: Regex -> Regex -> Ordering #

(<) :: Regex -> Regex -> Bool #

(<=) :: Regex -> Regex -> Bool #

(>) :: Regex -> Regex -> Bool #

(>=) :: Regex -> Regex -> Bool #

max :: Regex -> Regex -> Regex #

min :: Regex -> Regex -> Regex #

Show Regex 
Instance details

Defined in Text.Regex.PCRE.Light.Base

Methods

showsPrec :: Int -> Regex -> ShowS #

show :: Regex -> String #

showList :: [Regex] -> ShowS #