Tech News World, Contacts Samsung Galaxy, Windows 8, Nokia Lumia, Quad Core Smart Phones, HTC smartphone, Google Nexus, MacBook, PayPal

Friday, July 25, 2014

Difference between sorted, sortWith and sortBy in Scala

Difference between sorted, sortWith and sortBy in Scala - Although I work in the office and a lot of work that makes me tired but still I make a blog Tech News World and still will update it for you because this is part of my hobby who likes the world of technology, especially about the gadget, now we will discuss first about Difference between sorted, sortWith and sortBy in Scala because it is the topic that you are now looking for, please refer to the information I provide in the guarantee for you,

Articles : Difference between sorted, sortWith and sortBy in Scala
full Link : Difference between sorted, sortWith and sortBy in Scala

You can also see our article on:


Difference between sorted, sortWith and sortBy in Scala

Scala collections provide you three options for sorting: sorted( ), sortWith( ) and sortBy( ). Here is a simplified explanation:

sorted
Will sort the list using the natural ordering (based on the implicit Ordering passed)

sortBy (an attribute)
Sort by a given attribute using the attribute's type.
e.g. given a list of Person objects, if you want to sort them in ascending order of their age (which is an Int), you could simply say: personList.sortBy(_.age)

sortWith (a function)
Takes a comparator function. Useful when you want to specify a custom sorting logic. 
e.g. if you want to sort by age descending, you could write this as: 

personList.sortWith{(leftE,rightE) => 
     leftE.age > rightE.age
}

Or, more simply: personList.sortWith(_.age > _.age)

Checkout this gist for a full example: 
https://gist.github.com/gsluthra/80555ed4af24bea244b5





so much information about Difference between sorted, sortWith and sortBy in Scala

hopefully information Difference between sorted, sortWith and sortBy in Scala can provide useful knowledge for you in getting information about the latest gadgets,

just finished your reading article about Difference between sorted, sortWith and sortBy in Scala if you feel this article useful for you please bookmark or share using link http://aziin5teens.blogspot.com/2014/07/difference-between-sorted-sortwith-and.html for more people know

Tag :
Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : Difference between sorted, sortWith and sortBy in Scala

0 comments:

Post a Comment