Safe Haskell  None 

Language  Haskell2010 
Synopsis
 newtype Patch a = Patch {}
 patch :: (a > a) > Patch a
 noPatch :: Patch a
 newtype CheckPatch e m a = CheckPatch (Check (e, Patch a) m a)
 type CheckPatch' e = CheckPatch e Identity
 runCheckPatch :: CheckPatch e m a > Unvalidated a > m (CheckResult (e, Patch a))
 runCheckPatch' :: CheckPatch' e a > Unvalidated a > CheckResult (e, Patch a)
 liftPatch :: Functor m => (a > Maybe a) > Check e m a > CheckPatch e m a
 liftNoPatch :: Functor m => Check e m a > CheckPatch e m a
 demotePatch :: Functor m => CheckPatch e m a > Check e m a
 mapErrorPatch :: Functor m => (e > e') > CheckPatch e m a > CheckPatch e' m a
 overCheck :: (Check (e, Patch a) m a > Check (e', Patch a') m' a') > CheckPatch e m a > CheckPatch e' m' a'
 newtype Patched a = Patched {
 getPatched :: a
 validateByPatch :: forall m e a. Functor m => CheckPatch e m a > Unvalidated a > m (Either (Seq e, Maybe (Patched a)) a)
 validateByPatch' :: CheckPatch' e a > Unvalidated a > Either (Seq e, Maybe (Patched a)) a
 contramapL :: Functor m => Lens' s a > CheckPatch e m a > CheckPatch e m s
 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
 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
 checkingPatch :: Functor m => (a > (Maybe a, m (CheckResult e))) > CheckPatch e m a
 checkingPatch' :: (a > (Maybe a, CheckResult e)) > CheckPatch' e a
 testPatch :: Functor m => (a > m Bool) > (a > e) > Patch a > CheckPatch e m a
 testPatch' :: Applicative m => (a > Bool) > (a > e) > Patch a > CheckPatch e m a
 testPatch_ :: Monad m => (a > m Bool) > e > Patch a > CheckPatch e m a
 testPatch'_ :: Applicative m => (a > Bool) > e > Patch a > CheckPatch e m a
 testPatchDefault :: Applicative m => (a > m Bool) > (a > e) > a > CheckPatch e m a
 type MultiCheckPatch e m a = NP (NP (CheckPatch e m)) (Code a)
 constructorCheckPatch :: forall a m e xs. (Applicative m, Generic a) => (NP (CheckPatch e m) xs > NS (NP (CheckPatch e m)) (Code a)) > NP (CheckPatch e m) xs > CheckPatch e m a
 joinMultiCheckPatch :: forall a m e. (Applicative m, Generic a) => MultiCheckPatch e m a > CheckPatch e m a
 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
 data NP (a :: k > Type) (b :: [k]) where
 type DatatypeName = String
 type ConstructorName = String
 type FieldName = String
Patch
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 Lens
es 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.
CheckPatch (Check (e, Patch a) m a) 
Instances
Applicative m => Semigroup (CheckPatch e m a) Source #  
Defined in Control.Validation.Patch (<>) :: 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 #  
Defined in Control.Validation.Patch 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 # 
type CheckPatch' e = CheckPatch e Identity Source #
runCheckPatch :: CheckPatch e m a > Unvalidated a > m (CheckResult (e, Patch a)) Source #
runCheckPatch' :: CheckPatch' e a > Unvalidated a > CheckResult (e, Patch a) Source #
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 #
Patched  

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
Lensvariants of functions on
Check
s
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
CheckPatch
es
Patchvariants for constructionfunctions. 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 #
checkingPatch' :: (a > (Maybe a, CheckResult e)) > CheckPatch' e a 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 MultiCheckPatch
for an ADT, one 'CheckPatch e m' for each field of each constructor, organized in Lists (see examples for construction)
constructorCheckPatch Source #
:: 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, 
> NP (CheckPatch e m) xs  Product of 
> CheckPatch e m a 
joinMultiCheckPatch :: forall a m e. (Applicative m, Generic a) => MultiCheckPatch e m a > CheckPatch e m a Source #
Combine all CheckPatch
s 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 nary product.
The product is parameterized by a type constructor f
and
indexed by a typelevel 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 typelevel list describes the
types of its components. For
, the product becomes a
homogeneous list, where the contents of the typelevel list are
ignored, but its length still specifies the number of elements.K
a
In the context of the SOP approach to generic programming, an nary 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 ]
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
HTrans (NP :: (k1 > Type) > [k1] > Type) (NP :: (k2 > Type) > [k2] > Type)  
Defined in Data.SOP.NP 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)  
Defined in Data.SOP.NP 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)  
Defined in Data.SOP.NP 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)  
Defined in Data.SOP.NP  
HAp (NP :: (k > Type) > [k] > Type)  
HPure (NP :: (k > Type) > [k] > Type)  
All (Compose Eq f) xs => Eq (NP f xs)  
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NP f xs)  
All (Compose Show f) xs => Show (NP f xs)  
All (Compose Semigroup f) xs => Semigroup (NP f xs)  Since: sopcore0.4.0.0 
(All (Compose Monoid f) xs, All (Compose Semigroup f) xs) => Monoid (NP f xs)  Since: sopcore0.4.0.0 
All (Compose NFData f) xs => NFData (NP f xs)  Since: sopcore0.2.5.0 
Defined in Data.SOP.NP  
type AllZipN (NP :: (k > Type) > [k] > Type) (c :: a > b > Constraint)  
Defined in Data.SOP.NP  
type Same (NP :: (k1 > Type) > [k1] > Type)  
type SListIN (NP :: (k > Type) > [k] > Type)  
Defined in Data.SOP.NP  
type UnProd (NP :: (k > Type) > [k] > Type)  
type Prod (NP :: (k > Type) > [k] > Type)  
type AllN (NP :: (k > Type) > [k] > Type) (c :: k > Constraint)  
Defined in Data.SOP.NP  
type CollapseTo (NP :: (k > Type) > [k] > Type) a  
Defined in Data.SOP.NP 
type DatatypeName = String #
The name of a datatype.
type ConstructorName = String #
The name of a data constructor.