@@ -115,6 +115,7 @@ module Data.Text.Lazy
115 -- ** Breaking into many substrings
115 -- ** Breaking into many substrings
117 , splitWith
117 , splitWith
118 -- , breakSubstring
119 -- , breakSubstring
120 -- ** Breaking into lines and words
121 -- ** Breaking into lines and words
@@ -775,6 +776,20 @@ splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
775 comb _ [] _ = impossibleError "splitWith"
776 comb _ [] _ = impossibleError "splitWith"
776{-# INLINE splitWith #-}
777{-# INLINE splitWith #-}
779+-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
780+-- element may be shorter than the other chunks, depending on the
781+-- length of the input. Examples:
783+-- > chunksOf 3 "foobarbaz" == ["foo","bar","baz"]
784+-- > chunksOf 4 "haskell.org" == ["hask","ell.","org"]
785+chunksOf :: Int64 -> Text -> [Text]
788+ go t = case splitAt k t of
789+ (a,b) | null a -> []
790+ | otherwise -> a : go b
791+{-# INLINE chunksOf #-}
778-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
793-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
779-- newline 'Char's. The resulting strings do not contain newlines.
794-- newline 'Char's. The resulting strings do not contain newlines.
780lines :: Text -> [Text]
795lines :: Text -> [Text]