map Helper

template<size_t MaxDeps = 8, typename Transformer, typename Source>
auto RxESP32::Helpers::Transformation::map(Source &source, Transformer &&transformer, const typename Computed<decltype(transformer(source.get())), 1, MaxDeps>::Options &options = {})

Transform source value using a mapping function.

Creates a Computed that applies a transformation to the source’s value.

Since

v0.1.0

Signal<int> celsius(25);
// Computed fahrenheit with return type int (auto-deduced)
auto fahrenheit = map(celsius, [](int c) {
  return c * 9 / 5 + 32;
});
Serial.println(fahrenheit.get()); // 77

Warning

Transformer must accept source value type and return the desired result type.

Template Parameters:
size_t MaxDeps = 8

Maximum dependents for the resulting Computed.

Parameters:
Source &source

Source to transform.

Transformer &&transformer

Function that transforms the source value.

const typename Computed<decltype(transformer(source.get())), 1, MaxDeps>::Options &options = {}

Optional Computed configuration.

Returns:

Computed that holds the transformed value.

See Also