Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell opposite of intersect (List)

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] ?
like image 305
user914584 Avatar asked Dec 20 '12 07:12

user914584


1 Answers

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]
like image 105
Thomas Avatar answered Sep 19 '22 13:09

Thomas