Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Validator
Synopsis
- type ValidationM e = ValidationT e Identity
- data ValidationT e (m :: Type -> Type) a
- type ValidationRule e a = ValidationRuleT e Identity a
- type ValidationRuleT e (m :: Type -> Type) a = TransValidationRuleT e m a a
- type TransValidationRule e a b = TransValidationRuleT e Identity a b
- type TransValidationRuleT e (m :: Type -> Type) a b = a -> ValidationT e m b
- runValidator :: TransValidationRule e a b -> a -> Either e b
- runValidatorT :: Monad m => TransValidationRuleT e m a b -> a -> m (Either e b)
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- minLength :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => Int64 -> e -> ValidationRuleT e m a
- maxLength :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => Int64 -> e -> ValidationRuleT e m a
- lengthBetween :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => Int64 -> Int64 -> e -> ValidationRuleT e m a
- notEmpty :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => e -> ValidationRuleT e m a
- largerThan :: forall (m :: Type -> Type) a e. (Monad m, Ord a) => a -> e -> ValidationRuleT e m a
- smallerThan :: forall (m :: Type -> Type) a e. (Monad m, Ord a) => a -> e -> ValidationRuleT e m a
- valueBetween :: forall (m :: Type -> Type) a e. (Monad m, Ord a) => a -> a -> e -> ValidationRuleT e m a
- matchesRegex :: forall a (m :: Type -> Type) e. (ConvertibleStrings SBS a, ConvertibleStrings a SBS, Monad m) => Regex -> e -> ValidationRuleT e m a
- conformsPred :: forall (m :: Type -> Type) a e. Monad m => (a -> Bool) -> e -> ValidationRuleT e m a
- conformsPredM :: Monad m => (a -> m Bool) -> e -> ValidationRuleT e m a
- requiredValue :: forall (m :: Type -> Type) e a. Monad m => e -> TransValidationRuleT e m (Maybe a) a
- nonEmptyList :: forall (m :: Type -> Type) e a. Monad m => e -> TransValidationRuleT e m [a] (NonEmpty a)
- conformsPredTrans :: forall (m :: Type -> Type) a b e. Monad m => (a -> Maybe b) -> e -> TransValidationRuleT e m a b
- conformsPredTransM :: Monad m => (a -> m (Maybe b)) -> e -> TransValidationRuleT e m a b
- class HasLength a where
- class ConvertibleStrings a b where
- convertString :: a -> b
- data Int64
- re :: QuasiQuoter
- mkRegexQQ :: [PCREOption] -> QuasiQuoter
- data Regex
Core monad and runners
type ValidationM e = ValidationT e Identity Source #
The validation monad
data ValidationT e (m :: Type -> Type) a Source #
The validation monad transformer
Instances
type ValidationRule e a = ValidationRuleT e Identity a Source #
type ValidationRuleT e (m :: Type -> Type) a = TransValidationRuleT e m a a Source #
type TransValidationRule e a b = TransValidationRuleT e Identity a b Source #
type TransValidationRuleT e (m :: Type -> Type) a b = a -> ValidationT e m b Source #
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
' can be understood as the >=>
cs) ado
expression
do b <- bs a cs b
Checks
minLength :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => Int64 -> e -> ValidationRuleT e m a Source #
Check that the value is at least N elements long
maxLength :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => Int64 -> e -> ValidationRuleT e m a Source #
Check that the value is at maxium N elements long
lengthBetween :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => Int64 -> Int64 -> e -> ValidationRuleT e m a Source #
Check that the value's length is between N and M
notEmpty :: forall (m :: Type -> Type) a e. (Monad m, HasLength a) => e -> ValidationRuleT e m a Source #
Specialized minLength with N = 1
largerThan :: forall (m :: Type -> Type) a e. (Monad m, Ord a) => a -> e -> ValidationRuleT e m a Source #
Check that a value is larger than N
smallerThan :: forall (m :: Type -> Type) a e. (Monad m, Ord a) => a -> e -> ValidationRuleT e m a Source #
Check that a value is smaller than N
valueBetween :: forall (m :: Type -> Type) a e. (Monad m, Ord a) => a -> a -> e -> ValidationRuleT e m a Source #
Check that a value is between M and N
matchesRegex :: forall a (m :: Type -> Type) e. (ConvertibleStrings SBS a, ConvertibleStrings a SBS, Monad m) => Regex -> e -> ValidationRuleT e m a Source #
Checks that a value matches a regular expression
conformsPred :: forall (m :: Type -> Type) a e. 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 :: forall (m :: Type -> Type) e a. Monad m => e -> TransValidationRuleT e m (Maybe a) a Source #
Check that an optional value is actually set to 'Just a'
nonEmptyList :: forall (m :: Type -> Type) e a. Monad m => e -> TransValidationRuleT e m [a] (NonEmpty a) Source #
Check that a list is not empty
conformsPredTrans :: forall (m :: Type -> Type) a b e. 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.
Instances
HasLength ByteString Source # | |
Defined in Data.Validator Methods getLength :: ByteString -> Int64 Source # | |
HasLength ByteString Source # | |
Defined in Data.Validator Methods getLength :: ByteString -> Int64 Source # | |
HasLength Text Source # | |
HasLength Text Source # | |
HasLength [a] Source # | |
Defined in Data.Validator |
class ConvertibleStrings a b where #
Methods
convertString :: a -> b #
Instances
64-bit signed integer type
Instances
Data Int64 | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Int64 -> c Int64 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Int64 # dataTypeOf :: Int64 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Int64) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Int64) # gmapT :: (forall b. Data b => b -> b) -> Int64 -> Int64 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Int64 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Int64 -> r # gmapQ :: (forall d. Data d => d -> u) -> Int64 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Int64 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Int64 -> m Int64 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Int64 -> m Int64 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Int64 -> m Int64 # | |
Storable Int64 | Since: base-2.1 |
Bits Int64 | Since: base-2.1 |
Defined in GHC.Int Methods (.&.) :: Int64 -> Int64 -> Int64 # (.|.) :: Int64 -> Int64 -> Int64 # xor :: Int64 -> Int64 -> Int64 # complement :: Int64 -> Int64 # shift :: Int64 -> Int -> Int64 # rotate :: Int64 -> Int -> Int64 # setBit :: Int64 -> Int -> Int64 # clearBit :: Int64 -> Int -> Int64 # complementBit :: Int64 -> Int -> Int64 # testBit :: Int64 -> Int -> Bool # bitSizeMaybe :: Int64 -> Maybe Int # shiftL :: Int64 -> Int -> Int64 # unsafeShiftL :: Int64 -> Int -> Int64 # shiftR :: Int64 -> Int -> Int64 # unsafeShiftR :: Int64 -> Int -> Int64 # rotateL :: Int64 -> Int -> Int64 # | |
FiniteBits Int64 | Since: base-4.6.0.0 |
Defined in GHC.Int Methods finiteBitSize :: Int64 -> Int # countLeadingZeros :: Int64 -> Int # countTrailingZeros :: Int64 -> Int # | |
Bounded Int64 | Since: base-2.1 |
Enum Int64 | Since: base-2.1 |
Ix Int64 | Since: base-2.1 |
Num Int64 | Since: base-2.1 |
Read Int64 | Since: base-2.1 |
Integral Int64 | Since: base-2.1 |
Real Int64 | Since: base-2.1 |
Defined in GHC.Int Methods toRational :: Int64 -> Rational # | |
Show Int64 | Since: base-2.1 |
PrintfArg Int64 | Since: base-2.1 |
Defined in Text.Printf | |
NFData Int64 | |
Defined in Control.DeepSeq | |
Eq Int64 | Since: base-2.1 |
Ord Int64 | Since: base-2.1 |
Lift Int64 | |
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.