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

Add a skip_every iterator #132

Closed
shssoichiro opened this issue Jul 14, 2016 · 2 comments
Closed

Add a skip_every iterator #132

shssoichiro opened this issue Jul 14, 2016 · 2 comments

Comments

@shssoichiro
Copy link

The name and semantics can be changed if necessary, but I'd like an iterator that skips every nth element, and I wasn't able to find an existing one in reading through the docs. For example:

let items = vec![1, 2, 3, 4, 5, 6, 7, 8];
assert_eq!(vec![1, 2, 4, 5, 7, 8], items.iter().skip_every(3).collect());
@fyrchik
Copy link
Contributor

fyrchik commented Nov 9, 2019

This is equivalent to .enumerate().filter(|(n,_)| n % 3 != 2).map(|(_,v)| v). (or just enumerate + filter_map. I am not sure if specific implementation will be faster.

@shssoichiro
Copy link
Author

This ticket is from 3 years ago, so probably could be closed anyway. Thanks for alternative suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants