Iterates through an Collection,
passing each item and the item's index (a counter starting at
zero) to the given closure.

@param self    an Collection
@param closure a Closure to operate on each item
@return the self Collection
@since 2.4.0
169311
public static <T> Collection<T> eachWithIndex(Collection<T> self, @ClosureParams(value=FromString.class, options="T,Integer") Closure closure) {
        return (Collection<T>) eachWithIndex((Iterable<T>) self, closure);
    }
36711
function each(collection, iterator, context) {
  var i = 0;

  if ('array' === type(collection)) {
    for (; i < collection.length; i++) {
      if (false === iterator.call(context || iterator, collection[i], i, collection)) {
        return; // If false is returned by the callback we need to bail out.
      }
    }
  } else {
    for (i in collection) {
      if (hasOwn.call(collection, i)) {
        if (false === iterator.call(context || iterator, collection[i], i, collection)) {
          return; // If false is returned by the callback we need to bail out.
        }
      }
    }
  }
}
938003
public static Thread start(Thread self, Closure closure) {
        return createThread(null, false, closure);
    }
46216
public static <T extends Closure<?>> T instantiateClosure(Class<T> closureType, Object owner, Object thisObject) {
    try {
      Constructor<T> constructor = closureType.getConstructor(Object.class, Object.class);
      return constructor.newInstance(owner, thisObject);
    } catch (Exception e) {
      ExceptionUtil.sneakyThrow(e.getCause());
      return null; // never reached
    }
  }
1188136
public function items($items)
    {
        if ($items instanceof Closure) {
            $items = $items();
        }

        array_map(array($this, 'item'), (array) $items);

        return $this;
    }
356407
public static Iterator iterator(final DefaultTableModel self) {
        return new Iterator() {
            private int row = 0;

            public boolean hasNext() {
                return row > -1 && row < self.getRowCount();
            }

            public Object next() {
                int cols = self.getColumnCount();
                Object[] rowData = new Object[cols];
                for (int col = 0; col < cols; col++) {
                    rowData[col] = self.getValueAt(row, col);
                }
                row++;
                return rowData;
            }

            public void remove() {
                if (hasNext()) self.removeRow(row--);
            }
        };
    }
307206
public function each(Closure $closure)
    {
        foreach ($this->stack as &$item) {
            $closure($item);
        }

        return $this;
    }
879714
function Iterator() {
    var items = Array.prototype.slice.call(arguments, 0);

    this.items = (items.length == 1 && Array.isArray(items[0])) ? items[0] : items;
    this.reset();
}
629967
@SuppressWarnings("unchecked")
    public static Iterator<TreeNode> iterator(TreeNode self) {
        return (Iterator<TreeNode>) DefaultGroovyMethods.iterator(self.children());
    }
1466
public static <T> Set<T> toSet(Enumeration<T> self) {
        Set<T> answer = new HashSet<T>();
        while (self.hasMoreElements()) {
            answer.add(self.nextElement());
        }
        return answer;
    }
1346802
function(collection){
	Array.apply(this);
	if(arguments.length >= 1){
		for(var i=0,len = collection.length;i<len;i++){
			var item = collection[i];
			if(this.indexOf(item) < 0){
				this.push(item);
			}
		}
	}
 }
1269810
@Deprecated
    public static List collectAll(Collection self, Closure transform) {
        return collectNested(self, transform);
    }
1218005
public <T> T get(String name, Closure<String,T> closure){
        T obj = null;
        lock(name);
        try {
            obj = (T)cache.get(name);
            if(obj!=null){
                if(ttl>0 && (created.get(name)+tu.toMillis(ttl)<System.currentTimeMillis())){
                    //invalidate
                    obj = null;
                }
            }
            if(obj!=null){
                gets.put(name, gets.get(name) + 1);
                return obj;
            }
        } finally {
            unlock(name);
        }

        //add obj
        obj = closure.call(name);

        lock(name);
        try {

            created.put(name,System.currentTimeMillis());
            gets.put(name, 1L);
            cache.put(name, obj);

        } finally {
            unlock(name);
        }
        checkSize();
        return obj;
    }
843726
public static <T> Iterator<T> toUnique(Iterator<T> self) {
        return toUnique(self, (Comparator<T>) null);
    }
1195405
public static void println(Closure self, Object value) {
        Object owner = getClosureOwner(self);
        InvokerHelper.invokeMethod(owner, "println", new Object[]{value});
    }
1016366
private static <E> Collection<E> toCollection(Iterable<E> iterable) {
		return (iterable instanceof Collection) ? (Collection<E>)iterable : Lists.newArrayList(iterable.iterator());
	}
888320
public static Iterator<Component> iterator(final JTabbedPane self) {
        return new Iterator<Component>() {
            private int index = 0;

            public boolean hasNext() {
                return index > -1 && index < self.getTabCount();
            }

            public Component next() {
                return self.getComponentAt(index++);
            }

            public void remove() {
                if (hasNext()) self.removeTabAt(index--);
            }
        };
    }