From 37aa4a078457f7e5c4b7ec839468a3a37389cc60 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Mon, 24 Aug 2020 18:02:26 -0600 Subject: [PATCH] Add Data.Text.Lazy.Builder.toText --- src/Data/Text/Internal/Builder.hs | 5 +++++ src/Data/Text/Lazy/Builder.hs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/Data/Text/Internal/Builder.hs b/src/Data/Text/Internal/Builder.hs index 66858251..fd6aa51b 100644 --- a/src/Data/Text/Internal/Builder.hs +++ b/src/Data/Text/Internal/Builder.hs @@ -41,6 +41,7 @@ module Data.Text.Internal.Builder Builder , toLazyText , toLazyTextWith + , toText -- ** Constructing Builders , singleton @@ -231,6 +232,10 @@ toLazyTextWith :: Int -> Builder -> L.Text toLazyTextWith chunkSize m = L.fromChunks (runST $ newBuffer chunkSize >>= runBuilder (m `append` flush) (const (return []))) +-- | /O(n)./ Extract a strict @Text@ from a @Builder@. +toText :: Builder -> Text +toText = L.toStrict . toLazyText + -- | /O(1)./ Pop the strict @Text@ we have constructed so far, if any, -- yielding a new chunk in the result lazy @Text@. flush :: Builder diff --git a/src/Data/Text/Lazy/Builder.hs b/src/Data/Text/Lazy/Builder.hs index 6c4c24ad..3e04b9d2 100644 --- a/src/Data/Text/Lazy/Builder.hs +++ b/src/Data/Text/Lazy/Builder.hs @@ -43,6 +43,7 @@ module Data.Text.Lazy.Builder Builder , toLazyText , toLazyTextWith + , toText -- * Constructing Builders , singleton