Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created May 12, 2019 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/bdf56f6d35679e3beadf98c5cdf09b46 to your computer and use it in GitHub Desktop.
Save rust-play/bdf56f6d35679e3beadf98c5cdf09b46 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
struct Parent {
id: i32
}
struct Child {
id: i32,
order_id: i32
}
fn main() {
let sample = [(Parent {id: 1}, Child {id: 1, order_id: 1}), (Parent {id: 2}, Child {id: 1, order_id: 1})];
let orders = sample.into_iter().map(|item| item.0);
let submissions = sample.into_iter().map(|item| item.1);
orders.map(|item| { "id": item.id, "orders": orders.map(|submission| submissions.filter(|order| order.id == submission.id)) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment