Home

Awesome

validation-selective

Logo GitHub CI

Hackage MPL-2.0 license

Lightweight pure data validation based on Applicative and Selective functors.

validation-selective is built around the following data type:

data Validation e a
    = Failure e
    | Success a

This data type is similar to Either but allows accumulating all errors instead of short-circuiting on the first one.

For more examples and library tutorial, refer to Haddock:

Comparison with other packages

validation-selective is not the only package that provides such Validation data type. However, unlike other packages, it has some noticeable advantages:

The below section provides per-package comparison with the most popular validation packages in the Haskell ecosystem:

How to use

validation-selective is compatible with the latest GHC compiler versions starting from 8.6.

In order to start using validation-selective in your project, you will need to set it up with the three easy steps:

  1. Add the dependency on validation-selective in your project's .cabal file. For this, you should modify the build-depends section by adding the name of this library. After the adjustment, this section could look like this:

    build-depends: base ^>= 4.14
                 , validation-selective ^>= 0.0
    
  2. In the module where you wish to implement pure data validation, you should add the import:

    import Validation (Validation (..))
    
  3. Now you can use the types and functions from the library:

    main :: IO ()
    main = print [Failure "wrong", Success 42]
    

Usage with Stack

If validation-selective is not available on your current Stackage resolver yet, fear not! You can still use it from Hackage by adding the following to the extra-deps section of your stack.yaml file:

extra-deps:
  - validation-selective-CURRENT_VERSION