I was wondering what is the most elegant way of getting the increasing prefix of a given sequence. My idea is as follows, but it is not purely functional or any elegant:
And, another way to skin the cat:
val sequence = Seq(1,2,3,1,2,3,4,5,6) sequence.head :: sequence .sliding(2) .takeWhile{case List(a,b) => a <= b} .map(_(1)).toList // List[Int] = List(1, 2, 3)