Commits

Bryan O'Sullivan committed 393c70d

Fix definition of splitWith

  • Participants
  • Parent commits 184faa4

Comments (0)

Files changed (2)

File Data/Text.hs

 -- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
 -- > splitWith (=='a') []        == []
 splitWith :: (Char -> Bool) -> Text -> [Text]
-splitWith p = loop
-    where loop s | null s    = []
-                 | otherwise = if null s'
-                               then [s]
-                               else l : loop (unsafeTail s')
+splitWith _ (Text _off _arr 0) = []
+splitWith p t = loop t
+    where loop s | null s'   = [l]
+                 | otherwise = l : loop (unsafeTail s')
               where (l, s') = break p s
 {-# INLINE splitWith #-}
 

File tests/Properties.hs

 prop_T_splitWith p     = splitWith p `eqP` (map unpackT . T.splitWith p)
 prop_TL_splitWith p    = splitWith p `eqP` (map unpackT . TL.splitWith p)
 
-splitWith _ "" =  []
-splitWith p s  = if null s'
-                 then [s]
-                 else l : splitWith p (tail s')
-    where (l, s') = break p s
+splitWith :: (a -> Bool) -> [a] -> [[a]]
+splitWith _ [] =  []
+splitWith p xs = loop xs
+    where loop s | null s'   = [l]
+                 | otherwise = l : loop (tail s')
+              where (l, s') = break p s
 
 prop_T_breakSubstring_isInfixOf s l
                      = T.isInfixOf s l ==