@@ -115,6 +115,7 @@ module Data.Text.Lazy
115115 -- ** Breaking into many substrings
116116 , split
117117 , splitWith
118+ , chunksOf
118119 -- , breakSubstring
119120
120121 -- ** Breaking into lines and words
@@ -775,6 +776,20 @@ splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
775776 comb _ [] _ = impossibleError "splitWith"
776777{-# INLINE splitWith #-}
777778
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:
782+--
783+-- > chunksOf 3 "foobarbaz" == ["foo","bar","baz"]
784+-- > chunksOf 4 "haskell.org" == ["hask","ell.","org"]
785+chunksOf :: Int64 -> Text -> [Text]
786+chunksOf k = go
787+ where
788+ go t = case splitAt k t of
789+ (a,b) | null a -> []
790+ | otherwise -> a : go b
791+{-# INLINE chunksOf #-}
792+
778793-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
779794-- newline 'Char's. The resulting strings do not contain newlines.
780795lines :: Text -> [Text]