(Changed in version 2.8.0) collect has changed. The previous behavior can be reproduced with toSeq.
Upgrades Iterators to return results in batches of a given size.
Upgrades Iterators 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
Iteratorrealisation of the Producer / Consumer pattern where the producer and consumer run in separate threads.Both the
hasNextandnextmethods of theIteratormay 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
nextmay returnnullfollowing a successfulhasNext(another thread may have grabbed it first).If the client wishes to cancel iteration early, the
stopmethod may be called to free up resources.Functional purists may use this in their
Iterateespatterns.This is a multi-threaded alternative to the co-routine pattern.
It is a common misconception that
Iterator.hasNextis 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.