[GHC] #971: Add intercalate and split to Data.List

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Mon Oct 30 14:45:49 EST 2006


Jón Fairbairn <jon.fairbairn at cl.cam.ac.uk> writes:

> > 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 at cl.cam.ac.uk




More information about the Libraries mailing list