I want an infinite queue that is backed by an infinite stream in Scala. This feels simple enough but I just can't find how to do this.
I.e.
Stream.from(0).toQueue // Except that there is no method "toQueue"
I want an infinite queue that is backed by an infinite stream in Scala. This feels simple enough but I just can't find how to do this.
I.e.
Stream.from(0).toQueue // Except that there is no method "toQueue"
A queue can't be infinite because it requires access from both ends: dequeue
operation takes an element from the front of the queue, but enqueue
puts an element to the back of the queue. For infinite sequences it does not make sense. Infinite stack would make sense (and in fact that's what single-linked lists and streams essentially are), but Stack
interface is deprecated in favor of using implementations directly.
What you need an infinite queue for? If you only want to consume the stream sequentially, you can use native stream methods or destructuring or just generic collection methods like foreach
.