haskell - Group Elements by Equality -


i'm looking standard library function groups elements equality.

example:

f [1,2,3,1,2,3] == [ [1,1], [2,2], [3,3] ]

composing group , sort job:

prelude data.list> group . sort $ [1,2,3,1,2,3] [[1,1],[2,2],[3,3]] 

but, there native function in haskell's library can perform above work in single function?

i looked @ data.list, did not find such function.

there no such function in base. there discrimination package. in data.discrimination find following function:

group :: grouping => [a] -> [[a]] 

you don't have write grouping instances yourself, there default methods in place types have instance generic. example:

{-# language derivegeneric #-} import data.discrimination  data = deriving generic instance grouping instance sorting -- not necessary trying do. 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -