OCLOperators asSet
Created by Alexandra on 2017-08-13 · Last edited by Colline.ssali on 2025-12-12.
asSet () : Set(T)
It is used to convert a value or collection into a Set, which is an unordered collection that contains no duplicate elements. This operator is especially useful when an expression requires a Set but the value you have is a single object, a Sequence, or a Bag. When applied to a single object, it wraps it into a Set containing just that element; when applied to a collection, it removes any duplicates and returns a clean Set.
Returns a Set containing all elements of self.
| Expression | Result |
|---|---|
| Sequence{1, 2.0, '3'}->asSet() | Set{1, '3', 2.0} |
| Sequence{1, 1, 2.0, '3'}->asSet() | Set{'3', 1, 2.0} |
| Bag{1, 2.0, '3'}->asSet() | Set{2.0, 1, '3'} |
| Bag{1, 1, 2.0, '3'}->asSet() | Set{1, '3', 2.0} |
| OrderedSet{1, 2.0, '3'}->asSet() | Set{1, '3', 2.0} |
| OrderedSet{1, 1, 2.0, '3'}->asSet() | Set{'3', 1, 2.0} |
| Set{1, 2.0, '3'}->asSet() | Set{2.0, 1, '3'} |
| Set{1, 1, 2.0, '3'}->asSet() | Set{'3', 1, 2.0} |
Example:
Department.allInstances.asSet()Results:
