7

I'm trying to get the "opposite" of intersect of two list: like:

let all  = [1..5]
let mask = [2,3]
let res  = ???
-- let res = all `intersect` mask <-- reverse/opposite ?
-- I want to get [1,4,5] ?
user914584
  • 571
  • 8
  • 15

1 Answers1

19

You're looking for set difference, which is the \\ operator from Data.List:

Prelude> import Data.List ((\\))
Prelude Data.List> let all  = [1..5]
Prelude Data.List> let mask = [2,3]
Prelude Data.List> all \\ mask
[1,4,5]
Thomas
  • 174,939
  • 50
  • 355
  • 478
  • 3
    @user914584 But be aware that `(\\)` removes only one element from the first list per element of the second, e.g. `[1,2,3,2] \\ [2] = [1,3,2]`. If that's not good for your use case, ``filter (`notElem` second) first`` is an alternative. – Daniel Fischer Dec 20 '12 at 13:30