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> {
4444impl < Tuple : Ord > Relation < Tuple > {
4545 /// Merges two relations into their union.
4646 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;
4949
5050 // If one of the element lists is zero-length, we don't need to do any work
5151 if elements1. is_empty ( ) {
@@ -135,6 +135,13 @@ impl<Tuple: Ord> Relation<Tuple> {
135135 join:: antijoin ( input1, input2, logic)
136136 }
137137
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+
138145 /// Creates a `Relation` from a vector of tuples.
139146 pub fn from_vec ( mut elements : Vec < Tuple > ) -> Self {
140147 elements. sort ( ) ;
You can’t perform that action at this time.
0 commit comments