validation-selective: Lighweight pure data validation based on Applicative and Selective functors

[ data, library, mpl, selective, validation ] [ Propose Tags ]

Lighweight pure data validation based on Applicative and Selective functors. The library builds validation interface around the following data type:

data Validation e a
    = Failure e
    | Success a

[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.0.0, 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.2.0.0
Change log CHANGELOG.md
Dependencies base (>=4.12 && <4.21), deepseq (>=1.4.3.0 && <1.6), selective (>=0.3 && <0.8) [details]
License MPL-2.0
Copyright 2020-2023 Kowainik
Author Dmitrii Kovanikov, Veronika Romashkina
Maintainer Kowainik <xrom.xkov@gmail.com>
Revised Revision 4 made by tomjaguarpaw at 2024-05-19T16:04:15Z
Category Validation, Selective, Data
Home page https://github.com/kowainik/validation-selective
Bug tracker https://github.com/kowainik/validation-selective/issues
Source repo head: git clone https://github.com/kowainik/validation-selective.git
Uploaded by vrom911 at 2023-03-01T16:43:02Z
Distributions Arch:0.2.0.0, NixOS:0.2.0.0, Stackage:0.2.0.0
Reverse Dependencies 10 direct, 24 indirect [details]
Downloads 8787 total (166 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-03-01 [all 1 reports]

Readme for validation-selective-0.2.0.0

[back to package description]

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:

  • Lightweight. validation-selective depends only on base and selective (which is tiny) Haskell libraries which make this package fast to build. So adding validation capabilities to your library or application doesn't contribute much to your dependency footprint.
  • Selective instance. validation-selective is the only package that provides Selective instance for Validation which allows using Monad-like branching behaviour but without implementing wrong Monad instance.
  • More algebraic instances. validation-selective also provides the Alternative instance and a more general Semigroup instance.
  • Best-in-class documentation. Official Haddock documentation contains mini-tutorial, usage example, per-component comparison with Either, the motivation behind each instance and the interface in general along with examples for each instance and function.

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

  • either: Validation implementation by Edward Kmett. This package is more heavyweight, since it depends on more Haskell libraries like profunctors, bifunctors, semigroupoids. But it also provides prisms for Validation and some combinators for Either.
  • validation: Validation from Queensland Functional Programming Lab. Depends on lens, which makes it even heavier but also have richer interface compared to the either package.

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