/// Add an iteratively scheduled child circuit.
///
/// Add a child circuit with a nested clock.  The child will execute
/// multiple times for each parent timestamp, until its termination
/// condition is satisfied.  Every time the child circuit is activated
/// by the parent (once per parent timestamp), the executor calls
/// [`clock_start`](`super::operator_traits::Operator::clock_start`)
/// on each child operator.  It then calls `eval` on all
/// child operators in a causal order and checks if the termination
/// condition is satisfied by reading from a user-specified
/// "termination" stream.  If the value in the stream is `false`, the
/// executor `eval`s all operators again.  Once the termination
/// condition is `true`, the executor calls `clock_end` on all child
/// operators and returns control back to the parent scheduler.
///
/// The `constructor` closure populates the child circuit and returns the
/// termination stream used by the executor to check termination
/// condition on each iteration and an arbitrary user-defined return
/// value that typically contains output streams of the child.
///
/// # Examples
///
/// ```
/// # use std::{cell::RefCell, rc::Rc};
/// use dbsp::{
///     circuit::Root,
///     operator::{Apply2, Generator, Inspect, NestedSource, Z1},
/// };
///
/// let root = Root::build(|circuit| {
///     let mut n: usize = 0;
///     let source = circuit.add_source(Generator::new(move || {
///         let result = n;
///         n = n + 1;
///         result
///     }));
///     let fact = circuit
///         .iterate(|child| {
///             let counter = Rc::new(RefCell::new(0));
///             let counter_clone = counter.clone();
///             let countdown =
///                 child.add_source(NestedSource::new(source, child, move |n: &mut usize| {
///                     *n = *n - 1;
///                     *counter_clone.borrow_mut() = *n;
///                 }));
///             let (z1_output, z1_feedback) = child.add_feedback(Z1::new(1));
///             let mul = child
///                 .add_binary_operator(
///                     Apply2::new(|n1: &usize, n2: &usize| n1 * n2),
///                     &countdown,
///                     &z1_output,
///                 )
///                 .unwrap();
///             z1_feedback.connect(&mul);
///             Ok((move || *counter.borrow() <= 1, mul.leave()))
///         })
///         .unwrap();
///     circuit.add_sink(Inspect::new(move |n| eprintln!("Output: {}", n)), &fact);
/// });
/// ```
Add an iteratively scheduled child circuit.
Add a child circuit with a nested clock.  The child will execute
multiple times for each parent timestamp, until its termination
condition is satisfied.

The `constructor` closure populates the child circuit and returns the
termination stream used by the executor to check termination
condition on each iteration and an arbitrary user-defined return
value that typically contains output streams of the child.
Add an iteratively scheduled child circuit . Add a child circuit with a nested clock . The child will execute multiple times for each parent timestamp until its termination condition is satisfied . The ` constructor ` closure populates the child circuit and returns the termination stream used by the executor to check termination condition on each iteration and an arbitrary user - defined return value that typically contains output streams of the child .
pub fn iterate<F, C, T>(&self, constructor: F) -> Result<T, SchedulerError>
    where
        F: FnOnce(&mut Circuit<Self>) -> Result<(C, T), SchedulerError>,
        C: Fn() -> bool + 'static,
    {
        self.iterate_with_scheduler::<F, C, T, DynamicScheduler>(constructor)
    }
pub fn iterate < F , C , T > ( & self , constructor : F ) -> Result < T , SchedulerError > where F : FnOnce ( & mut Circuit < Self > ) -> Result < ( C , T ) , SchedulerError > , C : Fn ( ) -> bool + ' static , { self . iterate_with_scheduler :: < F , C , T , DynamicScheduler > ( constructor ) }
Add an iteratively scheduled child circuit.
Add an iteratively scheduled child circuit .
&self
<not_specific>
constructor
F
<not_specific>
examples
None
use std::{cell::refcell, rc::rc};
use dbsp::{
circuit::Root,
operator::{Apply2, Generator, Inspect, NestedSource, Z1},
}.

let root = Root::build(|circuit| {
let mut n: usize = 0;
let source = circuit.add_source(Generator::new(move || {
let result = n;
n = n + 1;
result
}));
let fact = circuit
.iterate(|child| {
let counter = Rc::new(RefCell::new(0));
let counter_clone = counter.clone();
let countdown
child.add_source(NestedSource::new(source, child, move |n: &mut usize| {
n = *n - 1;
counter_clone.borrow_mut() = *n;
}));
let (z1_output, z1_feedback) = child.add_feedback(Z1::new(1));
let mul = child
.add_binary_operator(
Apply2::new(|n1: &usize, n2: &usize| n1 * n2),
&countdown,
&z1_output,
)
.unwrap();
z1_feedback.connect(&mul);
Ok((move || *counter.borrow() <= 1, mul.leave()))
})
.unwrap();
circuit.add_sink(Inspect::new(move |n| eprintln!("Output: {}", n)), &fact);
});
```
use dbsp :: { circuit :: Root operator :: { Apply2 Generator Inspect NestedSource Z1 } } . let root = Root :: build ( |circuit| { let mut n : usize = 0 ; let source = circuit . add_source ( Generator :: new ( move || { let result = n ; n = n + 1 ; result } )) ; let fact = circuit . iterate ( |child| { let counter = Rc :: new ( RefCell :: new ( 0 )) ; let counter_clone = counter . clone () ; let countdown child . add_source ( NestedSource :: new ( source child move |n : &mut usize| { n = * n - 1 ; counter_clone . borrow_mut () = * n ; } )) ; let ( z1_output z1_feedback ) = child . add_feedback ( Z1 :: new ( 1 )) ; let mul = child . add_binary_operator ( Apply2 :: new ( |n1 : &usize n2 : &usize| n1 * n2 ) &countdown &z1_output ) . unwrap () ; z1_feedback . connect ( &mul ) ; Ok (( move || * counter . borrow () < = 1 mul . leave () )) } ) . unwrap () ; circuit . add_sink ( Inspect :: new ( move |n| eprintln! ( " Output : {} " n )) &fact ) ; } ) ; ` ` `