code: function RangeIterator(range, collection) {
  
      // the range, size, collection, and current slot index are private attributes
      // so methods that use them are defined in the constructor
      var currentSlot = 0;  // the slot before the first number
      const size = range.getSize();  // static so we can cache it here
  
      this.toStart = function() {
          currentSlot = 0;  // the slot before the first number
      };
      
      this.toSlot = function(slot) {
          currentSlot = slot;
      };
      
      this.toEnd = function() {
          currentSlot = size;  // the slot after the last number
      };
      
      this.hasPrevious = function() {
          return currentSlot > 0;
      };
      
      this.hasNext = function() {
          return currentSlot < size;
      };
      
      this.getPrevious = function() {
          if (!this.hasPrevious()) return;
          currentSlot--;
          const index = range.getFirstIndex() + currentSlot;
          var item;
          if (collection) {
              item = collection.getItem(index);  // retrieve the item
          } else {
              item = new elements.Number(index);  // the index is the item
          }
          return item;
      };
      
      this.getNext = function() {
          if (!this.hasNext()) return;
          const index = range.getFirstIndex() + currentSlot;
          var item;
          if (collection) {
              item = collection.getItem(index);  // retrieve the item
          } else {
              item = new elements.Number(index);  // the index is the item
          }
          currentSlot++;
          return item;
      };
      
      return this;
  }
docs: PRIVATE CLASSES