src/core/util/iterator.js
function findSubsequentItem(backwards, item, validate, limit) {
      validate = validate || trueFn;

      var curIndex = indexOf(item);
      while (true) {
        if (!inRange(curIndex)) return null;

        var nextIndex = curIndex + (backwards ? -1 : 1);
        var foundItem = null;
        if (inRange(nextIndex)) {
          foundItem = _items[nextIndex];
        } else if (reloop) {
          foundItem = backwards ? last() : first();
          nextIndex = indexOf(foundItem);
        }

        if ((foundItem === null) || (nextIndex === limit)) return null;
        if (validate(foundItem)) return foundItem;

        if (angular.isUndefined(limit)) limit = nextIndex;

        curIndex = nextIndex;
      }
    }
function findSubsequentItem(backwards, item, validate, limit) {
      validate = validate || trueFn;

      var curIndex = indexOf(item);
      while (true) {
        if (!inRange(curIndex)) return null;

        var nextIndex = curIndex + (backwards ? -1 : 1);
        var foundItem = null;
        if (inRange(nextIndex)) {
          foundItem = _items[nextIndex];
        } else if (reloop) {
          foundItem = backwards ? last() : first();
          nextIndex = indexOf(foundItem);
        }

        if ((foundItem === null) || (nextIndex === limit)) return null;
        if (validate(foundItem)) return foundItem;

        if (angular.isUndefined(limit)) limit = nextIndex;

        curIndex = nextIndex;
      }
    }
function findSubsequentItem ( backwards , item , validate , limit ) { validate = validate || trueFn ; var curIndex = indexOf ( item ) ; while ( true ) { if ( ! inRange ( curIndex ) ) return null ; var nextIndex = curIndex + ( backwards ? - 1 : 1 ) ; var foundItem = null ; if ( inRange ( nextIndex ) ) { foundItem = _items [ nextIndex ] ; } else if ( reloop ) { foundItem = backwards ? last ( ) : first ( ) ; nextIndex = indexOf ( foundItem ) ; } if ( ( foundItem === null ) || ( nextIndex === limit ) ) return null ; if ( validate ( foundItem ) ) return foundItem ; if ( angular . isUndefined ( limit ) ) limit = nextIndex ; curIndex = nextIndex ; } }
Find the next item. If reloop is true and at the end of the list, it will go back to the
first item. If given, the `validate` callback will be used to determine whether the next item
is valid. If not valid, it will try to find the next item again.

@param {boolean} backwards Specifies the direction of searching (forwards/backwards)
@param {*} item The item whose subsequent item we are looking for
@param {Function=} validate The `validate` function
@param {integer=} limit The recursion limit

@returns {*} The subsequent item or null
Find the next item . If reloop is true and at the end of the list it will go back to the first item . If given the validate callback will be used to determine whether the next item is valid . If not valid it will try to find the next item again .