-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Introduce Iterators#flatMap #92202
Introduce Iterators#flatMap #92202
Conversation
Various places that implement response chunking involving some kind of nested structure (e.g. a list of lists) need to call something like `flatMap`, and today this means they must must convert between iterators and streams to make use of `Stream#flatMap`. This is noisy and awkward, so with this commit we introduce a way to `flatMap` directly on iterators. Relates elastic#89838
Pinging @elastic/es-distributed (Team:Distributed) |
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
boolean hasNext = false; | ||
while (index < iterators.length && (hasNext = iterators[index].hasNext()) == false) { | ||
index++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it weird to be changing state in hasNext()
like this, I prefer to do all the moving in next()
so that we're always pointing at a nonempty iterator until done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming CI is happy :) warmed up to this, thanks!
Various places that implement response chunking involving some kind of nested structure (e.g. a list of lists) need to call something like
flatMap
, and today this means they must must convert between iterators and streams to make use ofStream#flatMap
. This is noisy and awkward, so with this commit we introduce a way toflatMap
directly on iterators.Relates #89838