contracheck-applicative-0.2.0: Validation types/typeclass based on the contravariance.
Safe HaskellNone
LanguageHaskell2010

Control.Validation.Patch

Synopsis

Patch

newtype Patch a Source #

Constructors

Patch 

Fields

Instances

Instances details
Semigroup (Patch a) Source # 
Instance details

Defined in Control.Validation.Patch

Methods

(<>) :: Patch a -> Patch a -> Patch a #

sconcat :: NonEmpty (Patch a) -> Patch a #

stimes :: Integral b => b -> Patch a -> Patch a #

Monoid (Patch a) Source # 
Instance details

Defined in Control.Validation.Patch

Methods

mempty :: Patch a #

mappend :: Patch a -> Patch a -> Patch a #

mconcat :: [Patch a] -> Patch a #

patch :: (a -> a) -> Patch a Source #

Helper functions to construct Patches.

CheckPatch

The CheckPatch type is similar to Check but accumulates a function that "fixes" your data i.e. corrects it where it fails a Check. To do so, some of the combinators take Lenses instead of normal functions (see below). To lift a normal Check to a CheckPatch use checkPatch. to validate and fix your data with a CheckPatch use validateByPatch.

newtype CheckPatch e m a Source #

A Check that also corrects the errors in your data.

Constructors

CheckPatch (Check (e, Patch a) m a) 

Instances

Instances details
Applicative m => Semigroup (CheckPatch e m a) Source # 
Instance details

Defined in Control.Validation.Patch

Methods

(<>) :: CheckPatch e m a -> CheckPatch e m a -> CheckPatch e m a #

sconcat :: NonEmpty (CheckPatch e m a) -> CheckPatch e m a #

stimes :: Integral b => b -> CheckPatch e m a -> CheckPatch e m a #

Applicative m => Monoid (CheckPatch e m a) Source # 
Instance details

Defined in Control.Validation.Patch

Methods

mempty :: CheckPatch e m a #

mappend :: CheckPatch e m a -> CheckPatch e m a -> CheckPatch e m a #

mconcat :: [CheckPatch e m a] -> CheckPatch e m a #

liftPatch :: Functor m => (a -> Maybe a) -> Check e m a -> CheckPatch e m a Source #

Lift a Check to a CheckPatch with a patch

liftNoPatch :: Functor m => Check e m a -> CheckPatch e m a Source #

Lift a Check to a CheckPatch without a patch.

demotePatch :: Functor m => CheckPatch e m a -> Check e m a Source #

Demote a CheckPatch into a Check by throwing the patch away

