@@ -52,9 +52,9 @@ module Data.Text.Lazy
5252 , length
5353
5454 -- * Transformations
55− -- , map
56− -- , intercalate
57− -- , intersperse
55+ , map
56+ , intercalate
57+ , intersperse
5858 -- , transpose
5959 -- , reverse
6060
@@ -153,6 +153,7 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
153153 fromIntegral, not, return, otherwise)
154154import qualified Prelude as P
155155import Data.Int (Int64)
156+import qualified Data.List as L
156157import Data.String (IsString(..))
157158import qualified Data.Text as T
158159import qualified Data.Text.Fusion as S
@@ -296,18 +297,6 @@ null _ = False
296297 S.null (stream t) = null t
297298 #-}
298299
299−length :: Text -> Int64
300−length = foldlChunks go 0
301− where go l t = l + fromIntegral (T.length t)
302−{-# INLINE [1] length #-}
303−
304−{-# RULES
305−"LAZY TEXT length -> fused" [~1] forall t.
306− length t = S.length64 (stream t)
307−"LAZY TEXT length -> unfused" [1] forall t.
308− S.length64 (stream t) = length t
309− #-}
310−
311300-- | /O(1)/ Returns the last character of a 'Text', which must be
312301-- non-empty. Subject to array fusion.
313302last :: Text -> Char
@@ -324,6 +313,37 @@ last (Chunk t ts) = go t ts
324313 S.last (stream t) = last t
325314 #-}
326315
316+length :: Text -> Int64
317+length = foldlChunks go 0
318+ where go l t = l + fromIntegral (T.length t)
319+{-# INLINE [1] length #-}
320+
321+{-# RULES
322+"LAZY TEXT length -> fused" [~1] forall t.
323+ length t = S.length64 (stream t)
324+"LAZY TEXT length -> unfused" [1] forall t.
325+ S.length64 (stream t) = length t
326+ #-}
327+
328+-- | /O(n)/ 'map' @f @xs is the 'Text' obtained by applying @f@ to
329+-- each element of @xs@. Subject to array fusion.
330+map :: (Char -> Char) -> Text -> Text
331+map f t = unstream (S.map f (stream t))
332+{-# INLINE [1] map #-}
333+
334+-- | /O(n)/ The 'intercalate' function takes a 'Text' and a list of
335+-- 'Text's and concatenates the list after interspersing the first
336+-- argument between each element of the list.
337+intercalate :: Text -> [Text] -> Text
338+intercalate t ts = unstream (S.intercalate (stream t) (L.map stream ts))
339+{-# INLINE intercalate #-}
340+
341+-- | /O(n)/ The 'intersperse' function takes a character and places it
342+-- between the characters of a 'Text'. Subject to array fusion.
343+intersperse :: Char -> Text -> Text
344+intersperse c t = unstream (S.intersperse c (stream t))
345+{-# INLINE intersperse #-}
346+
327347-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
328348-- prefix of @t@ of length @n@, and whose second is the remainder of
329349-- the string. It is equivalent to @('take' n t, 'drop' n t)@.