Skip to content

Commit

Permalink
introduce prettyValidateFail, fixing issue NorfairKing#112
Browse files Browse the repository at this point in the history
  • Loading branch information
KommuSoft committed Jun 3, 2023
1 parent 20ddbd6 commit 9f805a9
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 9f805a9

Please sign in to comment.