valida-base 0.1.0 → 0.1.1
raw patch · 3 files changed
+16/−13 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−1
- README.md +10/−10
- valida-base.cabal +2/−2
ChangeLog.md view
@@ -1,6 +1,9 @@-# Changelog for valida +# Changelog for valida-base ## Unreleased changes + +## 0.1.1 +General fixes to metadata files. ## 0.1.0 Initial release.
README.md view
@@ -1,7 +1,7 @@ # Valida Simple, elegant, applicative validation for product types - batteries included! -Read the documentation on [hackage](https://hackage.haskell.org/package/valida). +Read the documentation on [hackage](https://hackage.haskell.org/package/valida-base). # Highlights * Minimal - *Zero dependencies* apart from `base`. @@ -63,7 +63,7 @@ You can also find more examples [here](./examples/Main.hs). # Quick Start -The primary purpose of the `Validator` type is to validate each field in product types. To do this, you'll use [`verify`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:verify). +The primary purpose of the `Validator` type is to validate each field in product types. To do this, you'll use [`verify`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:verify). `verify` takes 2 inputs- * The "selector", which essentially just takes the product type as input, and returns the specific value of the specific field to validate. @@ -74,7 +74,7 @@ pairValidator :: Validator (NonEmpty String) (Int, String) (Int, String) pairValidator = (,) <$> verify (failureIf (>=10) "NotLessThan10") fst <*> verify (notEmpty "EmptyString") snd ``` -Or, if you prefer using operators - you can use [`-?>`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:-45--63--62-), which is a flipped version of `verify`. +Or, if you prefer using operators - you can use [`-?>`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:-45--63--62-), which is a flipped version of `verify`. ```hs pairValidator :: Validator (NonEmpty String) (Int, String) (Int, String) pairValidator = (,) @@ -82,7 +82,7 @@ <*> snd -?> notEmpty "EmptyString" ``` -You can then run the validator on your input using [`runValidator`](https://hackage.haskell.org/package/valida/docs/Valida.html#t:Validator)- +You can then run the validator on your input using [`runValidator`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#t:Validator)- ```hs >>> runValidator pairValidator (9, "foo") Success (9,"foo") @@ -92,7 +92,7 @@ Failure ("EmptyString" :| []) ``` -This is the core concept for building the validators. You can use the primitive combinators (e.g [`failureIf`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:failureIf), [`failureUnless`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:failureUnless)) to build `ValidationRule`s directly from predicate functions, or you can choose one of the many derivate combinators (e.g [`notEmpty`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:notEmpty)) to build `ValidationRule`s. Check out the [`Valida.Combinators`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html) module documentation to view all the included combinators. +This is the core concept for building the validators. You can use the primitive combinators (e.g [`failureIf`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:failureIf), [`failureUnless`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:failureUnless)) to build `ValidationRule`s directly from predicate functions, or you can choose one of the many derivate combinators (e.g [`notEmpty`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:notEmpty)) to build `ValidationRule`s. Check out the [`Valida.Combinators`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html) module documentation to view all the included combinators. ## Validators for non product types Although the primary purpose of Valida is building convenient validators for product types. Sometimes, you'll find yourself not needing to select on any field, but validating the input directly. In that case, you may find yourself using this pattern- @@ -102,14 +102,14 @@ intValidator = verify (failureIf even "Even") id ``` -In these situations, instead of using `verify` with `id` as selector, you should use [`validate`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:validate) instead, which is the same as `flip verify id`- +In these situations, instead of using `verify` with `id` as selector, you should use [`validate`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:validate) instead, which is the same as `flip verify id`- ```hs intValidator :: Validator (NonEmpty String) Int Int intValidator = validate (failureIf even "Even") ``` ## Combining multiple `ValidationRule`s -Often, you'll find yourself in situations where you expect the input to satisfy *multiple* `ValidationRule`s, or situations where you expect the input to satisfy *at least one* of many `ValidationRule`s. This is where [`andAlso`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:andAlso), and [`orElse`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:orElse) come into play. +Often, you'll find yourself in situations where you expect the input to satisfy *multiple* `ValidationRule`s, or situations where you expect the input to satisfy *at least one* of many `ValidationRule`s. This is where [`andAlso`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:andAlso), and [`orElse`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:orElse) come into play. ### Combining multiple `ValidationRule`s with `andAlso` `andAlso` is the semigroup implementation of `ValidationRule`, and thus is the same as `<>`. Combining 2 rules with `<>` creates a new rule that is only satisfied when *both of the given rules are satisfied*. Otherwise, the very first (left most) failure value is returned - and the rest are not tried. @@ -164,17 +164,17 @@ ``` ### Combining a foldable of `ValidationRule`s -You can combine a foldable of `ValidationRule`s using [`satisfyAll`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:satisfyAll) and [`satisfyAny`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:satisfyAny). `satisfyAll` folds using `andAlso`/`<>`, while `satisfyAny` folds using `orElse`/`</>`. +You can combine a foldable of `ValidationRule`s using [`satisfyAll`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:satisfyAll) and [`satisfyAny`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:satisfyAny). `satisfyAll` folds using `andAlso`/`<>`, while `satisfyAny` folds using `orElse`/`</>`. ## Ignoring errors -Although, highly inadvisable and generally not useful in serious code, you may use alternative versions of `ValidationRule` combinators that use `()` (unit) as its error type so you don't have to supply error values. For example, [`failureIf'`](https://hackage.haskell.org/package/valida/docs/Valida-Combinators.html#v:failureIf-39-) does not require an error value to be supplied. In case of failure, it simply yields `Failure ()`. +Although, highly inadvisable and generally not useful in serious code, you may use alternative versions of `ValidationRule` combinators that use `()` (unit) as its error type so you don't have to supply error values. For example, [`failureIf'`](https://hackage.haskell.org/package/valida-base/docs/Valida-Combinators.html#v:failureIf-39-) does not require an error value to be supplied. In case of failure, it simply yields `Failure ()`. ```hs >>> runValidator (validate (failureIf' even)) 2 Failure () ``` ## Re-assigning errors -Using the [`label`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:label)/[`<?>`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:-60--63--62-) and [`labelV`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:labelV)/[`<??>`](https://hackage.haskell.org/package/valida/docs/Valida.html#v:-60--63--63--62-) functions, you can use override the errors `ValidationRule`s and `Validator`s yield. +Using the [`label`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:label)/[`<?>`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:-60--63--62-) and [`labelV`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:labelV)/[`<??>`](https://hackage.haskell.org/package/valida-base/docs/Valida.html#v:-60--63--63--62-) functions, you can use override the errors `ValidationRule`s and `Validator`s yield. For example, to re assign the error on a `ValidationRule`- ```hs
valida-base.cabal view
@@ -5,9 +5,9 @@ -- see: https://github.com/sol/hpack name: valida-base-version: 0.1.0+version: 0.1.1 synopsis: Simple applicative validation for product types, batteries included!-description: This is a zero dependency version of the valida package. It is equivalent to valida == 0.1.0. Check out the README at github <https://github.com/TotallyNotChase/valida#readme>!+description: This is a zero dependency version of the valida package. It is equivalent to valida == 0.1.0. Check out the README at github <https://github.com/TotallyNotChase/valida-base#readme>! category: Validation, Data homepage: https://github.com/TotallyNotChase/valida-base#readme bug-reports: https://github.com/TotallyNotChase/valida-base/issues