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)

    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 Source

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

#fromEither Source

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

#toEither Source

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

#Validation Source

newtype Validation m e a b

Constructors

Instances

#runValidation Source

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

#ask Source

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

#hoistFn Source

hoistFn :: forall m b e a. Monad m => Monoid e => (a -> b) -> Validation m e a 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

Instances

#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