Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Sorting a sequence of Integers(How to sort a sequence returned from a query)
Sorting a sequence of Integers [message #1435294] Wed, 01 October 2014 09:22 Go to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: 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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5968
Registered: 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

Ed Willink


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 Go to previous message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Thank you.
Previous Topic:Need help for OCL Syntax
Next Topic:OCL GIT repository errors
Goto Forum:
  


Current Time: Mon Jul 16 12:37:35 GMT 2018

Powered by FUDForum. Page generated in 0.06185 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top