mapErrorPatch :: Functor m => (e -> e') -> CheckPatch e m a -> CheckPatch e' m a Source #

overCheck :: (Check (e, Patch a) m a -> Check (e', Patch a') m' a') -> CheckPatch e m a -> CheckPatch e' m' a' Source #

newtype Patched a Source #

Constructors

Patched 

Fields

Instances

Instances details
Eq a => Eq (Patched a) Source # 
Instance details

Defined in Control.Validation.Patch

Methods

(==) :: Patched a -> Patched a -> Bool #

(/=) :: Patched a -> Patched a -> Bool #

Read a => Read (Patched a) Source # 
Instance details

Defined in Control.Validation.Patch

Show a => Show (Patched a) Source # 
Instance details

Defined in Control.Validation.Patch

Methods

showsPrec :: Int -> Patched a -> ShowS #

show :: Patched a -> String #

showList :: [Patched a] -> ShowS #

Generic a => Generic (Patched a) Source # 
Instance details

Defined in Control.Validation.Patch

Associated Types

type Code (Patched a) :: [[Type]] #

Methods

from :: Patched a -> Rep (Patched a) #

to :: Rep (Patched a) -> Patched a #

type Code (Patched a) Source # 
Instance details

Defined in Control.Validation.Patch

type Code (Patched a) = Code a

validateByPatch :: forall m e a. Functor m => CheckPatch e m a -> Unvalidated a -> m (Either (Seq e, Maybe (Patched a)) a) Source #

validateByPatch takes a CheckPatch and the unvalidated data and either returns the validated data or returns the errors in the data and ─ if a fix exists ─ the fixed data.

validateByPatch' :: CheckPatch' e a -> Unvalidated a -> Either (Seq e, Maybe (Patched a)) a Source #

validateByPatch with trivial context

Lens-variants of functions on Checks

The functions contramapL, chooseL and divideL are the counterparts that take a lens instead of a simple function so they can patch their data if needed.

contramapL :: Functor m => Lens' s a -> CheckPatch e m a -> CheckPatch e m s Source #

chooseL :: forall m a b c e. Functor m => Lens' a (Either b c) -> CheckPatch e m b -> CheckPatch e m c -> CheckPatch e m a Source #

divideL :: forall m a b c e. Applicative m => Lens' a (b, c) -> CheckPatch e m b -> CheckPatch e m c -> CheckPatch e m a Source #

Construction of CheckPatches

Patch-variants for construction-functions. Functions have a Patch appended (e.g. test_ ~> testPatch_) and operators have an additional exclamation mark after the question mark (e.g. ?>> ~> ?!>>) For documentation see Control.Valiation.Check.

checkingPatch :: Functor m => (a -> (Maybe a, m (CheckResult e))) -> CheckPatch e m a Source #

testPatch :: Functor m => (a -> m Bool) -> (a -> e) -> Patch a -> CheckPatch e m a infix 7 Source #

testPatch' :: Applicative m => (a -> Bool) -> (a -> e) -> Patch a -> CheckPatch e m a infix 7 Source #

testPatch_ :: Monad m => (a -> m Bool) -> e -> Patch a -> CheckPatch e m a infix 7 Source #

testPatch'_ :: Applicative m => (a -> Bool) -> e -> Patch a -> CheckPatch e m a infix 7 Source #

testPatchDefault :: Applicative m => (a -> m Bool) -> (a -> e) -> a -> CheckPatch e m a Source #

Patch by replacing with default value

type MultiCheckPatch e m a = NP (NP (CheckPatch e m)) (Code a) Source #

A Multi-CheckPatch for an ADT, one 'CheckPatch e m' for each field of each constructor, organized in Lists (see examples for construction)

constructorCheckPatch Source #

Arguments

:: forall a m e xs. (Applicative m, Generic a) 
=> (NP (CheckPatch e m) xs -> NS (NP (CheckPatch e m)) (Code a))

The function deciding the constructor, Z for the zeroth, 'S . Z' for the first, etc.

-> NP (CheckPatch e m) xs

Product of CheckPatches, one for each constructor

-> CheckPatch e m a 

joinMultiCheckPatch :: forall a m e. (Applicative m, Generic a) => MultiCheckPatch e m a -> CheckPatch e m a Source #

Combine all CheckPatchs from a MultiCheckPatch into a single CheckPatch for the datatype a (given it has a Generic instance).

mapErrorsWithInfoPatch :: forall e e' a m. (Functor m, HasDatatypeInfo a) => Proxy a -> (DatatypeName -> ConstructorName -> FieldName -> e -> e') -> MultiCheckPatch e m a -> MultiCheckPatch e' m a Source #

Change the error of a MultiCheckPatch using the information about the datatype.

Reexports

data NP (a :: k -> Type) (b :: [k]) where #

An n-ary product.

The product is parameterized by a type constructor f and indexed by a type-level list xs. The length of the list determines the number of elements in the product, and if the i-th element of the list is of type x, then the i-th element of the product is of type f x.

The constructor names are chosen to resemble the names of the list constructors.

Two common instantiations of f are the identity functor I and the constant functor K. For I, the product becomes a heterogeneous list, where the type-level list describes the types of its components. For K a, the product becomes a homogeneous list, where the contents of the type-level list are ignored, but its length still specifies the number of elements.

In the context of the SOP approach to generic programming, an n-ary product describes the structure of the arguments of a single data constructor.

Examples:

I 'x'    :* I True  :* Nil  ::  NP I       '[ Char, Bool ]
K 0      :* K 1     :* Nil  ::  NP (K Int) '[ Char, Bool ]
Just 'x' :* Nothing :* Nil  ::  NP Maybe   '[ Char, Bool ]

Constructors

