HomeReferenceAlgorithm.h ⇀ Iterate

Iterate function

Folds values from an event stream into a signal.

Syntax

// (1)
template
<
    typename D,
    typename E,
    typename V,
    typename F,
    typename S = decay<V>::type
>
Signal<D,S> Iterate(const Events<D,E>& events, V&& init, F&& func); 

// (2)
template
<
    typename D,
    typename E,
    typename V,
    typename F,
    typename ... TDepValues,
    typename S = decay<V>::type
>
Signal<D,S> Iterate(const Events<D,E>& events, V&& init,
                    const SignalPack<D,TDepValues...>& depPack, F&& func);

Semantics

(1) Creates a signal with an initial value v = init.

(2) Similar to (1), but the synchronized values of signals in depPack are passed to func as additional arguments. Changes of signals in depPack do not trigger an update - only received events do.

The signature of func should be equivalent to:

The event parameter const E& can also be replaced by an event range, i.e. S func(EventRange<E> range, const S&) for case (1a). This allows for explicit batch processing of events of a single turn.

Graph

(1a)

(2a)