on master help sign in
Fix definition of splitWith
9fecd2aBryan O'Sullivan
Data/Text.hs+4−5
@@ -741,11 +741,10 @@ split c = splitWith (==c)
741-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
741-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
742-- > splitWith (=='a') [] == []
742-- > splitWith (=='a') [] == []
743splitWith :: (Char -> Bool) -> Text -> [Text]
743splitWith :: (Char -> Bool) -> Text -> [Text]
744−splitWith p = loop
744+splitWith _ (Text _off _arr 0) = []
745+splitWith p t = loop t
745− where loop s | null s = []
746+ where loop s | null s' = [l]
746− | otherwise = if null s'
747− then [s]
748− else l : loop (unsafeTail s')
747+ | otherwise = l : loop (unsafeTail s')
749 where (l, s') = break p s
748 where (l, s') = break p s
750{-# INLINE splitWith #-}
749{-# INLINE splitWith #-}
751
750
tests/Properties.hs+6−5
@@ -257,11 +257,12 @@ prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
257prop_T_splitWith p = splitWith p `eqP` (map unpackT . T.splitWith p)
257prop_T_splitWith p = splitWith p `eqP` (map unpackT . T.splitWith p)
258prop_TL_splitWith p = splitWith p `eqP` (map unpackT . TL.splitWith p)
258prop_TL_splitWith p = splitWith p `eqP` (map unpackT . TL.splitWith p)
259
259
260−splitWith _ "" = []
260+splitWith :: (a -> Bool) -> [a] -> [[a]]
261+splitWith _ [] = []
261−splitWith p s = if null s'
262+splitWith p xs = loop xs
262− then [s]
263+ where loop s | null s' = [l]
263− else l : splitWith p (tail s')
264+ | otherwise = l : loop (tail s')
264− where (l, s') = break p s
265+ where (l, s') = break p s
265
266
266prop_T_breakSubstring_isInfixOf s l
267prop_T_breakSubstring_isInfixOf s l
267 = T.isInfixOf s l ==
268 = T.isInfixOf s l ==