This will exit after the first element that is out of order. It should thus perform well, but I haven’t tested that. It’s also a lot more elegant in my opinion. 🙂
def sorted(l:List[Int]) = l.view.zip(l.tail).forall(x => x._1 <= x._2)
This will exit after the first element that is out of order. It should thus perform well, but I haven’t tested that. It’s also a lot more elegant in my opinion. 🙂
def sorted(l:List[Int]) = l.view.zip(l.tail).forall(x => x._1 <= x._2)