Created
March 6, 2017 15:27
-
-
Save anonymous/af6408326fc9e6b99c8e0fd391d8dd10 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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