1. Bryan O'Sullivan
  2. text

Commits

Bryan O'Sullivan  committed 1b88f4b

Simplify lazy takeEnd

  • Participants
  • Parent commits 6f2b209
  • Branches default

Comments (0)

Files changed (1)

File Data/Text/Lazy.hs

View file
  • Ignore whitespace
 takeEnd :: Int64 -> Text -> Text
 takeEnd n t0
     | n <= 0    = empty
-    | otherwise = fromChunks . L.reverse .
-                  takeChunk n . L.reverse . toChunks $ t0
-  where takeChunk _ [] = []
-        takeChunk i (t:ts)
-          | i <= l    = [T.takeEnd (fromIntegral i) t]
-          | otherwise = t : takeChunk (i-l) ts
+    | otherwise = takeChunk n empty . L.reverse . toChunks $ t0
+  where takeChunk _ acc [] = acc
+        takeChunk i acc (t:ts)
+          | i <= l    = chunk (T.takeEnd (fromIntegral i) t) acc
+          | otherwise = takeChunk (i-l) (Chunk t acc) ts
           where l = fromIntegral (T.length t)
 
 -- | /O(n)/ 'drop' @n@, applied to a 'Text', returns the suffix of the