public CoreObject<T> fold(final F2ReduceObjects<T> f, Option... options) {
// In case we only have zero or one elements, don't do anything
if (size() <= 1) return this;
final Folder folder = new Folder(null, size()) {
@Override
public void handle(int i, int j, int destination) {
// Get our target-array (if it is already there)
T[] a = (T[]) this.array.get();
// Get the in-value from the source-array
final T ii = a[i];
final T jj = a[j];
if (ii == null && jj == null) return;
if (ii == null && jj != null) {
a[destination] = jj;
return;
}
if (ii != null && jj == null) {
a[destination] = ii;
return;
}
a[destination] = f.f(ii, jj);
}
};
// Update the target array and fold ...
folder.updateArray(Arrays.copyOf(this.t, size()));
// Now do fold ...
fold(folder, options);
// ... and return result.
return new CoreObject<T>(this.commonCore, Arrays.copyOf((T[]) folder.getTargetArray(), 1));
}