validation-selective
Lighweight pure data validation based on Applicative and Selective functors
https://github.com/kowainik/validation-selective
LTS Haskell 18.28: | 0.1.0.1 |
Stackage Nightly 2024-09-07: | 0.2.0.0@rev:4 |
Latest on Hackage: | 0.2.0.0@rev:4 |
validation-selective-0.2.0.0@sha256:cc847f1a110e3b1bd437a5356f115881b61cafcb11781b570b180efd88bf0907,3917
Module documentation for 0.2.0.0
validation-selective
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 onbase
andselective
(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 providesSelective
instance forValidation
which allows usingMonad
-like branching behaviour but without implementing wrongMonad
instance. - More algebraic instances.
validation-selective
also provides theAlternative
instance and a more generalSemigroup
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 likeprofunctors
,bifunctors
,semigroupoids
. But it also provides prisms forValidation
and some combinators forEither
.validation
:Validation
from Queensland Functional Programming Lab. Depends onlens
, which makes it even heavier but also have richer interface compared to theeither
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:
-
Add the dependency on
validation-selective
in your project’s.cabal
file. For this, you should modify thebuild-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
-
In the module where you wish to implement pure data validation, you should add the import:
import Validation (Validation (..))
-
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
Changes
Changelog
validation-selective
uses PVP Versioning.
The changelog is available on GitHub.
0.2.0.0 — Mar 1, 2023
- #62: Support GHC-9.4.
- Allow
hedgehog-1.2
. - Allow
selective-0.6
. - Allow
doctest-0.21
. - Remove support for GHC-8.4 (due to
selective-0.6
, which dropped support for the earlier GHCs).
0.1.0.2 — Jun 11, 2021
🥧 0.1.0.1 — Mar 14, 2021
- #57: Support GHC-9.0. Upgrade minor version to 8.10.4 and 8.8.4.
0.1.0.0 — May 5, 2020
- #41: Support GHC-8.10.1.
- #24:
Add
validationAll
,when*
andmaybe*
combinators intoValidation.Combinators
.
0.0.0.0
- Initially created.