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

Introduce Iterators#flatMap #92202

Merged

Conversation

DaveCTurner
Copy link
Contributor

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 #89838

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
@DaveCTurner DaveCTurner added >non-issue :Distributed Coordination/Network Http and internode communication implementations v8.7.0 labels Dec 7, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Dec 7, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

}

@Override
public boolean hasNext() {
boolean hasNext = false;
while (index < iterators.length && (hasNext = iterators[index].hasNext()) == false) {
index++;
Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Copy link
Member

@original-brownbear original-brownbear left a 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!

@DaveCTurner DaveCTurner added auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) and removed auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) labels Dec 7, 2022
@DaveCTurner DaveCTurner added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Dec 7, 2022
@elasticsearchmachine elasticsearchmachine merged commit 18801a8 into elastic:main Dec 7, 2022
@DaveCTurner DaveCTurner deleted the 2022-12-07-Iterators#flatMap branch December 7, 2022 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Network Http and internode communication implementations >non-issue Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants