git.iko.soy/typeable/validationt
on master help sign in
6 files changed+52−54
since splitsnapshots
unifiedsplit
.travis.yml+13−24 README.md+2−1 src/Control/Monad/Validation.hs+18−5 stack.yaml+1−1 test/Doc.hs+1−1 validationt.cabal+17−22
.travis.yml+13−24
@@ -12,38 +12,27 @@ cache:
1212
1313jobs:
1414 include:
15−
16− # Cabal
17− - ghc: 8.4.4
15+ - ghc: 8.10.2
16+ env: SNAPSHOT="nightly-2020-11-03"
17+ - ghc: 8.8.4
18+ env: SNAPSHOT="lts-16.20"
1819 - ghc: 8.6.5
19−
20− # Stack
21− - ghc: 8.6.5
22− env: STACK_YAML="$TRAVIS_BUILD_DIR/stack.yaml"
20+ env: SNAPSHOT="lts-14.22"
21+ - ghc: 8.4.4
22+ env: SNAPSHOT="lts-12.26"
2323
2424install:
2525 - |
26− if [ -z "$STACK_YAML" ]; then
27− ghc --version
28− cabal --version
29− cabal new-update
30− cabal new-build --enable-tests --enable-benchmarks
31− else
32− # install stack
33− curl -sSL https://get.haskellstack.org/ | sh
26+ # install stack
27+ curl -sSL https://get.haskellstack.org/ | sh
3428
35− # build project with stack
36− stack --version
37− stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks
38− fi
29+ # build project with stack
30+ stack --version
31+ stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks --resolver=$SNAPSHOT
3932
4033script:
4134 - |
42− if [ -z "$STACK_YAML" ]; then
43− cabal new-test --enable-tests
44− else
45− stack test --system-ghc
46− fi
35+ stack test --system-ghc
4736
4837notifications:
4938 email: false
README.md+2−1
@@ -2,7 +2,8 @@
22
33# ValidationT
44
5−A very small validation data library.
5+A simple data validation library. The main idea is to provide an easy way to
6+validate web form data by aggregating errors for each field.
67
78## Usage
89
src/Control/Monad/Validation.hs+18−5
@@ -16,6 +16,7 @@ module Control.Monad.Validation
1616 , vWarningL
1717 , vZoom
1818 , vZoomL
19+ , vPromote
1920 , mmSingleton
2021 , setMempty
2122 , neConcat
@@ -37,11 +38,14 @@ import Data.Foldable as F
3738import Data.Functor
3839import Data.List as L
3940import Data.Map.Strict as M
40−import Data.Monoid
4141import Data.Text as T
4242import Data.Vector as V
4343import Test.QuickCheck
4444
45+#if MIN_VERSION_mtl(2,3,0)
46+import Control.Monad
47+import Control.Monad.Fix
48+#endif
4549
4650-- | Collects all thrown warnings in 'StateT' and errors
4751-- in 'ExceptT' into a single value using 'Monoid'.
@@ -85,7 +89,7 @@ instance (Ord k, Semigroup v) => Semigroup (MonoidMap k v) where
8589
8690instance (Ord k, Monoid v) => Monoid (MonoidMap k v) where
8791 mempty = MonoidMap M.empty
88− mappend = mmAppend
92+ mappend = (<>)
8993
9094instance (ToJSON k, ToJSON v) => ToJSON (MonoidMap k v) where
9195 toJSON (MonoidMap m) = toJSON $ L.map toObj $ M.toList m
@@ -143,12 +147,12 @@ neConcat f a
143147textErrors :: [Text] -> Maybe Text
144148textErrors = neConcat (\a b -> a <> ", " <> b)
145149
146−-- | Returns 'mempty' instead of error if no warnings have occured.
150+-- | Returns 'mempty' instead of error if no warnings have occurred.
147151-- Returns 'Nothing' as the second element of tuple if computation was
148152-- interrupted by 'vError'.
149153--
150154-- Returns all concatenated errors and warnings and the result if no
151−-- errors have occured (warnings could have occured).
155+-- errors have occurred (warnings could have occurred).
152156--
153157-- >>> :{
154158-- runValidationT $ do
@@ -174,7 +178,7 @@ runValidationT (ValidationT m) = do
174178 Right a -> (warnings, Just a)
175179
176180-- | Like 'runValidationT' but doesn't return the result
177−-- if any warning has occured.
181+-- if any warning has occurred.
178182--
179183-- >>> :{
180184-- runValidationTEither $ do
@@ -285,3 +289,12 @@ vZoomL
285289 -> ValidationT a m x
286290 -> ValidationT b m x
287291vZoomL l = vZoom (setMempty l)
292+
293+-- | Turn any warnings the have occurred into errors.
294+vPromote
295+ :: (Monad m, Monoid a, Eq a)
296+ => ValidationT a m x
297+ -> ValidationT a m x
298+vPromote m = do
299+ err <- lift $ runValidationTEither m
300+ either vError return err
stack.yaml+1−1
@@ -15,7 +15,7 @@
1515# resolver:
1616# name: custom-snapshot
1717# location: "./custom-snapshot.yaml"
18−resolver: lts-14.21
18+resolver: lts-22.4
1919
2020# User packages to be built.
2121# Various formats can be used as shown in the example below.
test/Doc.hs+1−1
@@ -3,4 +3,4 @@ module Main (main) where
33import Test.DocTest
44
55main :: IO ()
6−main = doctest [ "-XOverloadedStrings", "src" ]
6+main = doctest [ "-XOverloadedStrings", "-isrc", "src" ]
validationt.cabal+17−22
@@ -3,8 +3,10 @@
33
44name: validationt
55version: 0.3.0
6−synopsis: Straightforward validation monad.
7−description: Convenient solution for validating web forms and APIs.
6+synopsis: Straightforward validation monad
7+description:
8+ A simple data validation library. The main idea is to provide an easy way to validate web form data by aggregating errors for each field.
9+ .
810homepage: https://github.com/typeable/validationt
911license: BSD3
1012license-file: LICENSE
@@ -14,9 +16,12 @@ maintainer: makeit@typeable.io
1416category: Control
1517build-type: Simple
1618extra-source-files: ChangeLog.md
19+ , README.md
1720cabal-version: >=1.10
1821tested-with: GHC == 8.4.4
1922 , GHC == 8.6.5
23+ , GHC == 8.8.4
24+ , GHC == 8.10.2
2025
2126source-repository head
2227 type: git
@@ -24,14 +29,14 @@ source-repository head
2429
2530library
2631 exposed-modules: Control.Monad.Validation
27− build-depends: base >=4.8 && < 5
28− , aeson >= 1.0
32+ build-depends: base >=4.10 && < 5
33+ , aeson >=1.0
2934 , containers
30− , exceptions
35+ , exceptions >=0.9
3136 , lens
3237 , monad-control
33− , mtl
34− , QuickCheck
38+ , mtl <2.3 || >2.3
39+ , QuickCheck >=2.8.2
3540 , text
3641 , transformers
3742 , transformers-base
@@ -50,22 +55,12 @@ library
5055 -Wmissing-export-lists
5156
5257test-suite doctest
58+ default-language: Haskell2010
5359 type: exitcode-stdio-1.0
5460 hs-source-dirs: test
5561 ghc-options: -Wall
5662 main-is: Doc.hs
57− default-language: Haskell2010
58− build-depends: base >=4.8 && < 5
59− , aeson >= 1.0
60− , doctest
61− , containers
62− , exceptions
63− , lens
64− , monad-control
65− , mtl
66− , QuickCheck
67− , text
68− , transformers
69− , transformers-base
70− , vector
71− , doctest
63+ build-depends:
64+ base >= 4.10.0.0
65+ , doctest >= 0.11.4
66+ , validationt