Avoiding repitition of Exchange Items in table

Is there a smart way of grouping Exchange Items used in several outgoing and incoming functional exchanges allocated to a function?

Let’s say I have a function with 3 incoming and 3 outgoing exchanges, but in total, only 4 different exchange items are exchanged. I want to build a table that shows name and description of these exchange items but without duplication.
In regular coding I would use a for example a dictionary variable to collect and filter all exchange items associated with a function, but I don’t think M2Doc can do this, right?

Does anyone have another smart idea how to avoid duplication while looping?

To remove duplicates from a Sequence, you can convert it to an OrderedSet:


And you can also sort it to make the table easier to read:

mySequence->asOrderedSet()->sortedBy(e | e.name)

Thanks for the quick feedback! That sounds like it could go in the right direction… but how to I proceed if I have to “merge” two sequences? For example

for outgoing_exchange | func.outgoing
   for exchanged_item | outgoing_exchange.exchangedItems
      exchanged_item.name  # Table stuff

for incoming_exchange | func.incoming
   for exchanged_item | incoming_exchange.exchangedItems
      exchanged_item.name  # Table stuff

The challenge I see here is that the elements I want to filter are nested, so I do not have one sequence but multiple that I first have to merge and then filter by asOrderedSet().

Do you have another trick for that?

Found the trick myself, did not expect it to be that easy.

m:if SF1.outgoing->size() >0 or SF1.incoming->size() >0
m:for ex_item | (SF1.outgoing.oclAsType(capellacore::NamedElement).exchangedItems + SF1.incoming.oclAsType(capellacore::NamedElement).exchangedItems)->asOrderedSet()->sortedBy(e | e.name)

I compared it side-by-side, at least for my example, this code returns every exchange item only once, no matter how often it appears.

Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.