Module

Polyform.Validation

#V

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)

    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 our Category" which short circuits on the first valid result...

  • (Semigroup err, Semigroup a) => Semigroup (V err a)

    Defaul Semigroup instance appends valid and invalid parts of our V.

  • (Monoid e, Monoid a) => Monoid (V e a)

#isValid

isValid :: forall a e. V e a -> Boolean

#fromEither

fromEither :: forall a e. Monoid e => Either e a -> V e a

#toEither

toEither :: forall a e. V e a -> Either e a

#Validation

newtype Validation m e a b

Constructors

Instances

#runValidation

runValidation :: forall a b e m. Validation m e a b -> (a -> m (V e b))

#ask

ask :: forall a e m. Monad m => Monoid e => Validation m e a a

#hoistFn

hoistFn :: forall a e b m. Monad m => Monoid e => (a -> b) -> Validation m e a b

#hoistFnV

hoistFnV :: forall a e b m. Monad m => Monoid e => (a -> V e b) -> Validation m e a b

#hoistFnMV

hoistFnMV :: forall a e b m. Monad m => Monoid e => (a -> m (V e b)) -> Validation m e a b

#BifunctorValidation

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

Instances

#bimapValidation

bimapValidation :: forall a b b' e e' m. Monad m => (e -> e') -> (b -> b') -> Validation m e a b -> Validation m e' a b'

#lmapValidation

lmapValidation :: forall t167 t168 t169 t173 t174. Monad t174 => (t169 -> t168) -> Validation t174 t169 t173 t167 -> Validation t174 t168 t173 t167

#rmapValidation

rmapValidation :: forall t100 t101 t94 t95 t96. Monad t101 => (t95 -> t94) -> Validation t101 t96 t100 t95 -> Validation t101 t96 t100 t94

Modules