-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Stream.split(collection, count) ⇒ {splitted_values, rest_of_stream} #2922
Comments
That cannot work as you expect. A stream does not traverse a collection yet, so what happens if someone starts to traverse the second element of the split before the first one? For this reason, there is no way to implement Stream.split/2 without using a process for state and none of the stream functions require a separate process today. As mentioned on IRC, your issue will be tackled by the other issue where you commented. For now, Stream.transform/2 is definitely the best and most performatic way to go. |
I don't know how complex Elixir's stream implementation is, but based on what I learned about streams, there isn't any need for state in order to implement this feature: all you need are thunks (see slides 11-14 in this lecture). As long as the source of a stream is not mutable and not a resource, I think that sharing a thunk among multiple processes should be OK because they would independently be accessing the same stream from (possibly) different positions using their own independent "cursors" (call stacks, essentially). 😅 |
And the only way to implement thunks in elixir without requiring native José Valimwww.plataformatec.com.br |
Hello,
Please add support for a
Stream.split(collection, count)
function that returns{splitted_values, rest_of_stream}
so that I can continue consuming a stream from where I left off, instead of having to start all over again from the beginning each time I want to consume more of the stream. For example:In particular, this would allow me to consume a file stream in piecemeal fashion, rather than having to swoop through the entire file in one shot (which is what the Stream module API currently supports):
See also issue #2515 for a related discussion about a more general form of this feature.
Thanks for your consideration.
The text was updated successfully, but these errors were encountered: