validity 0.2.0.0 → 0.3.0.0
raw patch · 2 files changed
+19/−8 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- src/Data/Validity.hs +18/−7
- validity.cabal +1/−1
src/Data/Validity.hs view
@@ -36,17 +36,28 @@ class Validity a where isValid :: a -> Bool --- | Any @Foldable@ of things that can be checked for validity can be checked--- for validity+-- | Any tuple of things is valid if both of its elements are valid+instance (Validity a, Validity b) => Validity (a, b) where+ isValid (a, b) = isValid a && isValid b++-- | Any tuple of things is valid if all three of its elements are valid+instance (Validity a, Validity b, Validity c) => Validity (a, b, c) where+ isValid (a, b, c) = isValid a && isValid b && isValid c++-- | A list of things is valid if all of the things are valid. ----- This includes lists, which means that the empty list is considered valid.+-- This means that the empty list is considered valid. -- If the empty list should not be considered valid as part of your custom data -- type, make sure to write a custom @Validity instance@------ This also includes @Maybe@:+instance Validity a => Validity [a] where+ isValid = all isValid++-- | A Maybe thing is valid if the thing inside is valid or it's nothing -- It makes sense to assume that 'Nothing' is valid. -- If Nothing wasn't valid, you wouldn't have used a Maybe -- in the datastructure.-instance (Validity a, Foldable t) => Validity (t a) where- isValid = all isValid+instance Validity a => Validity (Maybe a) where+ isValid Nothing = True+ isValid (Just a) = isValid a+
validity.cabal view
@@ -1,5 +1,5 @@ name: validity-version: 0.2.0.0+version: 0.3.0.0 synopsis: Validity typeclass description: Please see README.md homepage: https://github.com/NorfairKing/validity#readme