Skip to content
This repository has been archived by the owner on Sep 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #55 from serokell/vrom911/54-formatting
Browse files Browse the repository at this point in the history
[#54] Change return type of formatting funcs to Text
  • Loading branch information
chshersh authored Feb 21, 2018
2 parents 1c45b7c + 9b1a537 commit 1ca2340
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.8.0
=====

* [#54](https://github.com/serokell/serokell-util/issues/54):
Change the return type of formatting functions in `Verify`
to `Text` instead of `Builder`.

0.7.0
=====

Expand Down
2 changes: 1 addition & 1 deletion serokell-util.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: serokell-util
version: 0.7.0
version: 0.8.0
synopsis: General-purpose functions by Serokell
homepage: https://github.com/serokell/serokell-util
license: MIT
Expand Down
13 changes: 7 additions & 6 deletions src/Serokell/Util/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Serokell.Util.Verify
import Universum

import Control.Monad.Except (MonadError, throwError)
import Fmt (fmt)

import Serokell.Util.Text (listBuilder)

Expand Down Expand Up @@ -69,15 +70,15 @@ verifyGeneric errors = case messages of

-- | Format VerificationRes in a pretty way using all errors messages
-- for VerFailure.
verResFullF :: VerificationRes -> B.Builder
verResFullF :: VerificationRes -> Text
verResFullF VerSuccess = "success"
verResFullF (VerFailure errors) = buildVerResImpl errors
verResFullF (VerFailure errors) = fmt $ buildVerResImpl errors

-- | Format VerificationRes in a pretty way using only first message
-- for VerFailure.
verResSingleF :: VerificationRes -> B.Builder
verResSingleF :: VerificationRes -> Text
verResSingleF VerSuccess = "success"
verResSingleF (VerFailure errors) = buildVerResImpl $ one $ head errors
verResSingleF (VerFailure errors) = fmt $ buildVerResImpl $ one $ head errors

buildVerResImpl :: NonEmpty Text -> B.Builder
buildVerResImpl errors =
Expand All @@ -86,11 +87,11 @@ buildVerResImpl errors =
-- These two functions can have more general type.

-- | Pretty printer for errors from VerFailure, all errors are printed.
formatAllErrors :: NonEmpty Text -> B.Builder
formatAllErrors :: NonEmpty Text -> Text
formatAllErrors = verResFullF . VerFailure

-- | Pretty printer for errors from VerFailure, only first error is printed.
formatFirstError :: NonEmpty Text -> B.Builder
formatFirstError :: NonEmpty Text -> Text
formatFirstError = verResSingleF . VerFailure

----------------------------------------------------------------------------
Expand Down

0 comments on commit 1ca2340

Please sign in to comment.