on master help sign in
Fix up lazy concat and concatMap.

--HG-- extra : convert_revision : e89ea3bc1859cd851476927bab0af2f4fd9f2cf4

commitaf4e4029340fc725cab9a8a730b46edd98194fff authorBryan O'Sullivan <bos@serpentine.com> dateMon 30 Nov 2009, 07:48 (17 years ago) parentb3fad05
1 file changed+9−7
Data/Text/Lazy.hs+9−7
Data/Text/Lazy.hs+9−7
@@ -547,18 +547,20 @@ foldr1 :: (Char -> Char -> Char) -> Text -> Char
547547foldr1 f t = S.foldr1 f (stream t)
548548{-# INLINE foldr1 #-}
549549
550−-- | /O(n)/ Concatenate a list of 'Text's. Subject to array fusion.
550+-- | /O(n)/ Concatenate a list of 'Text's.
551551concat :: [Text] -> Text
552−concat ts = unstream (S.concat (L.map stream ts))
552+concat = to
553+ where
554+ go Empty css = to css
555+ go (Chunk c cs) css = Chunk c (go cs css)
556+ to [] = Empty
557+ to (cs:css) = go cs css
553558{-# INLINE concat #-}
554559
555560-- | /O(n)/ Map a function over a 'Text' that results in a 'Text', and
556−-- concatenate the results. This function is subject to array fusion.
557−--
558−-- Note: if in 'concatMap' @f@ @t@, @f@ is defined in terms of fusible
559−-- functions, it will also be fusible.
561+-- concatenate the results.
560562concatMap :: (Char -> Text) -> Text -> Text
561−concatMap f t = unstream (S.concatMap (stream . f) (stream t))
563+concatMap f = concat . foldr ((:) . f) []
562564{-# INLINE concatMap #-}
563565
564566-- | /O(n)/ 'any' @p@ @t@ determines whether any character in the