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
Post a Comment