@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<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)); }); } }