Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Data.Text.show and Data.Text.Lazy.show #608

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ module Data.Text
, zip
, zipWith

-- * Showing values
, show

-- -* Ordered text
-- , sort

Expand All @@ -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))
Expand Down Expand Up @@ -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.
--
Expand Down
9 changes: 8 additions & 1 deletion src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
Loading