combine Helper

Basic Overload

template<size_t MaxDeps = 8, typename Combiner, typename Source1, typename ...Sources>
auto RxESP32::Helpers::Combinatorial::combine(Combiner &&combiner, Source1 &source1, Sources&... sources)

Combine multiple sources using a combiner function.

Creates a Computed that recomputes when any source changes, applying the combiner function to all source values.

Since

v0.1.0

Signal<int> a(5), b(10), c(15);

// Sum all signals
auto sum = combine([](int x, int y, int z) {
  return x + y + z;
}, a, b, c);

Serial.println(sum.get()); // 30

Warning

  • Requires at least 2 sources.

  • All sources must return the same type.

  • Combiner must accept all source types and return source1 type.

Template Parameters:
size_t MaxDeps = 8

Maximum dependents for resulting Computed.

Parameters:
Combiner &&combiner

Function that combines all source values.

Source1 &source1

First source (determines result type).

Sources&... sources

Additional sources (must match source1 type).

Returns:

Computed holding the combined result.

With Options

template<size_t MaxDeps = 8, typename Combiner, typename Source1, typename ...Sources>
auto RxESP32::Helpers::Combinatorial::combine(Combiner &&combiner, const typename Computed<decltype(std::declval<Source1>().get()), MaxDeps, 1 + sizeof...(Sources)>::Options &options, Source1 &source1, Sources&... sources)

Combine multiple sources using a combiner function with options.

Creates a Computed that recomputes when any source changes, applying the combiner function to all source values, with custom options.

Since

v0.1.0

Signal<int> a(5), b(10), c(15);

// Sum all signals with custom options
auto sum = combine([](int x, int y, int z) {
  return x + y + z;
}, {.lazy = true}, a, b, c);

Serial.println(sum.get()); // 30

Warning

  • Requires at least 2 sources.

  • All sources must return the same type.

  • Combiner must accept all source types and return source1 type.

Template Parameters:
size_t MaxDeps = 8

Maximum dependents for resulting Computed.

Parameters:
Combiner &&combiner

Function that combines all source values.

const typename Computed<decltype(std::declval<Source1>().get()), MaxDeps, 1 + sizeof...(Sources)>::Options &options

Computed configuration options.

Source1 &source1

First source (determines result type).

Sources&... sources

Additional sources (must match source1 type).

Returns:

Computed holding the combined result.

See Also