Safe Haskell | None |
---|---|
Language | Haskell2010 |
General-purpose utility functions
Synopsis
- data VerificationRes
- = VerSuccess
- | VerFailure !(NonEmpty Text)
- isVerFailure :: VerificationRes -> Bool
- isVerSuccess :: VerificationRes -> Bool
- verResToMonadError :: MonadError e m => (NonEmpty Text -> e) -> VerificationRes -> m ()
- verifyGeneric :: [(Bool, Text)] -> VerificationRes
- formatAllErrors :: NonEmpty Text -> Text
- formatFirstError :: NonEmpty Text -> Text
- verResFullF :: VerificationRes -> Text
- verResSingleF :: VerificationRes -> Text
Documentation
data VerificationRes Source #
Instances
Eq VerificationRes Source # | |
Defined in Serokell.Util.Verify (==) :: VerificationRes -> VerificationRes -> Bool # (/=) :: VerificationRes -> VerificationRes -> Bool # | |
Show VerificationRes Source # | |
Defined in Serokell.Util.Verify showsPrec :: Int -> VerificationRes -> ShowS # show :: VerificationRes -> String # showList :: [VerificationRes] -> ShowS # | |
Semigroup VerificationRes Source # | |
Defined in Serokell.Util.Verify (<>) :: VerificationRes -> VerificationRes -> VerificationRes # sconcat :: NonEmpty VerificationRes -> VerificationRes # stimes :: Integral b => b -> VerificationRes -> VerificationRes # | |
Monoid VerificationRes Source # | |
Defined in Serokell.Util.Verify mappend :: VerificationRes -> VerificationRes -> VerificationRes # mconcat :: [VerificationRes] -> VerificationRes # | |
Arbitrary VerificationRes # | |
Defined in Serokell.Arbitrary arbitrary :: Gen VerificationRes # shrink :: VerificationRes -> [VerificationRes] # |
Helpers
isVerFailure :: VerificationRes -> Bool Source #
isVerSuccess :: VerificationRes -> Bool Source #
verResToMonadError :: MonadError e m => (NonEmpty Text -> e) -> VerificationRes -> m () Source #
Verification
verifyGeneric :: [(Bool, Text)] -> VerificationRes Source #
This function takes list of (predicate, message) pairs and checks each predicate. If predicate is False it's considered an error. If there is at least one error this function returns VerFailure, otherwise VerSuccess is returned. It's useful to verify some data before using it. Example usage: `verifyGeneric [(checkA, "A is bad"), (checkB, "B is bad")]`
Prety printing
formatAllErrors :: NonEmpty Text -> Text Source #
Pretty printer for errors from VerFailure, all errors are printed.
formatFirstError :: NonEmpty Text -> Text Source #
Pretty printer for errors from VerFailure, only first error is printed.
verResFullF :: VerificationRes -> Text Source #
Format VerificationRes in a pretty way using all errors messages for VerFailure.
verResSingleF :: VerificationRes -> Text Source #
Format VerificationRes in a pretty way using only first message for VerFailure.