-
Notifications
You must be signed in to change notification settings - Fork 8
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
feature suggestion: takeWhile() #275
Comments
Would this be the same as And thank you 😊 |
I don't think it's the same as filter because this would terminate the stream early, allowing for early collection, or ability to exit out of a find algorithm. For example: This could exit early once charmander is found. const pm = await pipeline(
getPokemon(),
takeWhile(pokemon => pokemon.name !== 'charmander', true),
take(-1), // this would also be great to implement btw
collect
)
// => pm[0].name === 'charmander' This would have to cycle through all 720 pokemon before exiting const pm = await pipeline(
getPokemon(),
filter(pokemon => pokemon.name === 'charmander'),
collect
) Generally i think implementing some of the methods that rust's Iterator has would be great: https://doc.rust-lang.org/core/iter/trait.Iterator.html Or perhaps looking through the list of operators that rxjs provides: https://rxjs.dev/api?type=function |
Well stated, thank you. Yeah this makes a lot of sense. I'd happily take a pr if you're interested. I'll dig into the rust docs, but I'm also happy to take anything useful. |
What would |
Absolutely, i don't think you'd want to buffer much. I'm imagining that it would effectively release the data it doesn't need. Maybe a const takeRight = (count) => async function* (iterable){
const buffer = []
for await (const res of iterable) {
buffer.push(res)
if (buffer.length > count){ buffer.shift() }
}
while (buffer.length){ yield buffer.pop() }
}
const take = (n) => {
if (n < 0) { return takeRight(-n) }
else { return take(n) }
} I'd be happy to submit some pull requests |
hey there. Great library!
A
takeWhile()
operator would be great.Something like this?
The text was updated successfully, but these errors were encountered: