validators alternatives and similar packages
Based on the "Data" category.
Alternatively, view validators alternatives based on common mentions on social networks and blogs.
-
lens
Lenses, Folds, and Traversals - Join us on web.libera.chat #haskell-lens -
semantic-source
Parsing, analyzing, and comparing source code across many languages -
code-builder
Packages for defining APIs, running them, generating client code and documentation. -
text
Haskell library for space- and time-efficient operations over Unicode text. -
compendium-client
Mu (μ) is a purely functional framework for building micro services. -
cassava
A CSV parsing and encoding library optimized for ease of use and high performance -
unordered-containers
Efficient hashing-based container types -
holmes
A reference library for constraint-solving with propagators and CDCL. -
binary
Efficient, pure binary serialisation using ByteStrings in Haskell. -
primitive
This package provides various primitive memory-related operations. -
resource-pool
A high-performance striped resource pooling implementation for Haskell -
audiovisual
Extensible records, variants, structs, effects, tangles -
discrimination
Fast linear time sorting and discrimination for a large class of data types -
dependent-map
Dependently-typed finite maps (partial dependent products) -
dependent-sum
Dependent sums and supporting typeclasses for comparing and displaying them -
IORefCAS
A collection of different packages for CAS based data structures. -
safecopy
An extension to Data.Serialize with built-in version control -
streaming
An optimized general monad transformer for streaming applications, with a simple prelude of functions -
orgmode-parse
Attoparsec parser combinators for parsing org-mode structured text! -
reflection
Reifies arbitrary Haskell terms into types that can be reflected back into terms -
uuid-types
A Haskell library for creating, printing and parsing UUIDs -
scientific
Arbitrary-precision floating-point numbers represented using scientific notation
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of validators or a related project?
README
Validators
A library for validating input data in Haskell, inspired partly by elm-validate.
Concepts
Validator
The library provides a Validator
datatype for checking assertions
on input data. A validator is parametrized by 2 type variables:
err
: the type of error a validator can return,subject
: the type being inspected/validated.
Execute validators by using the validate
function:
data Error = TooSmall | TooBig
>>> let validator = assert (> 10) [TooSmall]
>>> validate validator 11 -- Success 11
>>> validate validator 4 -- Failure [TooSmall]
Validators return a Validation
type as result, which can be
further chained or checked for the final result. This is explained in
the Validation section.
Validators can also be combined using the Semigroup
instance,
resulting in a validator that accumulates errors from both sub-validators:
>>> let validator = maxSize 3 [TooBig] <> minSize 2 [TooSmall]
>>> validate validator [1, 2, 3] -- Success [1,2,3]
>>> validate validator [1, 2, 3, 4] -- Failure [TooBig]
>>> validate validator [1] -- Failure [TooSmall]
The library provides helper functions for commonly used validation checks. See the docs for a complete overview which validators are available.
Validation
Once a Validator
has been executed, it will return a Validation
data type.
This value will contain either all accumulated errors found during the checking
of assertions, or the given input value.
Validations are composed using their Applicative
instance. This can be useful
for example when validating product types. Like with Validator
, this will also
accumulate all encountered errors.
The following is an example for validating a Person
data type:
data PersonError = MissingName | InvalidAge
type Name = String
type Age = Int
data Person = Person Name Age
>>> let nameValidator = ifEmpty [MissingName]
>>> let ageValidator = assert (> 0) [InvalidAge]
>>> Person <$> validate nameValidator "" <*> validate ageValidator (subtract 1) -- Failure [MissingName, InvalidAge]
>>> Person <$> validate nameValidator "Alice" <*> validate ageValidator (subtract 1) -- Failure [InvalidAge]
>>> Person <$> validate nameValidator "Alice" <*> validate ageValidator 25 -- Success (Person "Alice" 25)
Contributing
The easiest way to start developing is by using Nix.
$ git clone [email protected]:luc-tielen/validators.git
$ cd validators
$ nix-shell
$ cabal new-configure # run inside the nix-shell
$ cabal new-build # run inside the nix-shell
The most often used commands are also provided by a Makefile.