
14 Dec
2008
14 Dec
'08
12:39 p.m.
Adam Vogt wrote:
* On Saturday, December 13 2008, Gianfranco Alongi wrote:
I have actually been thinking about a similar thing, but on the "group" subject. One can actually group things in many ways, such as groupBy (==) , so that groupBy (==) [1,2,1,2] should give [[1,1],[2,2]]. Of course other ideas are possible.
That result happens with:
sortedGroups = group . sort
That composition is pretty, unlike those splitting functions. I don't know if manually fusing sort and group helps performance at all though.
Sorting requires an Ord instance, though. Here's a relatively simple but slow way which doesn't: fullGroupBy :: (a -> a -> Bool) -> [a] -> [[a]] fullGroupBy rel xs = map (\a -> filter (rel a) xs) (nubBy rel xs)