
Jón Fairbairn
spans p = unfoldr (fmap (id >< dropWhile (not . p)) . spanMb p) (f >< g) (a,b) = (f a, g b)
We can write “groupBy (\a b -> p a && p b)” for another of the design cases, though I think some discussion of groupBy belongs in here: why does it require an equivalence relation? Shouldn't we at least have a version that works for any binary predicate?
I just noticed that Ross Paterson said much the same thing on Haskell Café this morning. And that I stopped before I'd indicated why runsBy is useful here...
runsBy = unfoldr . splitRun [...]
... so we get runsBy (const (/=',')) ",foo,,bar,baz" ==> [",foo",",",",bar",",baz"] and
spans p = map (dropWhile (not . p)) . runsBy (const p)
-- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk