Add toArray method
Closed this issue · 3 comments
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).
Great, absolutely! (Might take an optional object with limit parameter for infinite iterators?)
@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.
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).