[Haskell-cafe] Follow up on 'GroupBy behavior'

Henning Thielemann lemming at henning-thielemann.de
Mon May 21 06:17:19 EDT 2007


On Sat, 28 Apr 2007, Hans van Thiel wrote:

> Thanks again for the help, and, to follow up, this now does what I
> need..
>
> -- partitions a list according to an equivalence relation
>
> partition1 :: (a -> a -> Bool) -> [a] -> ([a],[a])
> partition1 eq ls = partition ((head ls) `eq`) ls
> --
> partitionBy :: (a -> a -> Bool) -> [a] -> [[a]]
> partitionBy eq [] = []
> partitionBy eq ls =
>     (fst x):(partitionBy eq (snd x))  where
>                              x =  partition1 eq ls

partitionBy is essentially a List.unfoldr



More information about the Haskell-Cafe mailing list