Imagine a nested list as below.
["A","ABBA","ABABA"]
I would like to create a function which removes singleton elements from this list (in this example, "A"), and removes any lists containing that singleton element.
So that:
removeElems ["A","ABBA","CCC"] -> ["CCC"]
Below is my attempt at solving this problem:
badElements nested = concat $ filter (\c -> length c == 1) nested
removeElements nested = [c | c <- nested, u <- badElements nested, not $ any (==u) c]
This produces strange results where the multiple generators 'cycle' the nested list, such as below:
["A","ABBA","C","BCCB"] --> ["A","A","ABBA","ABBA","C","C","BCCB","BCCB"]--> ["A","ABBA","C","BCCB"]
Another example:
[[1],[1,2,3,4],[2],[5,6,7,8]] --> [5,6,7,8]
not $ any (== u)is better written asall (/= u).notElem u, which is defined just like you wrote it,notElem x = all (/= x)source