on master help sign in
Define and export toLazyTextWith.

--HG-- extra : convert_revision : 24c2e55b447633e914f5429b73df1215751567ff

commit05b647594ecae08ac53d3f805e8fdff303ef7111 authorBryan O'Sullivan <bos@serpentine.com> dateSun 2 May 2010, 17:24 (16 years ago) parent2516cc0
1 file changed+15−7
Data/Text/Lazy/Builder.hs+15−7
Data/Text/Lazy/Builder.hs+15−7
@@ -18,6 +18,7 @@ module Data.Text.Lazy.Builder
1818 ( -- * The Builder type
1919 Builder
2020 , toLazyText
21+ , toLazyTextWith
2122
2223 -- * Constructing Builders
2324 , singleton
@@ -134,14 +135,21 @@ data Buffer s = Buffer {-# UNPACK #-} !(A.MArray s Word16)
134135
135136------------------------------------------------------------------------
136137
137−-- | /O(n)./ Extract a lazy 'L.T' from a 'Builder'. The construction
138−-- work takes place if and when the relevant part of the lazy 'L.T' is
139−-- demanded.
140−--
138+-- | /O(n)./ Extract a lazy 'L.Text' from a 'Builder' with a default
139+-- buffer size. The construction work takes place if and when the
140+-- relevant part of the lazy 'L.Text' is demanded.
141141toLazyText :: Builder -> L.Text
142−toLazyText m = L.fromChunks $ runST $ do
143− buf <- newBuffer defaultChunkSize
144− runBuilder (m `append` flush) (const (return [])) buf
142+toLazyText = toLazyTextWith defaultChunkSize
143+
144+-- | /O(n)./ Extract a lazy 'L.Text' from a 'Builder', using the given
145+-- size for the initial buffer. The construction work takes place if
146+-- and when the relevant part of the lazy 'L.Text' is demanded.
147+--
148+-- If the initial buffer is too small to hold all data, subsequent
149+-- buffers will be the default buffer size.
150+toLazyTextWith :: Int -> Builder -> L.Text
151+toLazyTextWith chunkSize m = L.fromChunks . runST $
152+ newBuffer chunkSize >>= runBuilder (m `append` flush) (const (return []))
145153
146154-- | /O(1)./ Pop the 'S.Text' we have constructed so far, if any,
147155-- yielding a new chunk in the result lazy 'L.Text'.