Guest User

Untitled

a guest
Jun 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. fn cartesian<I, J, T, U>(x: I, y: J) -> Vec<(T, U)>
  2. where
  3. I: IntoIterator<Item=T>,
  4. T: Clone,
  5. J: IntoIterator<Item=U>,
  6. J::IntoIter: Clone,
  7. U: Clone,
  8. {
  9. let y = y.into_iter();
  10. x.into_iter().map(
  11. |xp| y.clone().map(
  12. move |yp| (xp.clone(), yp)
  13. )
  14. ).flat_map(|i| i).collect()
  15. }
  16.  
  17. fn main() {
  18. let v1 = vec![String::from("foo"), String::from("bar")];
  19. let v2 = vec![String::from("baz"), String::from("qux")];
  20.  
  21. let it = cartesian(v1.iter(), v2.iter());
  22.  
  23. for item in it {
  24. let (s1, s2) = item;
  25. println!("{} {}", s1, s2)
  26. }
  27. }
Add Comment
Please, Sign In to add comment