🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
OCLOperators excluding

excluding ( object : T ) : Collection(T)

Returns a collection containing all elements of self minus all occurrences of object.

Note: At the time of writing, the OCL standard library sports a bug that changes *OrderedSets* in *Sets* when excluding elements.

Expression Result
Sequence{'b', 'a', 'b', 'c'}->excluding('b') Sequence{'a', 'c'}
Bag{'b', 'a', 'b', 'c'}->excluding('b') Bag{'c', 'a'}
OrderedSet{'b', 'a', 'b', 'c'}->excluding('b') Set{'c', 'a'}
Set{'b', 'a', 'b', 'c'}->excluding('b') Set{'c', 'a'}

The opposite—to add an object to a collection—is Append.

Video: OCL Operators: excluding