count Helper

template<size_t MaxDeps = 8, typename Source>
Computed<uint32_t, 1, MaxDeps> RxESP32::Helpers::Analysis::count(Source &source, const typename Computed<uint32_t, 1, MaxDeps>::Options &options = {})

Count the number of times a source signal updates.

Creates a Computed signal that increments a counter each time the source signal changes. The counter starts at 0 on the first update and increments thereafter. Useful for tracking update frequency or detecting state changes.

Since

v0.1.0

Signal<int> button;
auto clicks = count(button);  // Track button clicks

button.set(1);  // clicks.get() == 1  (first update)
button.set(0);  // clicks.get() == 2
button.set(1);  // clicks.get() == 3
button.set(0);  // clicks.get() == 4

Note

  • Stateful helper. Counter initializes to 0 on first execution, then increments on each subsequent update.

  • The source value is read but not returned - only the count is tracked.

Template Parameters:
size_t MaxDeps = 8

Maximum number of dependents for the computed signal

Parameters:
Source &source

Source to monitor for updates.

const typename Computed<uint32_t, 1, MaxDeps>::Options &options = {}

Optional Computed configuration.

Returns:

Computed signal emitting the update count (uint32_t).

See Also