Module
Polyform.Validation
- Package
- purescript-polyform
- Repository
- paluh/purescript-polyform
#V Source
data V e a
Constructors
Instances
Functor (V e)
Bifunctor V
(Semigroup e) => Apply (V e)
(Eq e, Eq a) => Eq (V e a)
(Ord e, Ord a) => Ord (V e a)
(Show e, Show a) => Show (V e a)
(Monoid e) => Applicative (V e)
(Semigroup e) => Alt (V e)
(Semigroup err, Semigroup a) => Semigroup (V err a)
Defaul
Semigroup
instance appends valid and invalid parts of ourV
.(Monoid e, Monoid a) => Monoid (V e a)
#Validation Source
newtype Validation m e a b
Constructors
Validation (a -> m (V e b))
Instances
Newtype (Validation m e a b) _
(Functor m) => Functor (Validation m e a)
(Semigroup e, Monad m) => Apply (Validation m e a)
(Monoid e, Monad m) => Applicative (Validation m e a)
(Monoid e, Monad m) => Alt (Validation m e a)
(Semigroup (m (V e b))) => Semigroup (Validation m e a b)
(Applicative m, Monoid e, Monoid b, Semigroup (m (V e b))) => Monoid (Validation m e a b)
(Monad m, Semigroup e) => Semigroupoid (Validation m e)
(Monad m, Monoid e) => Category (Validation m e)
(Monad m, Monoid e) => Profunctor (Validation m e)
(Monad m, Monoid e) => Choice (Validation m e)
#runValidation Source
runValidation :: forall m e b a. Validation m e a b -> (a -> m (V e b))
#hoistFnV Source
hoistFnV :: forall m b e a. Monad m => Monoid e => (a -> V e b) -> Validation m e a b
#hoistFnMV Source
hoistFnMV :: forall m b e a. Monad m => Monoid e => (a -> m (V e b)) -> Validation m e a b
#BifunctorValidation Source
newtype BifunctorValidation m a e b
Provides access to validation result
so you can bimap
over e
and b
type in resulting V e b
.
Constructors
BifunctorValidation (Validation m e a b)
Instances
Newtype (BifunctorValidation m a e b) _
(Monad m) => Bifunctor (BifunctorValidation m a)
#bimapValidation Source
bimapValidation :: forall m e' e b' b a. Monad m => (e -> e') -> (b -> b') -> Validation m e a b -> Validation m e' a b'
#lmapValidation Source
lmapValidation :: forall t174 t173 t169 t168 t167. Monad t174 => (t169 -> t168) -> Validation t174 t169 t173 t167 -> Validation t174 t168 t173 t167
#rmapValidation Source
rmapValidation :: forall t96 t95 t94 t101 t100. Monad t101 => (t95 -> t94) -> Validation t101 t96 t100 t95 -> Validation t101 t96 t100 t94
- Modules
- Polyform.
Field - Polyform.
Field. Generic - Polyform.
Field. Generic. Option - Polyform.
Field. Html5 - Polyform.
Field. Validation. Combinators - Polyform.
Form. Component - Polyform.
Input. Foreign - Polyform.
Input. Http - Polyform.
Input. Interpret - Polyform.
Input. Interpret. Http - Polyform.
Input. Interpret. Record - Polyform.
Input. Interpret. Validation - Polyform.
Validation - Polyform.
Validation. Par
This instance uses first valid value and accumulates only in case of invalid results.
pure (Valid e1 a1) <|> pure (Invalid e2) = Valid (e1 <> e2) a1 pure (Valid e1 a1) <|> pure (Valid e2 a2) = Valid (e1 <> e2) a1 pure (Invalid e1) <|> pure (Invalid e2) = Invalid (e1 <> e2)
If you need "dual" strategy just use apply which "prefers" invalid results:
pure (Valid e1 a1) > pure (Invalid e2) = Invalid (e1 <> e2) pure (Invalid e1) > pure (Valid e2 a2) = Invalid (e1 <> e2) pure (Valid e1 a1) *> pure (Valid e2 a2) = Valid (e1 <> e2) a2
If you find any not accumulative instance useful please add a newtype wrapper and provide a PR with related tests.
And maybe there is also a place for "
Alt
somewhat dual to ourCategory
" which short circuits on the first valid result...