OCLOperators select
Created by Alexandra on 2017-08-13 · Last edited by Vale.buyondo on 2026-02-10.
The select operator filters a source collection, returning a new collection of the same type containing only the elements that satisfy a specific condition.
Syntax
sourceCollection->select(iterator | condition)
- sourceCollection: The initial Set, Bag, or Sequence.
- iterator: A variable representing each element during the evaluation.
- condition: A boolean OclExpression. If
true, the element is included in the result.
| Expression | Result |
|---|---|
| Sequence{1, 2, 3}->select(i| i > 1) | Sequence{2, 3} |
| Bag{1, 2, 3}->select(i| i > 1 ) | Bag{3, 2} |
| Set{1, 2, 3}->select(i| i > 1 ) | Set{3, 2} |
| Customer.allInstances->select(a | a.Name.SqlLike('%Alex%')) | A collection of Customers whose name contains "Alex". |
