The Stream module contains many functions to work with lazily evaluated 
sequences. 
However, functions like `Stream.map`, `Stream.reduce`, `Stream.transform`, 
only make sense when the stream is the primary part of our recursion.
If we are doing something where we want to take an item from the (possibly 
infinite) stream only every once in a while, then we're out of luck. 
Functions like `Stream.take` only return a result, but discard the 
unevaluated tail of the stream.

So I would propose a function that, when called, would return a tuple: As 
first element of the tuple, the outcome of calculating the first item of 
the stream, and as second element the unevaluated stream without the first 
element included.
In the case the stream is empty, `nil` should be returned.

I was thinking `Stream.shift` as name for this thing, but there are quite 
probably better names to give this as well. Semantics is of course more 
important than syntax.

In any case, I think this is an addition that is very much in line with 
what Streams already do, but it will make it easier to work with them for 
certain kinds of algorithms, such as programs where we are parsing files 
but there is no natural way to split this file into lines or equally-sized 
chunks.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/a7b5734b-66b9-495b-9c55-fdd318fb6899%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to