Skip to content
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 toArray method #37

Closed
rubensworks opened this issue Feb 19, 2022 · 3 comments
Closed

Add toArray method #37

rubensworks opened this issue Feb 19, 2022 · 3 comments

Comments

@rubensworks
Copy link
Collaborator

While conserving the stream should be encouraged, there are still many use cases where converting the stream to an array is needed.
This is often done using arrayify-stream now, but this introduced the overhead of installing an additional package.
For developers, it would simplify things a lot if there was an (async) toArray method available, which would fully consume the stream and produce an array.

@RubenVerborgh If this sounds good to you, I will look into implementing this for including in the next major release (for #36).

@RubenVerborgh
Copy link
Owner

Great, absolutely! (Might take an optional object with limit parameter for infinite iterators?)

@jeswr
Copy link
Collaborator

jeswr commented Feb 20, 2022

@rubensworks - agreed this would be very useful; so long as you are just using consuming the data using the data and end events you should be able to do this without creating conflicts with what I am doing to resolve #35 (don't branch of #36 as a lot of those changes are not included in what I'm doing, just go off the main branch instead).

P.S. sorry for the delay - I'll push what I have today; editing some of the tests have been a bit time consuming. Once I've done that (which includes a solution to #38 ) it may be worth having a custom toArray method for the ArrayIterator that just returns the internal array? This may be useful in Comunica if an iterable (for instance of reasoning rules) is being pipelined through a set of actors each of which call toArray and work with the array and then create a new iterator using fromArray which they pass to the next actor.

@rubensworks
Copy link
Collaborator Author

it may be worth having a custom toArray method for the ArrayIterator that just returns the internal array?

Not sure. I had in mind that this method would arrayify elements that have not been consumed yet. E.g., if the user has already called read() several times, then I would expect these elements to not be included in the resulting array.
But a sliced version of the array might be possible though (but I would leave that as a possible optimization if needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants