valuable<T> method

Derived<T> valuable<T>(
  1. T getter(
    1. T? oldValue
    )
)

Creates a derived reference that computes its value based on the previous value.

The getter function computes the value based on the old value.

NOTE: First value is always null.

final count = ref(0);
final total = derived.valuable<int>(
  (prev) => count.value + (prev ?? 0)
);

print(total.value); // 0

count.value = 10;
print(total.value); // 10

count.value = 20;
print(total.value); // 30

Implementation

public.Derived<T> valuable<T>(T Function(T? oldValue) getter) {
  return impl.Derived(getter);
}