[Haskell-cafe] Generalized version of `words'?
dimitry at golubovsky.org
Sat Jun 11 14:34:56 EDT 2005
Does there exist a generalized version of the `words' function i. e.
one that breaks an arbitrary list into parts by an arbitrary predicate?
splitAt is not what I need.
I had to write my own:
-- A version of words, but works with any lists on any predicate.
parts pred s = case dropWhile pred s of
 -> 
s' -> w : parts pred s''
where (w, s'') = break pred s'
(just by parameterizing `words' found in Data.List with a predicate
passed as a parameter).
In case such a function already exists, what is its name?
In the opposite case, can such a function be added to the standard
library? (or why didn't it exist?)
More information about the Haskell-Cafe