[Haskell-cafe] Behavior of groupBy
Hans van Thiel
hthiel.char at zonnet.nl
Sat Apr 28 10:36:38 EDT 2007
On Sat, 2007-04-28 at 15:08 +0100, Neil Mitchell wrote:
> 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.
And thanks again. I'll roll my own then..
More information about the Haskell-Cafe