Skip to content

introduce prettyValidateFail, fixing issue #112 #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions validity/src/Data/Validity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module Data.Validity
checkValidity,
validationIsValid,
prettyValidate,
prettyValidateFail,
prettyValidation,

-- * Re-exports
Expand Down Expand Up @@ -679,3 +680,10 @@ prettyValidation v =
case i of
0 -> segment
_ -> replicate i ' ' ++ "\\ " ++ segment

-- | Validate a given value and fail the monadic computation if so.

-- This function will fail the moand with a nice error if the value is invalid.
-- It will return the original value wrapped in the monadic context if it was valid.
prettyValidateFail :: (Validity a, MonadFail m) => a -> m a
prettyValidateFail = either fail pure . prettyValidate
2 changes: 1 addition & 1 deletion validity/validity.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: validity
version: 0.12.0.1
version: 0.13.0.0
synopsis: Validity typeclass
description: For more info, see <https://github.com/NorfairKing/validity the readme>.
.
Expand Down