Tech News Today, Marshmallow Custom Rom, Huawei, Run Programs, Network, Chromebook, Bank Account

Jumat, 25 Juli 2014

Difference between sorted, sortWith and sortBy in Scala

Difference between sorted, sortWith and sortBy in Scala - To all visitors of this blog, I say welcome and thank you for visiting the blog Tech News Today Look for all the things you need that are available on this blog. If not available, please leave suggestions and comments for the development of this blog. now we will discuss first about Difference between sorted, sortWith and sortBy in Scala we have collected a lot of information from sources to create this article, so please see.

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





information Difference between sorted, sortWith and sortBy in Scala has been completed in the discussion.

hopefully the article we give the title Difference between sorted, sortWith and sortBy in Scala can provide knowledge for you in living everyday life in determining the gadget that suits your needs.

you just read the article about Difference between sorted, sortWith and sortBy in Scala if this article is useful for you and want to bookmark it or share it please use the link https://sihanandi.blogspot.com/2014/07/difference-between-sorted-sortwith-and.html thank you and do not forget to comment if anyone.

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

Related : Difference between sorted, sortWith and sortBy in Scala

0 komentar:

Posting Komentar