modelmda

How to sort collection in ObjectReef?


I was wondering is there any way to order collection of objects in ObjectReef? Usually, in other programming languages, there is something like standard library to perform sorting on sets.

ObjectReef doesn't have any standard library AFAIK.

Should I implement sorting manually or what?


Solution

  • You don't have to create your implementation of sort algorithms. In ObjectReef, you act declaratively and can use the orderedBy keyword on the collection you want to sort

    For example

    self.MyTasks.orderedBy('StartDate').forAll( ... )
    

    You can also sort by multiple fields, by specifying their names separated by semicolons

    self.MyTasks.orderedBy('StartDate;Duration;Index').forAll( ... )
    

    If you want reverse order, then use revForAll like

    self.MyTasks.orderedBy('StartDate').revForAll( ... )
    

    Detailed info about collection operators you can find in ObjectReef documentation.