on master help sign in
Simplify lazy takeEnd
commit260f3ab509315f7d9783704daea21bc376a2fd83 authorBryan O'Sullivan <bos@serpentine.com> dateFri 7 Mar 2014, 11:47 (13 years ago) parentb51087a
1 file changed+5−6
Data/Text/Lazy.hs+5−6
Data/Text/Lazy.hs+5−6
@@ -946,12 +946,11 @@ take i t0 = take' i t0
946946takeEnd :: Int64 -> Text -> Text
947947takeEnd n t0
948948 | n <= 0 = empty
949− | otherwise = fromChunks . L.reverse .
950− takeChunk n . L.reverse . toChunks $ t0
951− where takeChunk _ [] = []
952− takeChunk i (t:ts)
953− | i <= l = [T.takeEnd (fromIntegral i) t]
954− | otherwise = t : takeChunk (i-l) ts
949+ | otherwise = takeChunk n empty . L.reverse . toChunks $ t0
950+ where takeChunk _ acc [] = acc
951+ takeChunk i acc (t:ts)
952+ | i <= l = chunk (T.takeEnd (fromIntegral i) t) acc
953+ | otherwise = takeChunk (i-l) (Chunk t acc) ts
955954 where l = fromIntegral (T.length t)
956955
957956-- | /O(n)/ 'drop' @n@, applied to a 'Text', returns the suffix of the