distinctMap<R> method

RxComputed<R> distinctMap<R>(
  1. R mapper(
    1. T
    )
)

Create a reactive value that only updates when the mapped value changes

Implementation

RxComputed<R> distinctMap<R>(R Function(T) mapper) {
  R? lastMapped;
  return computed(() {
    final newMapped = mapper(value);
    if (lastMapped != newMapped) {
      lastMapped = newMapped;
    }
    return lastMapped as R;
  });
}