[Haskell-cafe] wordsBy in the base libraries?

Yitzchak Gale gale at sefer.org
Mon Oct 22 06:49:16 EDT 2007


How about this:

wordsBy :: (a -> Bool) -> [a] -> [[a]]
wordsBy p (x:xs)       = if p x then wordsBy p xs
                                else let (w, t) = getNextWord xs in (x:w) : t
  where
    getNextWord (x:xs) = if p x then ([], wordsBy p xs)
                                else let (w, t) = getNextWord xs in (x:w, t)
    getNextWord _      = ([], [])
wordsBy _ _            = []


(yuck)

-Yitz


More information about the Haskell-Cafe mailing list