So, I want to use nubBy to remove all duplicates from a list of lists. In this case [1,2,3]==[1,3,2]==[2,3,1] etc, so I’m figuring I need to use all and elem to ask if all the elements are elements of another list, but I’m struggling to work out the syntax.
To be clear, I have for example
[[1,2],[2,3],[4,5],[2,1],[2,3]]
and I want to remove duplicates to get the output
[[1,2],[2,3],[4,5]]
If you don’t care that the order of the elements in the inner lists of the result match one of the original ones, you can just use
map sortto sort them before usingnub. Otherwise,nubBy ((==) `on` sort)will do the job at the extra cost of sorting the inner lists for each comparison.