@SafeVarargs
    public static <T> CompletableFuture<T> allOf(
        T defaultValue,
        BinaryOperator<T> merger, 
        CompletableFuture<T>... futures) {
        
        @SuppressWarnings("unchecked")
        final CompletableFuture<Void>[] accumulators 
            = (CompletableFuture<Void>[]) Array.newInstance(
                CompletableFuture.class, 
                futures.length
            );

        final AtomicReference<T> result = new AtomicReference<>(defaultValue);

        for (int i = 0; i < futures.length; i++) {
            final CompletableFuture<T> future = futures[i];
            accumulators[i] = future.thenAcceptAsync(r -> result.accumulateAndGet(r, merger));
        }
        
        return CompletableFuture.allOf(accumulators)
            .thenApplyAsync(v -> result.get());
    }
@author Simon Jonasson
@author Emil Forslund

@since 3.0.0
tool-parent/tool-core/src/main/java/com/speedment/tool/core/internal/util/CompletableFutureUtil.java