I would recommend trying out an implementation I am afraid that, once started, a Stream can no longer be modified, so if you use Stream.shift(...), your only option is to use Stream.shift(...) until the Stream is done or halt it. It effectively becomes an iterator API.
*José Valim* www.plataformatec.com.br Skype: jv.ptec Founder and Director of R&D On Fri, Mar 24, 2017 at 9:53 PM, <[email protected]> wrote: > 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 > <https://groups.google.com/d/msgid/elixir-lang-core/a7b5734b-66b9-495b-9c55-fdd318fb6899%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAGnRm4LhUR2udDBcy9oBxHUpqtX-NWdUrwLT98wJsBo6Lvtm3g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
