validation 1.1.1 → 1.1.2
raw patch · 3 files changed
+37/−67 lines, 3 filesdep −ghc-primdep ~basedep ~bifunctorsdep ~deepseq
Dependencies removed: ghc-prim
Dependency ranges changed: base, bifunctors, deepseq, lens, semigroups
Files
- changelog +5/−0
- src/Data/Validation.hs +16/−49
- validation.cabal +16/−18
changelog view
@@ -1,3 +1,8 @@+1.1.2++* Drop support for GHC-7.8.*, GHC-7.6.*, GHC-7.4.*, and GHC-7.2.*+* Adjust lower bounds of most dependencies to be inline with the lowest supported GHC version of 7.10.3+ 1.1.1 * Add `Data.Bifunctor.Swap.Swap` instance from `swap`
src/Data/Validation.hs view
@@ -1,12 +1,10 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TypeFamilies #-} -#if __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE DeriveGeneric #-}-#endif- -- | A data type similar to @Data.Either@ that accumulates failures. module Data.Validation (@@ -44,11 +42,13 @@ import Control.DeepSeq (NFData (rnf)) import Control.Lens (over, under) import Control.Lens.Getter((^.))-import Control.Lens.Iso(Iso, iso, from)+import Control.Lens.Iso(Iso, iso, from #if !MIN_VERSION_lens(4,20,0)-import Control.Lens.Iso(Swapped(..))+ , Swapped(..))+#else+ ) #endif-import Control.Lens.Prism(Prism, prism)+import Control.Lens.Prism(Prism, _Left, _Right) import Control.Lens.Review(( # )) import Data.Bifoldable(Bifoldable(bifoldr)) import Data.Bifunctor(Bifunctor(bimap))@@ -68,13 +68,11 @@ import Data.Semigroup(Semigroup((<>))) import Data.Traversable(Traversable(traverse)) import Data.Typeable(Typeable)-#if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic)-#endif import Prelude(Show, Maybe(..)) --- | An @Validation@ is either a value of the type @err@ or @a@, similar to 'Either'. However,+-- | A @Validation@ is either a value of the type @err@ or @a@, similar to 'Either'. However, -- the 'Applicative' instance for @Validation@ /accumulates/ errors using a 'Semigroup' on @err@. -- In contrast, the @Applicative@ for @Either@ returns only the first error. --@@ -87,12 +85,7 @@ data Validation err a = Failure err | Success a- deriving (- Eq, Ord, Show, Data, Typeable-#if __GLASGOW_HASKELL__ >= 702- , Generic-#endif- )+ deriving (Data, Eq, Generic, Ord, Show, Typeable) instance Functor (Validation err) where fmap _ (Failure e) =@@ -237,7 +230,7 @@ -- | 'validation' is the catamorphism for @Validation@. validation :: (e -> c) -> (a -> c) -> Validation e a -> c-validation ec ac v = case v of+validation ec ac = \case Failure e -> ec e Success a -> ac a @@ -284,7 +277,7 @@ -- @ ensure :: Validate v => e -> (a -> Maybe b) -> v e a -> v e b ensure e p =- over _Validation $ \v -> case v of+ over _Validation $ \case Failure x -> Failure x Success a -> validate e p a @@ -295,9 +288,9 @@ -- -- @(Either e a -> Either e' a') -> Validation e a -> Validation e' a'@ validationed :: Validate v => (v e a -> v e' a') -> Validation e a -> Validation e' a'-validationed f = under _Validation f+validationed = under _Validation --- | @bindValidation@ binds through an Validation, which is useful for+-- | @bindValidation@ binds through a Validation, which is useful for -- composing Validations sequentially. Note that despite having a bind -- function of the correct type, Validation is not a monad. -- The reason is, this bind does not accumulate errors, so it does not@@ -318,29 +311,13 @@ _Either :: Iso (f e a) (f g b) (Either e a) (Either g b)- _Either =- iso- (\x -> case x ^. _Validation of- Failure e -> Left e- Success a -> Right a)- (\x -> _Validation # case x of- Left e -> Failure e- Right a -> Success a)+ _Either = _Validation . iso toEither fromEither {-# INLINE _Either #-} instance Validate Validation where _Validation = id {-# INLINE _Validation #-}- _Either =- iso- (\x -> case x of- Failure e -> Left e- Success a -> Right a)- (\x -> case x of- Left e -> Failure e- Right a -> Success a)- {-# INLINE _Either #-} instance Validate Either where _Validation =@@ -356,24 +333,14 @@ _Failure :: Validate f => Prism (f e1 a) (f e2 a) e1 e2-_Failure =- prism- (\x -> _Either # Left x)- (\x -> case x ^. _Either of- Left e -> Right e- Right a -> Left (_Either # Right a))+_Failure = _Either . _Left {-# INLINE _Failure #-} -- | This prism generalises 'Control.Lens.Prism._Right'. It targets the success case of either 'Either' or 'Validation'. _Success :: Validate f => Prism (f e a) (f e b) a b-_Success =- prism- (\x -> _Either # Right x)- (\x -> case x ^. _Either of- Left e -> Left (_Either # Left e)- Right a -> Right a)+_Success = _Either . _Right {-# INLINE _Success #-} -- | 'revalidate' converts between any two instances of 'Validate'.
validation.cabal view
@@ -1,5 +1,5 @@ name: validation-version: 1.1.1+version: 1.1.2 license: BSD3 license-file: LICENCE author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>@@ -35,7 +35,7 @@ cabal-version: >= 1.10 build-type: Simple extra-source-files: changelog-tested-with: GHC==8.6.4, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2+tested-with: GHC==9.0.1, GHC==8.10.4, GHC==8.8.4, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3 source-repository head type: git@@ -46,15 +46,13 @@ Haskell2010 build-depends:- base >= 4.5 && < 5- , assoc >= 1 && < 1.1- , deepseq >= 1.2 && < 1.5- , semigroups >= 0.8 && < 1- , semigroupoids >= 5 && < 6- , bifunctors >= 5.1 && < 6- , lens >= 4 && < 5.1- if impl(ghc>=7.2) && impl(ghc<7.5)- build-depends: ghc-prim == 0.2.0.0+ base >= 4.8 && < 5+ , assoc >= 1 && < 1.1+ , deepseq >= 1.4 && < 1.5+ , semigroups >= 0.16 && < 1+ , semigroupoids >= 5 && < 6+ , bifunctors >= 5.5 && < 6+ , lens >= 4 && < 6 ghc-options: -Wall@@ -76,9 +74,9 @@ Haskell2010 build-depends:- base >= 3 && < 5- , hedgehog >= 0.5 && < 1.1- , semigroups >= 0.8 && < 1+ base >= 4.8 && < 5+ , hedgehog >= 0.5 && < 1.1+ , semigroups >= 0.16 && < 1 , validation ghc-options:@@ -99,10 +97,10 @@ Haskell2010 build-depends:- base >= 3 && < 5- , HUnit >= 1.5 && < 1.7- , lens- , semigroups >= 0.8 && < 1+ base >= 4.8 && < 5+ , HUnit >= 1.5 && < 1.7+ , lens >= 4 && < 5+ , semigroups >= 0.16 && < 1 , validation ghc-options: