Proposal (Trac ticket #3671): Add takeRec, genericTakeRec and spanRec to Data.List

Yitzchak Gale gale at sefer.org
Thu Nov 19 06:28:12 EST 2009


Philip K.F. wrote:
> runs :: (a -> a -> Bool) -> [a] -> [[a]]
> runs p xs = ...
>
> which produces a list of runs, i.e. the first result is that prefix of
> xs, such that for all consecutive elements e_i, e_{i+1}, the property
> holds, i.e. p e_i e_{i+1} -->> True.

We already have something like that:

groupBy :: (a -> a -> Bool) -> [a] -> [[a]]

In fact, instead of spans and breaks, why not just use:

runs :: (a -> Bool) -> [a] -> [[a]]
runs = groupBy . on (==)

Then we have:

breaks p = runs p . dropWhile p
spans p = runs p . dropWhile (not . p)

Regards,
Yitz


More information about the Libraries mailing list