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

Purpose Checks whether any element in a collection satisfies a given condition.

Returns true if at least one element matches; otherwise, returns false.

Syntax

Collection->exists(variable | condition)


Collection a list, set, or other enumerable collection.

variable a placeholder name for each element in the collection.

condition a Boolean expression against which each element is tested.

Example

Customer.allInstances()->exists(o | o.name = 'John')

Checks if any Customer in the system has name = 'John'.

Returns true if at least one customer named John exists.

Expression Result
Sequence{2.3, 5.2}->exists(self > 3) true


This is the reverse of ->forAll.