rposition method

int? rposition(
  1. bool f(
    1. T
    )
)

Searches for an element in an iterator from the right, returning its index. Recommended to use with a list, as it is more efficient, otherwise use positionOpt.

Implementation

int? rposition(bool Function(T) f) {
  final list = toList(growable: false).reversed;
  var index = list.length - 1;
  for (final element in list) {
    if (f(element)) {
      return index;
    }
    index--;
  }
  return null;
}