Eclipse Community Forums Forum Search:

Home » Modeling » OCL » Sorting a sequence of Integers(How to sort a sequence returned from a query)
Sorting a sequence of Integers Wed, 01 October 2014 09:22
 Anakreontas MentisMessages: 85Registered: October 2014 Member
I have a query that returns a sequence of Integers. I need to sort the result but don't know what expression could I pass to sortedBy function to achieve this. What I need is to provide an expression that points to elements of the Sequence. The 'self' keyword wan't do because it points to the context where the query is invoked.

Here is an example:
Sequence{7, 2, 10}->sortedBy(????) // should give Sequence{2, 7, 10}
Re: Sorting a sequence of Integers [message #1435439 is a reply to message #1435294] Wed, 01 October 2014 13:43
 Ed WillinkMessages: 6066Registered: July 2009 Senior Member
Hi

It's a slightly uncomfortable limitation of the sortedBy power that a
simple sort looks odd.

sortedBy(n | n)

is what you need. Specify the iterator variable and then return it as
the sort key.

Regards

On 01/10/2014 14:42, Anakreontas Mentis wrote:
> I have a query that returns a sequence of Integers. I need to sort the
> result but don't know what expression could I pass to sortedBy function
> to achieve this. What I need is to provide an expression that points to
> elements of the Sequence. The 'self' keyword wan't do because it points
> to the context where the query is invoked.
>
> Here is an example:
> Sequence{7, 2, 10}->sortedBy(????) // should give Sequence{2, 7, 10}
Re: Sorting a sequence of Integers [message #1435997 is a reply to message #1435439] Thu, 02 October 2014 08:31
 Anakreontas MentisMessages: 85Registered: October 2014 Member
Thank you.
 Previous Topic: Need help for OCL Syntax Next Topic: OCL GIT repository errors
Goto Forum:

Current Time: Wed Oct 17 04:10:34 GMT 2018