
19 Nov
2009
19 Nov
'09
11:28 a.m.
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