@Override public Array<T> padTo(int length, T element) { final int actualLength = length(); if (length <= actualLength) { return this; } else { return appendAll(Iterator.continually(element).take(length - actualLength)); } }
@Override public Array<Array<T>> permutations() { if (isEmpty()) { return empty(); } else if (delegate.length == 1) { return of(this); } else { final Array<Array<T>> zero = empty(); return distinct().foldLeft(zero, (xs, x) -> { final Function<Array<T>, Array<T>> prepend = l -> l.prepend(x); return xs.appendAll(remove(x).permutations().map(prepend)); }); } }
@Override public Array<T> padTo(int length, T element) { final int actualLength = length(); if (length <= actualLength) { return this; } else { return appendAll(Iterator.continually(element).take(length - actualLength)); } }
@Override public Array<Array<T>> permutations() { if (isEmpty()) { return empty(); } else if (delegate.length == 1) { return of(this); } else { final Array<Array<T>> zero = empty(); return distinct().foldLeft(zero, (xs, x) -> { final Function<Array<T>, Array<T>> prepend = l -> l.prepend(x); return xs.appendAll(remove(x).permutations().map(prepend)); }); } }