@@ -285,8 +285,8 @@ impl<Tuple: Ord> Variable<Tuple> {
285
285
///
286
286
/// let mut iteration = Iteration::new();
287
287
/// let variable = iteration.variable::<(usize, usize)>("source");
288
- /// variable.insert ((0 .. 10).map(|x| (x, x + 1)).collect( ));
289
- /// variable.insert ((0 .. 10).map(|x| (x + 1, x)).collect( ));
288
+ /// variable.extend ((0 .. 10).map(|x| (x, x + 1)));
289
+ /// variable.extend ((0 .. 10).map(|x| (x + 1, x)));
290
290
///
291
291
/// while iteration.changed() {
292
292
/// variable.from_join(&variable, &variable, |&key, &val1, &val2| (val1, val2));
@@ -322,7 +322,7 @@ impl<Tuple: Ord> Variable<Tuple> {
322
322
///
323
323
/// let mut iteration = Iteration::new();
324
324
/// let variable = iteration.variable::<(usize, usize)>("source");
325
- /// variable.insert ((0 .. 10).map(|x| (x, x + 1)).collect( ));
325
+ /// variable.extend ((0 .. 10).map(|x| (x, x + 1)));
326
326
///
327
327
/// let relation: Relation<_> = (0 .. 10).filter(|x| x % 3 == 0).collect();
328
328
///
@@ -356,7 +356,7 @@ impl<Tuple: Ord> Variable<Tuple> {
356
356
///
357
357
/// let mut iteration = Iteration::new();
358
358
/// let variable = iteration.variable::<(usize, usize)>("source");
359
- /// variable.insert ((0 .. 10).map(|x| (x, x)).collect( ));
359
+ /// variable.extend ((0 .. 10).map(|x| (x, x)));
360
360
///
361
361
/// while iteration.changed() {
362
362
/// variable.from_map(&variable, |&(key, val)|
@@ -434,6 +434,7 @@ impl<Tuple: Ord> Variable<Tuple> {
434
434
to_add : Rc :: new ( RefCell :: new ( Vec :: new ( ) ) ) ,
435
435
}
436
436
}
437
+
437
438
/// Inserts a relation into the variable.
438
439
///
439
440
/// This is most commonly used to load initial values into a variable.
@@ -444,6 +445,18 @@ impl<Tuple: Ord> Variable<Tuple> {
444
445
self . to_add . borrow_mut ( ) . push ( relation) ;
445
446
}
446
447
}
448
+
449
+ /// Extend the variable with values from the iterator.
450
+ ///
451
+ /// This is most commonly used to load initial values into a variable.
452
+ /// it is not obvious that it should be commonly used otherwise, but
453
+ /// it should not be harmful.
454
+ pub fn extend < T > ( & self , iterator : impl IntoIterator < Item = T > )
455
+ where Relation < Tuple > : FromIterator < T >
456
+ {
457
+ self . insert ( iterator. into_iter ( ) . collect ( ) ) ;
458
+ }
459
+
447
460
/// Consumes the variable and returns a relation.
448
461
///
449
462
/// This method removes the ability for the variable to develop, and
0 commit comments