Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2017 15:27
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 anonymous/af6408326fc9e6b99c8e0fd391d8dd10 to your computer and use it in GitHub Desktop.
Save anonymous/af6408326fc9e6b99c8e0fd391d8dd10 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
/// Takes two iterators over an ordered (key, value) sequence,
/// removing all entries which keys don't find a match in place
/// and zips the resulting filtered iterators afterwards.
///
/// Assumes the keys are in ascending order.
pub fn filter_zip<K, V, W, A, B>(a: &mut A, b: &mut B) // -> Iterator<Item=(K,(V, W))>
where K: Ord,
A: Iterator<Item=(K, V)>,
B: Iterator<Item=(K, W)>,
{
a.filter(|&(ref key_a,_)| {
let mut is_equal = false;
b.filter(|&(ref key_b,_)| {
if key_a == key_b {
is_equal = true;
true
} else {
key_a > key_b
}
});
is_equal
})
// .zip(b)
;
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment