public static <T> Collection<T> init(Iterable<T> self) {
        if (!self.iterator().hasNext()) {
            throw new NoSuchElementException("Cannot access init() for an empty Iterable");
        }
        Collection<T> result;
        if (self instanceof Collection) {
            Collection<T> selfCol = (Collection<T>) self;
            result = createSimilarCollection(selfCol, selfCol.size() - 1);
        } else {
            result = new ArrayList<T>();
        }
        addAll(result, init(self.iterator()));
        return result;
    }
public static < T > Collection < T > init ( Iterable < T > self ) { if ( ! self . iterator ( ) . hasNext ( ) ) { throw new NoSuchElementException ( "Cannot access init() for an empty Iterable" ) ; } Collection < T > result ; if ( self instanceof Collection ) { Collection < T > selfCol = ( Collection < T > ) self ; result = createSimilarCollection ( selfCol , selfCol . size ( ) - 1 ) ; } else { result = new ArrayList < T > ( ) ; } addAll ( result , init ( self . iterator ( ) ) ) ; return result ; }
Returns the items from the Iterable excluding the last item. Leaves the original Iterable unchanged.
<pre class="groovyTestCase">
def list = [3, 4, 2]
assert list.init() == [3, 4]
assert list == [3, 4, 2]
</pre>

@param self an Iterable
@return a Collection without its last element
@throws NoSuchElementException if the iterable is empty and you try to access init()
@since 2.4.0