Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2015 23:18
Show Gist options
  • Save anonymous/ff1968fe1db9a605cd79 to your computer and use it in GitHub Desktop.
Save anonymous/ff1968fe1db9a605cd79 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn main() {
let g = vec![1, 5, 6, 9, 8];
let r = 7;
let mut i = g.iter().enumerate().peekable();
while let Some((index, lhs_val)) = i.next() {
let lookahead = i.peek();
println!("{}, {} with lookahead {:?}", index, lhs_val, lookahead);
}
// resulting iteration would be
// 0, 1 and includes 1, 5 & 2, 6
// 3, 9
// 4, 8
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment