list - Haskell split tuple array where first elements are the same -


i have list in haskell of form similar to

[([], "str1"), ([], "str2"), ([1], "ser1")] 

and want split separate lists of 2-tuples, first elements of each tuple same, so

[([], "str1"), ([], "str2")] [([1], "ser1")] 

i''ve been eyeing data.list.split's splitwhen function, i've been having trouble getting ghc accept predicate it, since gather wasn't meant that.

i think can use groupby:

> import data.list > import data.function  > let xs = [([], "str1"), ([], "str2"), ([1], "ser1")]  > groupby ((==) `on` fst) xs  [[([],"str1"),([],"str2")], [([1],"ser1")]] 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -