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 AtomicReferenceArray array = new AtomicReferenceArray(this.adapter.array());
final Folder<T> folder = new Folder<T>(this) {
@Override
public void handle(int i, int j, int destination) {
// Get the in-value from the source-array
final T ii = (T) array.get(i);
final T jj = (T) array.get(j);
if (ii == null && jj == null) return;
if (ii == null && jj != null) {
array.set(destination, jj);
return;
}
if (ii != null && jj == null) {
array.set(destination, ii);
return;
}
array.set(destination, f.f(ii, jj));
}
};
// Now do fold ...
fold(folder, options);
T[] target = (T[]) Array.newInstance(this.adapter.clazz(), 1); // Arrays.copyOf(this.t, 1);
target[0] = (T) array.get(0);
// ... and return result.
return new CoreObject<T>(this.commonCore, target);
}