I run the following code snippet:
val it = List(1,1,1,2,2,3,3).iterator.buffered val compare = it.head it.takeWhile(_ == compare).toList
and it returns (1,1,1). However, if I ran this as:
val it = List(1,1,1,2,2,3,3).iterator.buffered it.takeWhile(_ == it.head).toList
I get (1,1). Why is this so? Is head evaluated when takeWhile called, and should the result be the same?
source share