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)

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to