<commit_before>package peergos.shared.util;

import jsinterop.annotations.*;

import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;

public class Futures {

    @JsMethod
    public static final <T> CompletableFuture<T> of(T val) {
        return CompletableFuture.completedFuture(val);
    }

    /**
     *
     * @param futures collection of independent futures whose results we want to combine
     * @param <T> result type of each future
     * @return
     */
    public static <T> CompletableFuture<Set<T>> combineAll(Collection<CompletableFuture<T>> futures) {
        CompletableFuture<Set<T>> identity = CompletableFuture.completedFuture(Collections.emptySet());
        return futures.stream().reduce(identity,
                (a, b) -> b.thenCompose(opt ->
                        a.thenApply(set -> Stream.concat(set.stream(), Stream.of(opt))
                                .collect(Collectors.toSet()))),
                (a, b) -> b.thenCompose(setb ->
                        a.thenApply(seta -> Stream.concat(seta.stream(), setb.stream()).collect(Collectors.toSet()))));
    }<commit_msg>remove JsMethod annotation on Future.of()<commit_after>package peergos.shared.util;

import jsinterop.annotations.*;

import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;

public class Futures {

    public static final <T> CompletableFuture<T> of(T val) {
        return CompletableFuture.completedFuture(val);
    }

    /**
     *
     * @param futures collection of independent futures whose results we want to combine
     * @param <T> result type of each future
     * @return
     */
    public static <T> CompletableFuture<Set<T>> combineAll(Collection<CompletableFuture<T>> futures) {
        CompletableFuture<Set<T>> identity = CompletableFuture.completedFuture(Collections.emptySet());
        return futures.stream().reduce(identity,
                (a, b) -> b.thenCompose(opt ->
                        a.thenApply(set -> Stream.concat(set.stream(), Stream.of(opt))
                                .collect(Collectors.toSet()))),
                (a, b) -> b.thenCompose(setb ->
                        a.thenApply(seta -> Stream.concat(seta.stream(), setb.stream()).collect(Collectors.toSet()))));
    }
{'fraction_non_alphanumeric': 0.13304721030042918, 'fraction_numerical': 0.0, 'mean_word_length': 2.659340659340659, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7303580', 'n_tokens_mistral': 676, 'n_tokens_neox': 647, 'n_words': 141}