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] ?
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] ?
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]
(\\)
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. –
Pearman © 2022 - 2024 — McMap. All rights reserved.