[Haskell-cafe] Behavior of groupBy

Neil Mitchell ndmitchell at gmail.com
Sat Apr 28 10:08:24 EDT 2007

Hi Hans,

> > The standard function groupBy of List.hs doesn't work as I expect in
> > this case:
> >
> > groupBy (\x y -> (last x) == (last y)) ["abc", "bd","cac"]
> You are doing something wrong.  groupBy is specified to never reorder
> elements.  You probably want to use sortBy first.

I have a defined groupSetBy which does groupBy working as though the
list was in fact a set (which is often what it really is). Its a
common thing to want - perhaps it should be a library function.



More information about the Haskell-Cafe mailing list