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

Iterator adaptor .positions(predicate) #218

Closed
bluss opened this Issue Sep 11, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@bluss
Copy link
Owner

bluss commented Sep 11, 2017

Like an iterated version of position or a filtered version of enumerate.

The existing combination is a bit heavy on the punctuation:

self.1.iter()
      .enumerate()
      .filter(|&(_, node)| node.weight.is_none())
      .map(|(i, _)| NodeIndex::<Ix>::new(i))

Propose instead:

self.1.iter()
      .positions(|node| node.weight.is_none())
      .map(NodeIndex::<Ix>::new)
@bluss

This comment has been minimized.

Copy link
Owner Author

bluss commented Sep 11, 2017

An alternative, a literal filtered version of enumerate. Indices are including the removed elements, of course.

self.1.iter()
      .enumerate_filter(|node| node.weight.is_none())
      .map(|(i, _node)| NodeIndex::<Ix>::new(i))
@tmccombs

This comment has been minimized.

Copy link
Contributor

tmccombs commented Sep 16, 2017

I prefer the positions interface, because it is easier to use in situations like

let positions = self.1.iter().positions().collect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.