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


The collect operator iterates over a collection and returns a new collection containing the results of applying an expression to each element.

Unlike foreach, collect is a pure OCL operator and does not modify state.

Syntax

collection->collect(item | expression)

Execution Context

ViewModels, Constraints, Debugger → Evaluate Expression, Debugger → Execute Action

collect is not an EAL operator. Examples

Customer.allInstances->collect(c | c.Name)

Returns a list of customer names.

Collect derived values

Customer.allInstances->collect(c | c.Age + 1)

Returns a list where each element is the customer’s age plus one.