An assignment expression has type Unit
in Scala. That is the reason for your compiler warning.
There is a nice idiom in Scala that avoids the while loop:
val iterator = Iterator.continually(reader.readNext()).takeWhile(_ != null)
This gives you an iterator over whatever reader.readNext
returns.
The continually
method returns an “infinite” iterator and takeWhile
takes the prefix of that, up to but not including the first null.
(Scala 2.8)