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 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.  If the condition 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 a
/// closure that checks the termination condition 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, Z1},
/// };
///
/// let root = Root::build(|circuit| {
///     // Generate sequence 0, 1, 2, ...
///     let mut n: usize = 0;
///     let source = circuit.add_source(Generator::new(move || {
///         let result = n;
///         n = n + 1;
///         result
///     }));
///     // Compute factorial of each number in the sequence.
///     let fact = circuit
///         .iterate(|child| {
///             let counter = Rc::new(RefCell::new(0));
///             let counter_clone = counter.clone();
///             let countdown = source.delta0(child).apply(move |parent_val| {
///                 if *parent_val > 0 {
///                     *counter_clone.borrow_mut() += *parent_val;
///                 }
///                 let res = *counter_clone.borrow();
///                 *counter_clone.borrow_mut() -= 1;
///                 res
///             });
///             let (z1_output, z1_feedback) = child.add_feedback_with_export(Z1::new(1));
///             let mul = child.add_binary_operator(
///                 Apply2::new(|n1: &usize, n2: &usize| n1 * n2),
///                 &countdown,
///                 &z1_output.local,
///             );
///             z1_feedback.connect(&mul);
///             Ok((move || *counter.borrow() <= 1, z1_output.export))
///         })
///         .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 a
closure that checks the termination condition 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 a closure that checks the termination condition 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
constructor
F
examples
None
use std::{cell::refcell, rc::rc};
use dbsp::{
circuit::Root,
operator::{Apply2, Generator, Inspect, Z1},
}.

let root = Root::build(|circuit| {
Generate sequence 0, 1, 2,
let mut n: usize = 0;
let source = circuit.add_source(Generator::new(move || {
let result = n;
n = n + 1;
result
}));
Compute factorial of each number in the sequence.
let fact = circuit
.iterate(|child| {
let counter = Rc::new(RefCell::new(0));
let counter_clone = counter.clone();
let countdown = source.delta0(child).apply(move |parent_val| {
if *parent_val > 0 {
counter_clone.borrow_mut() += *parent_val;
}
let res = *counter_clone.borrow();
counter_clone.borrow_mut() -= 1;
res
});
let (z1_output, z1_feedback) = child.add_feedback_with_export(Z1::new(1));
let mul = child.add_binary_operator(
Apply2::new(|n1: &usize, n2: &usize| n1 * n2),
&countdown,
&z1_output.local,
);
z1_feedback.connect(&mul);
Ok((move || *counter.borrow() <= 1, z1_output.export))
})
.unwrap();
circuit.add_sink(Inspect::new(move |n| eprintln!("Output: {}", n)), &fact);
});
```
use dbsp :: { circuit :: Root operator :: { Apply2 Generator Inspect Z1 } } . let root = Root :: build ( |circuit| { Generate sequence 0 1 2 let mut n : usize = 0 ; let source = circuit . add_source ( Generator :: new ( move || { let result = n ; n = n + 1 ; result } )) ; Compute factorial of each number in the sequence . let fact = circuit . iterate ( |child| { let counter = Rc :: new ( RefCell :: new ( 0 )) ; let counter_clone = counter . clone () ; let countdown = source . delta0 ( child ) . apply ( move |parent_val| { if * parent_val > 0 { counter_clone . borrow_mut () + = * parent_val ; } let res = * counter_clone . borrow () ; counter_clone . borrow_mut () - = 1 ; res } ) ; let ( z1_output z1_feedback ) = child . add_feedback_with_export ( Z1 :: new ( 1 )) ; let mul = child . add_binary_operator ( Apply2 :: new ( |n1 : &usize n2 : &usize| n1 * n2 ) &countdown &z1_output . local ) ; z1_feedback . connect ( &mul ) ; Ok (( move || * counter . borrow () < = 1 z1_output . export )) } ) . unwrap () ; circuit . add_sink ( Inspect :: new ( move |n| eprintln! ( " Output : {} " n )) &fact ) ; } ) ; ` ` `