select<B> method

AtomWithParent<FutureValue<B>, Parent> select<B>(
  1. B f(
    1. A value
    )
)

Create a derived atom, that transforms an atoms value using the given function f.

Only rebuilds when the selected value changes.

Implementation

AtomWithParent<FutureValue<B>, Parent> select<B>(
  B Function(A value) f,
) =>
    AtomWithParent(parent, (get, parent) {
      final value = get(this).map(f);
      if (value.dataOrNull != null) {
        // ignore: null_check_on_nullable_type_parameter
        return FutureValue.data(value.dataOrNull!);
      }

      final prev = get.self();
      if (prev is FutureData<B>) {
        return prev;
      }

      return value;
    });