<commit_before><commit_msg>Added ImmutableCollectors<commit_after>package eu.goodlike.functional;

import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import java.util.List;
import java.util.Set;
import java.util.stream.Collector;

/**
 * Collectors for immutable collections from Guava
 */
public final class ImmutableCollectors {

    /**
     * @return collects Stream into an ImmutableList
     */
    public static <T> Collector<T, ImmutableList.Builder<T>, List<T>> toList() {
        return Collector.of(ImmutableList::builder, ImmutableList.Builder::add, ImmutableCollectors::combine, ImmutableList.Builder::build);
    }

    /**
     * @return collects Stream into an ImmutableSet
     */
    public static <T> Collector<T, ImmutableSet.Builder<T>, Set<T>> toSet() {
        return Collector.of(ImmutableSet::builder, ImmutableSet.Builder::add, ImmutableCollectors::combine, ImmutableSet.Builder::build);
    }

    // PRIVATE

    private ImmutableCollectors() {
        throw new AssertionError("Do not instantiate, use static methods!");
    }

    private static <T, B extends ImmutableCollection.Builder<T>> B combine(B left, B right) {
        @SuppressWarnings("unchecked")
        B builder = (B) left.addAll(right.build());
        return builder;
    }

}
{'fraction_non_alphanumeric': 0.11653313911143481, 'fraction_numerical': 0.0, 'mean_word_length': 4.014598540145985, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4553975', 'n_tokens_mistral': 406, 'n_tokens_neox': 397, 'n_words': 90}