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