From 6ed3cae83734b492309119533ff8f0e0aa64e40a Mon Sep 17 00:00:00 2001 From: Li-yao Xia Date: Thu, 8 Aug 2024 10:38:24 +0200 Subject: [PATCH] Add Data.Text.show and Data.Text.Lazy.show --- src/Data/Text.hs | 9 ++++++++- src/Data/Text/Lazy.hs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Data/Text.hs b/src/Data/Text.hs index c14abf6e..790e9d1a 100644 --- a/src/Data/Text.hs +++ b/src/Data/Text.hs @@ -202,6 +202,9 @@ module Data.Text , zip , zipWith + -- * Showing values + , show + -- -* Ordered text -- , sort @@ -215,7 +218,7 @@ module Data.Text import Prelude (Char, Bool(..), Int, Maybe(..), String, Eq, (==), (/=), Ord(..), Ordering(..), (++), - Monad(..), pure, Read(..), + Monad(..), pure, Read(..), Show, (&&), (||), (+), (-), (.), ($), ($!), (>>), not, return, otherwise, quot) import Control.DeepSeq (NFData(rnf)) @@ -2050,6 +2053,10 @@ emptyError fun = P.error $ "Data.Text." ++ fun ++ ": empty input" overflowError :: HasCallStack => String -> a overflowError fun = P.error $ "Data.Text." ++ fun ++ ": size overflow" +-- | Convert a value to 'Text'. +show :: Show a => a -> Text +show = pack . P.show + -- | /O(n)/ Make a distinct copy of the given string, sharing no -- storage with the original string. -- diff --git a/src/Data/Text/Lazy.hs b/src/Data/Text/Lazy.hs index f17f2c29..9c0f0dd6 100644 --- a/src/Data/Text/Lazy.hs +++ b/src/Data/Text/Lazy.hs @@ -201,12 +201,15 @@ module Data.Text.Lazy , zip , zipWith + -- * Showing values + , show + -- -* Ordered text -- , sort ) where import Prelude (Char, Bool(..), Maybe(..), String, - Eq, (==), Ord(..), Ordering(..), Read(..), Show(..), + Eq, (==), Ord(..), Ordering(..), Read(..), Show(showsPrec), Monad(..), pure, (<$>), (&&), (+), (-), (.), ($), (++), error, flip, fmap, fromIntegral, not, otherwise, quot) @@ -1792,6 +1795,10 @@ zipWith f t1 t2 = unstream (S.zipWith g (stream t1) (stream t2)) where g a b = safe (f a b) {-# INLINE [0] zipWith #-} +-- | Convert a value to lazy 'Text'. +show :: Show a => a -> Text +show = pack . P.show + revChunks :: [T.Text] -> Text revChunks = L.foldl' (flip chunk) Empty