Nil :: forall k (a :: k -> Type). NP a ('[] :: [k]) 
(:*) :: forall k (a :: k -> Type) (x :: k) (xs :: [k]). a x -> NP a xs -> NP a (x ': xs) infixr 5 

Instances

Instances details
HTrans (NP :: (k1 -> Type) -> [k1] -> Type) (NP :: (k2 -> Type) -> [k2] -> Type) 
Instance details

Defined in Data.SOP.NP

Methods

htrans :: forall c (xs :: l1) (ys :: l2) proxy f g. AllZipN (Prod NP) c xs ys => proxy c -> (forall (x :: k10) (y :: k20). c x y => f x -> g y) -> NP f xs -> NP g ys #

hcoerce :: forall (f :: k10 -> Type) (g :: k20 -> Type) (xs :: l1) (ys :: l2). AllZipN (Prod NP) (LiftedCoercible f g) xs ys => NP f xs -> NP g ys #

HSequence (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

Methods

hsequence' :: forall (xs :: l) f (g :: k0 -> Type). (SListIN NP xs, Applicative f) => NP (f :.: g) xs -> f (NP g xs) #

hctraverse' :: forall c (xs :: l) g proxy f f'. (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g (f' a)) -> NP f xs -> g (NP f' xs) #

htraverse' :: forall (xs :: l) g f f'. (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g (f' a)) -> NP f xs -> g (NP f' xs) #

HTraverse_ (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

Methods

hctraverse_ :: forall c (xs :: l) g proxy f. (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g ()) -> NP f xs -> g () #

htraverse_ :: forall (xs :: l) g f. (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g ()) -> NP f xs -> g () #

HCollapse (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

Methods

hcollapse :: forall (xs :: l) a. SListIN NP xs => NP (K a) xs -> CollapseTo NP a #

HAp (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

Methods

hap :: forall (f :: k0 -> Type) (g :: k0 -> Type) (xs :: l). Prod NP (f -.-> g) xs -> NP f xs -> NP g xs #

HPure (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

Methods

hpure :: forall (xs :: l) f. SListIN NP xs => (forall (a :: k0). f a) -> NP f xs #

hcpure :: forall c (xs :: l) proxy f. AllN NP c xs => proxy c -> (forall (a :: k0). c a => f a) -> NP f xs #

All (Compose Eq f) xs => Eq (NP f xs) 
Instance details

Defined in Data.SOP.NP

Methods

(==) :: NP f xs -> NP f xs -> Bool #

(/=) :: NP f xs -> NP f xs -> Bool #

(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NP f xs) 
Instance details

Defined in Data.SOP.NP

Methods

compare :: NP f xs -> NP f xs -> Ordering #

(<) :: NP f xs -> NP f xs -> Bool #

(<=) :: NP f xs -> NP f xs -> Bool #

(>) :: NP f xs -> NP f xs -> Bool #

(>=) :: NP f xs -> NP f xs -> Bool #

max :: NP f xs -> NP f xs -> NP f xs #

min :: NP f xs -> NP f xs -> NP f xs #

All (Compose Show f) xs => Show (NP f xs) 
Instance details

Defined in Data.SOP.NP

Methods

showsPrec :: Int -> NP f xs -> ShowS #

show :: NP f xs -> String #

showList :: [NP f xs] -> ShowS #

All (Compose Semigroup f) xs => Semigroup (NP f xs)

Since: sop-core-0.4.0.0

Instance details

Defined in Data.SOP.NP

Methods

(<>) :: NP f xs -> NP f xs -> NP f xs #

sconcat :: NonEmpty (NP f xs) -> NP f xs #

stimes :: Integral b => b -> NP f xs -> NP f xs #

(All (Compose Monoid f) xs, All (Compose Semigroup f) xs) => Monoid (NP f xs)

Since: sop-core-0.4.0.0

Instance details

Defined in Data.SOP.NP

Methods

mempty :: NP f xs #

mappend :: NP f xs -> NP f xs -> NP f xs #

mconcat :: [NP f xs] -> NP f xs #

All (Compose NFData f) xs => NFData (NP f xs)

Since: sop-core-0.2.5.0

Instance details

Defined in Data.SOP.NP

Methods

rnf :: NP f xs -> () #

type AllZipN (NP :: (k -> Type) -> [k] -> Type) (c :: a -> b -> Constraint) 
Instance details

Defined in Data.SOP.NP

type AllZipN (NP :: (k -> Type) -> [k] -> Type) (c :: a -> b -> Constraint) = AllZip c
type Same (NP :: (k1 -> Type) -> [k1] -> Type) 
Instance details

Defined in Data.SOP.NP

type Same (NP :: (k1 -> Type) -> [k1] -> Type) = NP :: (k2 -> Type) -> [k2] -> Type
type SListIN (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

type SListIN (NP :: (k -> Type) -> [k] -> Type) = SListI :: [k] -> Constraint
type UnProd (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NS

type UnProd (NP :: (k -> Type) -> [k] -> Type) = NS :: (k -> Type) -> [k] -> Type
type Prod (NP :: (k -> Type) -> [k] -> Type) 
Instance details

Defined in Data.SOP.NP

type Prod (NP :: (k -> Type) -> [k] -> Type) = NP :: (k -> Type) -> [k] -> Type
type AllN (NP :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) 
Instance details

Defined in Data.SOP.NP

type AllN (NP :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) = All c
type CollapseTo (NP :: (k -> Type) -> [k] -> Type) a 
Instance details

Defined in Data.SOP.NP

type CollapseTo (NP :: (k -> Type) -> [k] -> Type) a = [a]

type DatatypeName = String #

The name of a datatype.

type ConstructorName = String #

The name of a data constructor.

type FieldName = String #

The name of a field / record selector.