tuwunel_core/utils/set/intersection.rs
1use crate::is_equal_to;
2
3/// Intersection of sets
4///
5/// Outputs the set of elements common to all input sets. Inputs do not have to
6/// be sorted. If inputs are sorted a more optimized function is available in
7/// this suite and should be used.
8pub fn intersection<Item, Iter, Iters>(mut input: Iters) -> impl Iterator<Item = Item> + Send
9where
10 Iters: Iterator<Item = Iter> + Clone + Send,
11 Iter: Iterator<Item = Item> + Send,
12 Item: Eq,
13{
14 input.next().into_iter().flat_map(move |first| {
15 let input = input.clone();
16 first.filter(move |targ| {
17 input
18 .clone()
19 .all(|mut other| other.any(is_equal_to!(*targ)))
20 })
21 })
22}