derive<S> function

dynamic derive<S>(
  1. Signal<S> signal,
  2. DeriveValue<S> derivedValue
)

Derive the next value of a Signal from the previous value.

Set the next value of a Signal by reusing the previous value of the given Signal, giving derive a reference to the signal and a function that calculates on how to get the derivedValue. This may be used when updating a signal that keeps track of a mutable object as its state for example.

Implementation

derive<S>(Signal<S> signal, DeriveValue<S> derivedValue) {
  final (getter, setter) = signal;
  setter(derivedValue(getter()));
}