Skip to main content

intersect/
intersect.rs

1//! Demonstrates how to keep only shared tuples with the `INTERSECT` operation.
2
3use darwen::prelude::{Relation, RelationBuilder, ScalarType};
4use darwen::{heading, tuple};
5
6fn side_a() -> Relation {
7    RelationBuilder::new()
8        .with_heading(heading!(name = ScalarType::String).unwrap())
9        .with_body(vec![
10            tuple!(name = "Monica").unwrap(),
11            tuple!(name = "Erica").unwrap(),
12            tuple!(name = "Rita").unwrap(),
13            tuple!(name = "Tina").unwrap(),
14        ])
15        .build()
16        .unwrap()
17}
18
19fn side_b() -> Relation {
20    RelationBuilder::new()
21        .with_heading(heading!(name = ScalarType::String).unwrap())
22        .with_body(vec![
23            tuple!(name = "Rita").unwrap(),
24            tuple!(name = "Sandra").unwrap(),
25            tuple!(name = "Mary").unwrap(),
26            tuple!(name = "Jessica").unwrap(),
27        ])
28        .build()
29        .unwrap()
30}
31
32fn main() {
33    let side_a = side_a();
34    let side_b = side_b();
35
36    println!("{}", side_a.intersect(&side_b).unwrap());
37}