
19 Nov
2009
19 Nov
'09
12:24 p.m.
Ian Lynagh wrote:
breaks (',' ==) "123,456,,78" == ["123", "456", "", "78"]
I wrote:
runs = groupBy . on (==) breaks p = filter (not . p . head) . runs p
Except that has slightly different semantics than Ian's: breaks (',' ==) "123,456,,78" == ["123","456","78"]
A combinator approach to Ian's semantics: spans p = map (takeWhile p) . takeWhile (not . null) . iterate (drop 1 . dropWhile p) breaks p = spans $ not . p Here you have to put the "not null" step in the middle. I wonder if that interferes with the fusion. -Yitz