Guest User

Untitled

a guest
Jul 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import Data.List (unfoldr)
  2.  
  3. -- *Main> split ',' ",,,abc,bd,,ce,,,"
  4. -- ["abc","bd","ce"]
  5.  
  6. genericSplit :: (a -> Bool) -> [a] -> [[a]]
  7. genericSplit p xs = unfoldr (splitOne p) xs
  8. where
  9. splitOne _ [] = Nothing
  10. splitOne p (x:xs) | p x = splitOne p xs
  11. splitOne p xs = Just (before, after)
  12. where (before, afterIncluding) = span (not.p) xs
  13. after = dropWhile p afterIncluding
  14.  
  15. split s xs = genericSplit (==s) xs
Add Comment
Please, Sign In to add comment