Using DeleteCases
and Union
:
SetDifference[sets : {__ ? VectorQ}, opts___] := Module[{sdiff},
sdiff =
DeleteCases[First @ sets,
Apply[Alternatives, Union @@ Rest[sets]]];
Piecewise @ {
{sdiff, SameQ[opts, Null]},
{Union @ sdiff, SameQ[opts, "SortAndDistinct"]}
}
];
l1 = {b, e, d, a, b, c, d}; l2 = {b, c}; l3 = {a, f};
SetDifference[{l1, l2, l3}]
(*{e, d, d}*)
SetDifference[{l1, l2, l3}, "SortAndDistinct"]
(*{d, e}*)