@@ -52,9 +52,9 @@ module Data.Text.Lazy
54 -- * Transformations
54 -- * Transformations
56− -- , intercalate
56+ , intercalate
57− -- , intersperse
57+ , intersperse
58 -- , transpose
58 -- , transpose
59 -- , reverse
59 -- , reverse
@@ -153,6 +153,7 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
153 fromIntegral, not, return, otherwise)
153 fromIntegral, not, return, otherwise)
154import qualified Prelude as P
154import qualified Prelude as P
155import Data.Int (Int64)
155import Data.Int (Int64)
156+import qualified Data.List as L
156import Data.String (IsString(..))
157import Data.String (IsString(..))
157import qualified Data.Text as T
158import qualified Data.Text as T
158import qualified Data.Text.Fusion as S
159import qualified Data.Text.Fusion as S
@@ -296,18 +297,6 @@ null _ = False
296 S.null (stream t) = null t
297 S.null (stream t) = null t
299−length :: Text -> Int64
300−length = foldlChunks go 0
301− where go l t = l + fromIntegral (T.length t)
302−{-# INLINE [1] length #-}
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
311-- | /O(1)/ Returns the last character of a 'Text', which must be
300-- | /O(1)/ Returns the last character of a 'Text', which must be
312-- non-empty. Subject to array fusion.
301-- non-empty. Subject to array fusion.
313last :: Text -> Char
302last :: Text -> Char
@@ -324,6 +313,37 @@ last (Chunk t ts) = go t ts
324 S.last (stream t) = last t
313 S.last (stream t) = last t
316+length :: Text -> Int64
317+length = foldlChunks go 0
318+ where go l t = l + fromIntegral (T.length t)
319+{-# INLINE [1] length #-}
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
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 #-}
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 #-}
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 #-}
327-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
347-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
328-- prefix of @t@ of length @n@, and whose second is the remainder of
348-- prefix of @t@ of length @n@, and whose second is the remainder of
329-- the string. It is equivalent to @('take' n t, 'drop' n t)@.
349-- the string. It is equivalent to @('take' n t, 'drop' n t)@.