I have a function (frequency) which that counts how many times each distinct value in a list occurs in that list. For example,
frequency "ababca"
should return:
[(3, 'a'), (2, 'b'), (1, 'c')].
This works fine but now I need to sort the list using the first element within the list of the list using this function.
results :: [Party ] -> [(Int, Party)]
results xs = ??? frequency (sort xs) ???
example of desired output:
[(1, "Green"), (2, "Red"), (3, "Blue")]
The above does not work, I have no idea what I can do.
using regular ‘sort’
Thank you in Advance.
Links to documentation for
on,sortBy,compare,fst.The difference is that
sortsorts in ascending order of the first element of each pair, breaking tie-breaks with the second elements of the pairs, whilesortBy (compare `on` fst)explicitly only looks at the first element of each pair.