Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala error: value sort is not a member of List

Following a simple example at http://www.simplyscala.com/ I get:

scala> val lst=List(1,7,2,8,5,6,3,9,14,12,4,10)
lst: List[Int] = List(1, 7, 2, 8, 5, 6, 3, 9, 14, 12, 4, 10)

scala> lst.sort(_>_)
<console>:9: error: value sort is not a member of List[Int]
      lst.sort(_>_)

What is wrong? Thanks!

like image 481
Anton Ashanin Avatar asked Mar 21 '13 11:03

Anton Ashanin


2 Answers

SimplyScala wasn't updated for a long long time: .sort was deprecated in 2.8.0 and cut out in latter versions. Instead you have to use sortWith method.

like image 89
om-nom-nom Avatar answered Oct 29 '22 21:10

om-nom-nom


sortis actually not defined in class List. You should use sortWith in your case.

like image 2
Nicolas Avatar answered Oct 29 '22 22:10

Nicolas