Skip to content

Commit

Permalink
Prepare 0.1.0.0 release (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
chshersh authored May 5, 2020
1 parent 8dc86be commit 5b46cd4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
`validation-selective` uses [PVP Versioning][1].
The changelog is available [on GitHub][2].

## Unreleased
## 0.1.0.0 — May 5, 2020

* [#41](https://github.com/kowainik/relude/issues/41):
Support GHC-8.10.1.
(by [@chshersh](https://github.com/chshersh))
* [#24](https://github.com/kowainik/relude/issues/24):
Add `validationAll`, `when*` and `maybe*` combinators into
`Validation.Combinators`.
(by [@vrom911](https://github.com/vrom911))

## 0.0.0.0

Expand Down
16 changes: 14 additions & 2 deletions src/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ validatePassword password =
validateShortPassword password *> validatePasswordDigit password
:}
Let's see how it works:
>>> validatePassword "abcd"
Expand All @@ -280,6 +281,17 @@ Failure (ShortPassword :| [])
>>> validatePassword "abcd12345"
Success "abcd12345"
The @validation@ library provides several convenient combinators, so
you can write the password check in a shorter way:
@
validatePassword :: 'String' -> 'Validation' ('NonEmpty' FormValidationError) Password
validatePassword = 'fmap' Password . 'validateAll'
[ (\`'failureIf'\` ShortPassword) . (< 8) . 'length'
, (\`'failureUnless'\` NoDigitPassword) . 'any' isDigit
]
@
After we've implemented validations for all fields, we can compose
them together to produce validation for the whole @User@. As before,
we are going to use the 'Applicative' instance:
Expand Down Expand Up @@ -1129,7 +1141,7 @@ failure e = Failure (e :| [])
{-# INLINE failure #-}

{- | Returns a 'Failure' in case of the given predicate is 'True'.
Returns @'Success' '()'@ otherwise.
Returns @'Success' ()@ otherwise.
>>> let shouldFail = (==) "I am a failure"
>>> failureIf (shouldFail "I am a failure") "I told you so"
Expand All @@ -1144,7 +1156,7 @@ failureIf p e
{-# INLINE failureIf #-}

{- | Returns a 'Failure' unless the given predicate is 'True'.
Returns @'Success' '()'@ in case of the predicate is satisfied.
Returns @'Success' ()@ in case of the predicate is satisfied.
Similar to 'failureIf' with the reversed predicate.
Expand Down
18 changes: 9 additions & 9 deletions src/Validation/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ start element when all checks are successful.
A basic example of usage could look like this:
@
> let validatePassword = validateAll
> __let__ validatePassword = 'validateAll'
[ validateEmptyPassword
, validateShortPassword
]
> validateAll "VeryStrongPassword"
Success "VeryStrongPassword"
> 'validateAll' \"VeryStrongPassword\"
'Success' \"VeryStrongPassword\"
> validateAll ""
Failure (EmptyPassword :| [ShortPassword])
> 'validateAll' ""
'Failure' (EmptyPassword :| [ShortPassword])
@
-}
validateAll
Expand Down Expand Up @@ -77,7 +77,7 @@ whenFailure a (Success _) _ = pure a

{- | Applies given action to the 'Validation' content if it is 'Failure'.
Similar to 'whenFailure' but the default value is '()'.
Similar to 'whenFailure' but the default value is @()@.
>>> whenFailure_ (Success 42) putStrLn
>>> whenFailure_ (Failure "foo") putStrLn
Expand All @@ -104,7 +104,7 @@ whenFailureM x mv f = mv >>= \v -> whenFailure x v f

{- | Monadic version of 'whenFailure_'.
Applies monadic action to the given 'Validation' in case of 'Failure'.
Similar to 'whenFailureM' but the default is '()'.
Similar to 'whenFailureM' but the default is @()@.
>>> whenFailureM_ (pure $ Success 42) putStrLn
>>> whenFailureM_ (pure $ Failure "foo") putStrLn
Expand All @@ -131,7 +131,7 @@ whenSuccess _ (Success a) f = f a

{- | Applies given action to the 'Validation' content if it is 'Success'.
Similar to 'whenSuccess' but the default value is '()'.
Similar to 'whenSuccess' but the default value is @()@.
>>> whenSuccess_ (Failure "foo") print
>>> whenSuccess_ (Success 42) print
Expand All @@ -158,7 +158,7 @@ whenSuccessM x mv f = mv >>= \v -> whenSuccess x v f

{- | Monadic version of 'whenSuccess_'.
Applies monadic action to the given 'Validation' in case of 'Success'.
Similar to 'whenSuccessM' but the default is '()'.
Similar to 'whenSuccessM' but the default is @()@.
>>> whenSuccessM_ (pure $ Failure "foo") print
>>> whenSuccessM_ (pure $ Success 42) print
Expand Down
2 changes: 1 addition & 1 deletion validation-selective.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: validation-selective
version: 0.0.0.1
version: 0.1.0.0
synopsis: Lighweight pure data validation based on Applicative and Selective functors
description:
Lighweight pure data validation based on Applicative and Selective
Expand Down

0 comments on commit 5b46cd4

Please sign in to comment.