Skip to content

Define stimes 0 for lazy text #641

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

Merged
merged 1 commit into from
Jun 21, 2025
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
7 changes: 7 additions & 0 deletions src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ instance Read Text where
-- | @since 1.2.2.0
instance Semigroup Text where
(<>) = append
stimes n _ | n < 0 = P.error "Data.Text.Lazy.stimes: given number is negative!"
stimes n a =
let nInt64 = fromIntegral n :: Int64
len = if n == fromIntegral nInt64 && nInt64 >= 0 then nInt64 else P.maxBound
-- We clamp the length to maxBound :: Int64.
-- To tell the difference, the caller would have to skip through 2^63 chunks.
in replicate len a

instance Monoid Text where
mempty = empty
Expand Down
4 changes: 4 additions & 0 deletions tests/Tests/Properties/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ tl_mappend s = mappend s`eqP` (unpackS . mappend (TL.pack s))
t_stimes = \ number -> eq
((stimes :: Int -> String -> String) number . unSqrt)
(unpackS . (stimes :: Int -> T.Text -> T.Text) number . T.pack . unSqrt)
tl_stimes = \ number -> eq
((stimes :: Int -> String -> String) number . unSqrt)
(unpackS . (stimes :: Int -> TL.Text -> TL.Text) number . TL.pack . unSqrt)
t_mconcat = (mconcat . unSqrt) `eq` (unpackS . mconcat . L.map T.pack . unSqrt)
tl_mconcat = (mconcat . unSqrt) `eq` (unpackS . mconcat . L.map TL.pack . unSqrt)
t_mempty = mempty === (unpackS (mempty :: T.Text))
Expand Down Expand Up @@ -76,6 +79,7 @@ testInstances =
testProperty "t_mappend" t_mappend,
testProperty "tl_mappend" tl_mappend,
testProperty "t_stimes" t_stimes,
testProperty "tl_stimes" tl_stimes,
testProperty "t_mconcat" t_mconcat,
testProperty "tl_mconcat" tl_mconcat,
testProperty "t_mempty" t_mempty,
Expand Down