git.iko.soy/typeable/validationt
on master help sign in
.travis.yml+14−27
since splitsnapshots
unifiedsplit
@@ -4,48 +4,35 @@ language: haskell
4git:
4git:
5 depth: 5
5 depth: 5
6
6
7−cabal: "2.4"
8−
9cache:
7cache:
10 directories:
8 directories:
11 - "$HOME/.cabal/store"
9 - "$HOME/.cabal/store"
12 - "$HOME/.stack"
10 - "$HOME/.stack"
13 - "$TRAVIS_BUILD_DIR/.stack-work"
11 - "$TRAVIS_BUILD_DIR/.stack-work"
14
12
15−matrix:
13+jobs:
16 include:
14 include:
17−
15+ - ghc: 8.10.2
18− # Cabal
16+ env: SNAPSHOT="nightly-2020-11-03"
19− - ghc: 8.4.4
17+ - ghc: 8.8.4
18+ env: SNAPSHOT="lts-16.20"
20 - ghc: 8.6.5
19 - ghc: 8.6.5
21−
20+ env: SNAPSHOT="lts-14.22"
22− # Stack
23− - ghc: 8.6.5
21+ - ghc: 8.4.4
24− env: STACK_YAML="$TRAVIS_BUILD_DIR/stack.yaml"
22+ env: SNAPSHOT="lts-12.26"
25
23
26install:
24install:
27 - |
25 - |
28− if [ -z "$STACK_YAML" ]; then
29− ghc --version
30− cabal --version
31− cabal new-update
32− cabal new-build --enable-tests --enable-benchmarks
33− else
34− # install stack
26+ # install stack
35− curl -sSL https://get.haskellstack.org/ | sh
27+ curl -sSL https://get.haskellstack.org/ | sh
36
28
37− # build project with stack
29+ # build project with stack
38− stack --version
30+ stack --version
39− stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks
31+ stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks --resolver=$SNAPSHOT
40− fi
41
32
42script:
33script:
43 - |
34 - |
44− if [ -z "$STACK_YAML" ]; then
45− cabal new-test --enable-tests
46− else
47− stack test --system-ghc
35+ stack test --system-ghc
48− fi
49
36
50notifications:
37notifications:
51 email: false
38 email: false
ChangeLog.md+6
@@ -1,5 +1,11 @@
1# Revision history for validationt
1# Revision history for validationt
2
2
3+## 0.3.0
4+
5+* Added documentation.
6+* Fixed `textErrors` behaviour.
7+* Dropped `transformers-lift` dependency.
8+
3## 0.2.1.0
9## 0.2.1.0
4
10
5* GHC 8.4 support
11* GHC 8.4 support
README.md+2−1
@@ -2,7 +2,8 @@
2
2
3# ValidationT
3# ValidationT
4
4
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.
6
7
7## Usage
8## Usage
8
9
src/Control/Monad/Validation.hs+18−5
@@ -16,6 +16,7 @@ module Control.Monad.Validation
16 , vWarningL
16 , vWarningL
17 , vZoom
17 , vZoom
18 , vZoomL
18 , vZoomL
19+ , vPromote
19 , mmSingleton
20 , mmSingleton
20 , setMempty
21 , setMempty
21 , neConcat
22 , neConcat
@@ -37,11 +38,14 @@ import Data.Foldable as F
37import Data.Functor
38import Data.Functor
38import Data.List as L
39import Data.List as L
39import Data.Map.Strict as M
40import Data.Map.Strict as M
40−import Data.Monoid
41import Data.Text as T
41import Data.Text as T
42import Data.Vector as V
42import Data.Vector as V
43import Test.QuickCheck
43import Test.QuickCheck
44
44
45+#if MIN_VERSION_mtl(2,3,0)
46+import Control.Monad
47+import Control.Monad.Fix
48+#endif
45
49
46-- | Collects all thrown warnings in 'StateT' and errors
50-- | Collects all thrown warnings in 'StateT' and errors
47-- in 'ExceptT' into a single value using 'Monoid'.
51-- in 'ExceptT' into a single value using 'Monoid'.
@@ -85,7 +89,7 @@ instance (Ord k, Semigroup v) => Semigroup (MonoidMap k v) where
85
89
86instance (Ord k, Monoid v) => Monoid (MonoidMap k v) where
90instance (Ord k, Monoid v) => Monoid (MonoidMap k v) where
87 mempty = MonoidMap M.empty
91 mempty = MonoidMap M.empty
88− mappend = mmAppend
92+ mappend = (<>)
89
93
90instance (ToJSON k, ToJSON v) => ToJSON (MonoidMap k v) where
94instance (ToJSON k, ToJSON v) => ToJSON (MonoidMap k v) where
91 toJSON (MonoidMap m) = toJSON $ L.map toObj $ M.toList m
95 toJSON (MonoidMap m) = toJSON $ L.map toObj $ M.toList m
@@ -143,12 +147,12 @@ neConcat f a
143textErrors :: [Text] -> Maybe Text
147textErrors :: [Text] -> Maybe Text
144textErrors = neConcat (\a b -> a <> ", " <> b)
148textErrors = neConcat (\a b -> a <> ", " <> b)
145
149
146−-- | Returns 'mempty' instead of error if no warnings have occured.
150+-- | Returns 'mempty' instead of error if no warnings have occurred.
147-- Returns 'Nothing' as the second element of tuple if computation was
151-- Returns 'Nothing' as the second element of tuple if computation was
148-- interrupted by 'vError'.
152-- interrupted by 'vError'.
149--
153--
150-- Returns all concatenated errors and warnings and the result if no
154-- 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).
152--
156--
153-- >>> :{
157-- >>> :{
154-- runValidationT $ do
158-- runValidationT $ do
@@ -174,7 +178,7 @@ runValidationT (ValidationT m) = do
174 Right a -> (warnings, Just a)
178 Right a -> (warnings, Just a)
175
179
176-- | Like 'runValidationT' but doesn't return the result
180-- | Like 'runValidationT' but doesn't return the result
177−-- if any warning has occured.
181+-- if any warning has occurred.
178--
182--
179-- >>> :{
183-- >>> :{
180-- runValidationTEither $ do
184-- runValidationTEither $ do
@@ -285,3 +289,12 @@ vZoomL
285 -> ValidationT a m x
289 -> ValidationT a m x
286 -> ValidationT b m x
290 -> ValidationT b m x
287vZoomL l = vZoom (setMempty l)
291vZoomL 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 @@
15# resolver:
15# resolver:
16# name: custom-snapshot
16# name: custom-snapshot
17# location: "./custom-snapshot.yaml"
17# location: "./custom-snapshot.yaml"
18−resolver: lts-14.21
18+resolver: lts-22.4
19
19
20# User packages to be built.
20# User packages to be built.
21# Various formats can be used as shown in the example below.
21# Various formats can be used as shown in the example below.
test/Doc.hs+1−1
@@ -3,4 +3,4 @@ module Main (main) where
3import Test.DocTest
3import Test.DocTest
4
4
5main :: IO ()
5main :: IO ()
6−main = doctest [ "-XOverloadedStrings", "src" ]
6+main = doctest [ "-XOverloadedStrings", "-isrc", "src" ]
validationt.cabal+18−22
@@ -2,9 +2,11 @@
2-- documentation, see http://haskell.org/cabal/users-guide/
2-- documentation, see http://haskell.org/cabal/users-guide/
3
3
4name: validationt
4name: validationt
5−version: 0.2.1.0
5+version: 0.3.0
6−synopsis: Straightforward validation monad.
6+synopsis: Straightforward validation monad
7−description: Convenient solution for validating web forms and APIs.
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+ .
8homepage: https://github.com/typeable/validationt
10homepage: https://github.com/typeable/validationt
9license: BSD3
11license: BSD3
10license-file: LICENSE
12license-file: LICENSE
@@ -14,9 +16,12 @@ maintainer: makeit@typeable.io
14category: Control
16category: Control
15build-type: Simple
17build-type: Simple
16extra-source-files: ChangeLog.md
18extra-source-files: ChangeLog.md
19+ , README.md
17cabal-version: >=1.10
20cabal-version: >=1.10
18tested-with: GHC == 8.4.4
21tested-with: GHC == 8.4.4
19 , GHC == 8.6.5
22 , GHC == 8.6.5
23+ , GHC == 8.8.4
24+ , GHC == 8.10.2
20
25
21source-repository head
26source-repository head
22 type: git
27 type: git
@@ -24,14 +29,14 @@ source-repository head
24
29
25library
30library
26 exposed-modules: Control.Monad.Validation
31 exposed-modules: Control.Monad.Validation
27− build-depends: base >=4.8 && < 5
32+ build-depends: base >=4.10 && < 5
28− , aeson >= 1.0
33+ , aeson >=1.0
29 , containers
34 , containers
30− , exceptions
35+ , exceptions >=0.9
31 , lens
36 , lens
32 , monad-control
37 , monad-control
33− , mtl
38+ , mtl <2.3 || >2.3
34− , QuickCheck
39+ , QuickCheck >=2.8.2
35 , text
40 , text
36 , transformers
41 , transformers
37 , transformers-base
42 , transformers-base
@@ -50,21 +55,12 @@ library
50 -Wmissing-export-lists
55 -Wmissing-export-lists
51
56
52test-suite doctest
57test-suite doctest
58+ default-language: Haskell2010
53 type: exitcode-stdio-1.0
59 type: exitcode-stdio-1.0
54 hs-source-dirs: test
60 hs-source-dirs: test
55 ghc-options: -Wall
61 ghc-options: -Wall
56 main-is: Doc.hs
62 main-is: Doc.hs
57− build-depends: base >=4.8 && < 5
63+ build-depends:
58− , aeson >= 1.0
64+ base >= 4.10.0.0
59− , doctest
65+ , doctest >= 0.11.4
60− , containers
66+ , validationt
61− , exceptions
62− , lens
63− , monad-control
64− , mtl
65− , QuickCheck
66− , text
67− , transformers
68− , transformers-base
69− , vector
70− , doctest