@Override public Array<T> slice(long beginIndex, long endIndex) { if (beginIndex >= endIndex || beginIndex >= length() || isEmpty()) { return empty(); } if (beginIndex <= 0 && endIndex >= length()) { return this; } final int index = Math.max((int) beginIndex, 0); final int length = Math.min((int) endIndex, length()) - index; final Object[] arr = new Object[length]; System.arraycopy(delegate, index, arr, 0, length); return wrap(arr); }
@Override public Vector<Vector<T>> combinations(int k) { class Recursion { Vector<Vector<T>> combinations(Vector<T> elements, int k) { return (k == 0) ? Vector.of(Vector.empty()) : elements .zipWithIndex() .flatMap( t -> combinations(elements.drop(t._2 + 1), (k - 1)) .map((Vector<T> c) -> c.prepend(t._1))); } } return new Recursion().combinations(this, Math.max(k, 0)); }
@Override public Array<Array<T>> combinations(int k) { return Combinations.apply(this, Math.max(k, 0)); }