🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators collect
Created by Alexandra on 2017-08-13 · Last edited by Vale.buyondo on 2025-12-13.


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.