Proposal (Trac ticket #3671): Add takeRec, genericTakeRec and
spanRec to Data.List
Yitzchak Gale
gale at sefer.org
Thu Nov 19 07:24:23 EST 2009
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
More information about the Libraries
mailing list