filter Helper¶
-
template<size_t MaxDeps = 8, typename Predicate, typename Source>
auto RxESP32::Helpers::Transformation::filter(Source &source, Predicate &&predicate, const typename Computed<decltype(source.get()), 1, MaxDeps>::Options &options = {})¶ Filter source values based on a predicate.
Creates a Computed that only updates when the predicate returns
true. Whenfalse, the last valid value is retained.- Since
v0.1.0
Signal<int> values(0); // Only positive values auto positive = filter(values, [](int v) { return v > 0; }); values.set(5); // positive.get() == 5 values.set(-10); // positive.get() == 5 (unchanged) values.set(20); // positive.get() == 20Warning
Predicate must accept source value type and return
bool.
See Also¶
Transformation Helpers - Overview