@@ -1,17 +1,155 @@
11{-# OPTIONS_GHC -fno-warn-orphans #-}
2+-- |
3+-- Module : Data.Text.Lazy
4+-- Copyright : (c) Bryan O'Sullivan 2009,
5+-- (c) Tom Harper 2008-2009,
6+-- (c) Duncan Coutts 2008
7+--
8+-- License : BSD-style
9+-- Maintainer : rtharper@aftereternity.co.uk, bos@serpentine.com,
10+-- duncan@haskell.org
11+-- Stability : experimental
12+-- Portability : GHC
13+--
14+-- A time and space-efficient implementation of Unicode text using
15+-- lists of packed arrays. This representation is suitable for high
16+-- performance use and for streaming large quantities of data. It
17+-- provides a means to manipulate a large body of text without
18+-- requiring that the entire content be resident in memory.
19+--
20+-- Some operations, such as 'concat', 'append', 'reverse' and 'cons',
21+-- have better complexity than their "Data.Text" equivalents, due to
22+-- optimisations resulting from the list spine structure. And for
23+-- other operations lazy 'Text's are usually within a few percent of
24+-- strict ones, but with better heap usage. For data larger than
25+-- available memory, or if you have tight memory constraints, this
26+-- module will be the only option.
27+--
28+-- This module is intended to be imported @qualified@, to avoid name
29+-- clashes with "Prelude" functions. eg.
30+--
31+-- > import qualified Data.Text.Lazy as B
232
333module Data.Text.Lazy
434 (
535 Text
36+ -- * Creation and elimination
637 , pack
738 , unpack
39+ , singleton
40+ , empty
41+
842 -- * Basic interface
43+ -- , cons
44+ -- , snoc
945 , append
46+ -- , uncons
47+ -- , head
48+ -- , last
49+ -- , tail
50+ -- , init
51+ -- , null
52+ -- , length
53+
54+ -- * Transformations
55+ -- , map
56+ -- , intercalate
57+ -- , intersperse
58+ -- , transpose
59+ -- , reverse
60+
61+ -- * Folds
62+ -- , foldl
63+ -- , foldl'
64+ -- , foldl1
65+ -- , foldl1'
66+ -- , foldr
67+ -- , foldr1
68+
69+ -- ** Special folds
70+ -- , concat
71+ -- , concatMap
72+ -- , any
73+ -- , all
74+ -- , maximum
75+ -- , minimum
76+
77+ -- * Construction
78+
79+ -- ** Scans
80+ -- , scanl
81+ -- , scanl1
82+ -- , scanr
83+ -- , scanr1
84+
85+ -- ** Accumulating maps
86+ -- , mapAccumL
87+ -- , mapAccumR
88+
89+ -- ** Generation and unfolding
90+ -- , replicate
91+ -- , unfoldr
92+ -- , unfoldrN
93+
94+ -- * Substrings
95+
96+ -- ** Breaking strings
97+ -- , take
98+ -- , drop
99+ -- , takeWhile
100+ -- , dropWhile
101+ -- , splitAt
102+ -- , span
103+ -- , break
104+ -- , group
105+ -- , groupBy
106+ -- , inits
107+ -- , tails
108+
109+ -- ** Breaking into many substrings
110+ -- , split
111+ -- , splitWith
112+ -- , breakSubstring
113+
114+ -- ** Breaking into lines and words
115+ -- , lines
116+ --, lines'
117+ -- , words
118+ -- , unlines
119+ -- , unwords
120+
121+ -- * Predicates
122+ -- , isPrefixOf
123+ -- , isSuffixOf
124+ -- , isInfixOf
125+
126+ -- * Searching
127+ -- , elem
128+ -- , filter
129+ -- , find
130+ -- , partition
131+
132+ -- , findSubstring
133+
134+ -- * Indexing
135+ -- , index
136+ -- , findIndex
137+ -- , findIndices
138+ -- , elemIndex
139+ -- , elemIndices
140+ -- , count
141+
142+ -- * Zipping and unzipping
143+ -- , zipWith
144+
145+ -- -* Ordered text
146+ -- , sort
10147 ) where
11148
12149import Data.String (IsString(..))
150+import qualified Data.Text as T
13151import qualified Data.Text.Fusion as S
14−import Data.Text.Fusion.Internal as S
152+import qualified Data.Text.Fusion.Internal as S
15153import Data.Text.Lazy.Fusion
16154import Data.Text.Lazy.Internal
17155
@@ -37,9 +175,20 @@ pack = unstream . S.streamList
37175-- | /O(n)/ Convert a 'Text' into a 'String'.
38176-- Subject to array fusion.
39177unpack :: Text -> String
40−unpack = unstreamList . stream
178+unpack = S.unstreamList . stream
41179{-# INLINE [1] unpack #-}
42180
181+singleton :: Char -> Text
182+singleton c = Chunk (T.singleton c) Empty
183+{-# INLINE [1] singleton #-}
184+
185+{-# RULES
186+"TEXT singleton -> fused" [~1] forall c.
187+ singleton c = unstream (S.singleton c)
188+"TEXT singleton -> unfused" [1] forall c.
189+ unstream (S.singleton c) = singleton c
190+ #-}
191+
43192-- | /O(n\/c)/ Append two 'Text's
44193append :: Text -> Text -> Text
45194append xs ys = foldrChunks Chunk ys xs