(Changed in version 2.8.0) collect
has changed. The previous behavior can be reproduced with toSeq
.
Upgrades Iterator
s to return results in batches of a given size.
Upgrades Iterator
s to return results in batches of a given size.
(Note that paging does imply anything on the buffering strategy)
Instruct the implementation to truncate at its earliest convenience and dispose of resources.
A very clean
Iterator
realisation of the Producer / Consumer pattern where the producer and consumer run in separate threads.Both the
hasNext
andnext
methods of theIterator
may block (e.g. when the consumer catches up with the producer).This is best used by a single producer and single consumer but can be extended to multiple consumers under the caveat that
next
may returnnull
following a successfulhasNext
(another thread may have grabbed it first).If the client wishes to cancel iteration early, the
stop
method may be called to free up resources.Functional purists may use this in their
Iteratees
patterns.This is a multi-threaded alternative to the co-routine pattern.
It is a common misconception that
Iterator.hasNext
is not allowed to block. However, the API documentation does not preclude blocking behaviour. Indeed, the Scala standard library encourages consumer blocking in the XML Pull API: scala.xml.pull.ProducerConsumerIterator.