From 9b1a537d451c6708a81dc6e35202037f2802b5e5 Mon Sep 17 00:00:00 2001 From: vrom911 Date: Thu, 22 Feb 2018 01:31:26 +0300 Subject: [PATCH] [#54] Change return type of formatting funcs to Text --- CHANGES.md | 7 +++++++ serokell-util.cabal | 2 +- src/Serokell/Util/Verify.hs | 13 +++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3c8cd8b..ab9cfac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 ===== diff --git a/serokell-util.cabal b/serokell-util.cabal index 025cfa2..2daf848 100644 --- a/serokell-util.cabal +++ b/serokell-util.cabal @@ -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 diff --git a/src/Serokell/Util/Verify.hs b/src/Serokell/Util/Verify.hs index 74b42af..63ebed3 100644 --- a/src/Serokell/Util/Verify.hs +++ b/src/Serokell/Util/Verify.hs @@ -23,6 +23,7 @@ module Serokell.Util.Verify import Universum import Control.Monad.Except (MonadError, throwError) +import Fmt (fmt) import Serokell.Util.Text (listBuilder) @@ -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 = @@ -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 ----------------------------------------------------------------------------