🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators reject
Created by Alexandra on 2017-08-13 · Last edited by Peter.byaruhanga on 2026-01-08.

reject ( expr : OclExpression ) : Collection(T)

Returns a collection with all elements of self except for those that validate the OclExpression expr.

Expression Result
Sequence{1, 2, 3}->reject(i : Integer | i > 1 ) Sequence{1}
Bag{1, 2, 3}->reject(i : Integer | i > 1 ) Bag{1}
OrderedSet{1, 2, 3}->reject(i : Integer | i > 1 ) OrderedSet{1}
Set{1, 2, 3}->reject(i : Integer | i > 1 ) Set{1}


Example

Bag{1, 2, 3}->reject(i | i < 2 )

This returns 2 and 3 because anything less than 2 is rejected.

OCL operators reject example.png