Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate itertools;
- use itertools::Itertools;
- fn main() {
- let v = vec![1, 2, 2, 2, 3, 4, 4, 5];
- let res = v.into_iter()
- .enumerate()
- .map(|(idx, value)| (value, idx, idx))
- .coalesce(|x, y| {
- if x.0 == y.0 {
- Ok((x.0, x.1, y.1))
- } else {
- Err((x, y))
- }
- })
- .collect::<Vec<_>>();
- println!("{:?}", res);
- }
Add Comment
Please, Sign In to add comment