<div dir="ltr"><div>Hi,</div><div><br></div>For a small problem, I was looking for a groupBy like function that groups based on a predicate on successive elements but I could not find one. I wrote these little functions for that purpose:<div><br></div><div><div>-- | Like span, but with a predicate that compares two successive elements. The</div><div>-- span ends when the two successive elements do not satisfy the predicate.</div><div>rollingSpan :: (a -> a -> Bool) -> [a] -> ([a], [a])</div><div>rollingSpan _ xs@[] = (xs, xs)</div><div>rollingSpan _ xs@[_] = (xs, [])</div><div>rollingSpan p (x1:xs@(x2:_))</div><div>    | p x1 x2 =</div><div>        let (ys, zs) = rollingSpan p xs</div><div>        in (x1 : ys, zs)</div><div>    | otherwise = ([x1], xs)</div><div><br></div><div>-- | Like 'groupBy' but with a predicate that compares two successive elements.</div><div>-- A group ends when two successive elements do not satisfy the predicate.</div><div>rollingGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]</div><div>rollingGroupBy _ [] = []</div><div>rollingGroupBy cmp xs =</div><div>    let (ys, zs) = rollingSpan cmp xs</div><div>    in ys : rollingGroupBy cmp zs</div></div><div><br></div><div>Are there any existing functions that serve this purpose or is there any simpler way to achieve such functionality? If not, where is the right place for these, if any. Can they be included in Data.List in base?</div><div><br></div><div>Thanks,</div><div>Harendra</div></div>