Guest User

Untitled

a guest
Apr 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. extern crate itertools;
  2.  
  3. use itertools::Itertools;
  4.  
  5. fn main() {
  6. let v = vec![1, 2, 2, 2, 3, 4, 4, 5];
  7. let res = v.into_iter()
  8. .enumerate()
  9. .map(|(idx, value)| (value, idx, idx))
  10. .coalesce(|x, y| {
  11. if x.0 == y.0 {
  12. Ok((x.0, x.1, y.1))
  13. } else {
  14. Err((x, y))
  15. }
  16. })
  17. .collect::<Vec<_>>();
  18. println!("{:?}", res);
  19. }
Add Comment
Please, Sign In to add comment