
On 22/03/14 18:29, martin wrote:
Am 03/22/2014 06:40 PM, schrieb Kim-Ee Yeoh:
On Sat, Mar 22, 2014 at 11:51 PM, martin
mailto:martin.drautzburg@web.de> wrote: How can I groupBy a List whose elements are only instances of Eq but not of Ord?
If you take a look at the code for groupBy:
groupBy :: (a -> a -> Bool) -> [a] -> [[a]] groupBy _ [] = [] groupBy eq (x:xs) = (x:ys) : groupBy eq zs
Cool!
I have a database background and the SQL "group by" does of course not assume any ordering. So I often wonder, where you would use Haskell's groupBy WITHOUT sorting first, but I assume there are situations, where this is useful.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
One example that comes to mind is filtering consecutive-same elements: | Prelude Data.List> map head $ group "hello world!!!" | "helo world!" -- Mateusz K.