This is big news! Now OCL has a closure operation (thanks to Martin for alerting me ). This means that now in OCL you could write something like parents->closure(children) to compute the set of parents.children, parents.children.children, parents.children.children.children etc.

I’ve been missing this feature for a long time since I found similar situations very often and I was tired of specifying recursive OCL operations to simulate the closure myself.

From the OCL standard 2.3 Beta 2 :  Closure operation uses the same syntax as the select and reject iterators and is written as one of

  • source>closure( v : Type | expression-with-v )
  • source>closure( v | expression-with-v )
  • source>closure( expression )

The returned collection of the closure iteration is an accumulation of the source, and the collections resulting from the recursive invocation of expression-with-v in which v is associated exactly once with each distinct element of the returned collection. The iteration terminates when expression-with-v returns empty collections or collections containing only already accumulated elements. The collection type of the result collection is the unique form (Set or OrderedSet) of the original source collection. If the source collection is ordered, the result is in depth first preorder.

So, what’s your opinion? Are you happy with this new feature? Were you missing it?

Want to build better software faster?

Want to build better software faster?

Read about the latest trends on software modeling and low-code development

You have Successfully Subscribed!

Pin It on Pinterest

Share This