Skip to main content

union/
union.rs

1//! Demonstrates how to combine compatible relations with the `UNION` operation.
2
3use darwen::prelude::{Relation, RelationBuilder, ScalarType};
4use darwen::{heading, tuple};
5
6fn station_a() -> Relation {
7    RelationBuilder::new()
8        .with_heading(heading!(number = ScalarType::Integer).unwrap())
9        .with_body(vec![
10            tuple!(number = 4).unwrap(),
11            tuple!(number = 8).unwrap(),
12            tuple!(number = 15).unwrap(),
13        ])
14        .build()
15        .unwrap()
16}
17
18fn station_b() -> Relation {
19    RelationBuilder::new()
20        .with_heading(heading!(number = ScalarType::Integer).unwrap())
21        .with_body(vec![
22            tuple!(number = 15).unwrap(),
23            tuple!(number = 16).unwrap(),
24            tuple!(number = 23).unwrap(),
25            tuple!(number = 42).unwrap(),
26        ])
27        .build()
28        .unwrap()
29}
30
31fn main() {
32    let station_a = station_a();
33    let station_b = station_b();
34
35    println!("{}", station_a.union(&station_b).unwrap());
36}