distanceToElementWhere method

int? distanceToElementWhere(
  1. bool test(
    1. E element
    )
)

Calculate how far back in the stack a matching element is.

Returns null if not found.

Implementation

int? distanceToElementWhere(bool Function(E element) test) {
  final pos = _list.lastIndexWhere(test);
  if (pos == -1) {
    return null;
  }
  final distance = _list.length - pos - 1;
  return distance;
}