Idiomatic construction to check whether a collection is ordered

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)

Leave a Comment

tech