File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -44,8 +44,8 @@ pub struct Relation<Tuple: Ord> {
44
44
impl < Tuple : Ord > Relation < Tuple > {
45
45
/// Merges two relations into their union.
46
46
pub fn merge ( self , other : Self ) -> Self {
47
- let mut elements1 = self . elements ;
48
- let mut elements2 = other. elements ;
47
+ let Relation { elements : mut elements1 } = self ;
48
+ let Relation { elements : mut elements2 } = other;
49
49
50
50
// If one of the element lists is zero-length, we don't need to do any work
51
51
if elements1. is_empty ( ) {
@@ -135,6 +135,13 @@ impl<Tuple: Ord> Relation<Tuple> {
135
135
join:: antijoin ( input1, input2, logic)
136
136
}
137
137
138
+ /// Construct a new relation by mapping another one. Equivalent to
139
+ /// creating an iterator but perhaps more convenient. Analogous to
140
+ /// `Variable::from_map`.
141
+ pub fn from_map < T2 : Ord > ( & self , input : & Relation < T2 > , logic : impl FnMut ( & T2 ) -> Tuple ) -> Self {
142
+ input. iter ( ) . map ( logic) . collect ( )
143
+ }
144
+
138
145
/// Creates a `Relation` from a vector of tuples.
139
146
pub fn from_vec ( mut elements : Vec < Tuple > ) -> Self {
140
147
elements. sort ( ) ;
You can’t perform that action at this time.
0 commit comments