[Haskell-cafe] Re: Data.List.Split
matti.niemenmaa+news at iki.fi
Sun Dec 14 12:39:03 EST 2008
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)
More information about the Haskell-Cafe