Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List (unfoldr)
- -- *Main> split ',' ",,,abc,bd,,ce,,,"
- -- ["abc","bd","ce"]
- genericSplit :: (a -> Bool) -> [a] -> [[a]]
- genericSplit p xs = unfoldr (splitOne p) xs
- where
- splitOne _ [] = Nothing
- splitOne p (x:xs) | p x = splitOne p xs
- splitOne p xs = Just (before, after)
- where (before, afterIncluding) = span (not.p) xs
- after = dropWhile p afterIncluding
- split s xs = genericSplit (==s) xs
Add Comment
Please, Sign In to add comment