on master help sign in
Fix definition of splitWith

--HG-- extra : convert_revision : 21f23e60d1b6421541af8210e9a42dffa21f0268

commit9fecd2af8a4e07133d14f08d0d5404e1166b98f4 authorBryan O'Sullivan <bos@serpentine.com> dateFri 6 Mar 2009, 07:11 (18 years ago) parent445a34f
2 files changed+10−10
Data/Text.hs+4−5 tests/Properties.hs+6−5
Data/Text.hs+4−5
@@ -741,11 +741,10 @@ split c = splitWith (==c)
741741-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
742742-- > splitWith (=='a') [] == []
743743splitWith :: (Char -> Bool) -> Text -> [Text]
744−splitWith p = loop
745− where loop s | null s = []
746− | otherwise = if null s'
747− then [s]
748− else l : loop (unsafeTail s')
744+splitWith _ (Text _off _arr 0) = []
745+splitWith p t = loop t
746+ where loop s | null s' = [l]
747+ | otherwise = l : loop (unsafeTail s')
749748 where (l, s') = break p s
750749{-# INLINE splitWith #-}
751750
tests/Properties.hs+6−5
@@ -257,11 +257,12 @@ prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
257257prop_T_splitWith p = splitWith p `eqP` (map unpackT . T.splitWith p)
258258prop_TL_splitWith p = splitWith p `eqP` (map unpackT . TL.splitWith p)
259259
260−splitWith _ "" = []
261−splitWith p s = if null s'
262− then [s]
263− else l : splitWith p (tail s')
264− where (l, s') = break p s
260+splitWith :: (a -> Bool) -> [a] -> [[a]]
261+splitWith _ [] = []
262+splitWith p xs = loop xs
263+ where loop s | null s' = [l]
264+ | otherwise = l : loop (tail s')
265+ where (l, s') = break p s
265266
266267prop_T_breakSubstring_isInfixOf s l
267268 = T.isInfixOf s l ==