<commit_before>package com.andreapivetta.minifunk;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A sequence of elements supporting different aggregate operations.
 *
 * @author <NAME>
 */
public final class Enumerable<T> {

    private List<T> list;

    private Enumerable(List<T> list) {
        this.list = list;
    }

    /**
     * Creates an {@link Enumerable} instance from a List<T>
     *
     * @param list the starting list
     * @return the {@link Enumerable} instance
     */
    public static <T> Enumerable<T> from(List<T> list) {
        return new Enumerable<T>(list);
    }

    /**
     * Creates an {@link Enumerable} instance from an T[]
     *
     * @param array the starting array
     * @return the {@link Enumerable} instance
     */
    public static <T> Enumerable<T> from(T[] array) {
        return new Enumerable<T>(Arrays.asList(array));
    }

    /**
     * Returns a {@link List} from the current {@link Enumerable} instance
     *
     * @return the list
     */
    public List<T> asList() {
        return this.list;
    }

    /**
     * Performs the given action for each element of the {@link Enumerable} until all elements have been processed or
     * the action throws an exception. Exceptions thrown by the action are relayed to the caller.
     *
     * @param action the action to be performed for each element
     */
    public void forEach(Consumer<T> action) {
        for (T t : this.list)
            action.accept(t);
    }

    /**
     * Returns an {@link Enumerable} consisting of the elements of this {@link Enumerable} that match the given
     * predicate.
     *
     * @param predicate a predicate to apply to each element to determine if it should be included
     * @return the new {@link Enumerable}
     */
    public Enumerable<T> filter(Predicate<T> predicate) {
        List<T> filtered = new ArrayList<T>();
        for (T t : list)
            if (predicate.test(t))
                filtered.add(t);
        this.list = filtered;
        return this;
    }

    /**
     * Returns an {@link Enumerable} consisting of the results of applying the given function to the elements of this
     * {@link Enumerable}.
     *
     * @param mapper a function to apply to each element
     * @param <R>    The element type of the new {@link Enumerable}
     * @return the new {@link Enumerable}
     */
    public <R> Enumerable<R> map(Function<T, R> mapper) {
        List<R> result = new ArrayList<R>();
        for (T t : this.list)
            result.add(mapper.apply(t));
        return new Enumerable<R>(result);
    }
<commit_msg>filter returns a new Enumerable instance<commit_after>package com.andreapivetta.minifunk;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A sequence of elements supporting different aggregate operations.
 *
 * @author <NAME>
 */
public final class Enumerable<T> {

    private List<T> list;

    private Enumerable(List<T> list) {
        this.list = list;
    }

    /**
     * Creates an {@link Enumerable} instance from a List<T>
     *
     * @param list the starting list
     * @return the {@link Enumerable} instance
     */
    public static <T> Enumerable<T> from(List<T> list) {
        return new Enumerable<T>(list);
    }

    /**
     * Creates an {@link Enumerable} instance from an T[]
     *
     * @param array the starting array
     * @return the {@link Enumerable} instance
     */
    public static <T> Enumerable<T> from(T[] array) {
        return new Enumerable<T>(Arrays.asList(array));
    }

    /**
     * Returns a {@link List} from the current {@link Enumerable} instance
     *
     * @return the list
     */
    public List<T> asList() {
        return this.list;
    }

    /**
     * Performs the given action for each element of the {@link Enumerable} until all elements have been processed or
     * the action throws an exception. Exceptions thrown by the action are relayed to the caller.
     *
     * @param action the action to be performed for each element
     */
    public void forEach(Consumer<T> action) {
        for (T t : this.list)
            action.accept(t);
    }

    /**
     * Returns an {@link Enumerable} consisting of the elements of this {@link Enumerable} that match the given
     * predicate.
     *
     * @param predicate a predicate to apply to each element to determine if it should be included
     * @return the new {@link Enumerable}
     */
    public Enumerable<T> filter(Predicate<T> predicate) {
        List<T> filtered = new ArrayList<T>();
        for (T t : list)
            if (predicate.test(t))
                filtered.add(t);
        return new Enumerable<T>(filtered);
    }

    /**
     * Returns an {@link Enumerable} consisting of the results of applying the given function to the elements of this
     * {@link Enumerable}.
     *
     * @param mapper a function to apply to each element
     * @param <R>    The element type of the new {@link Enumerable}
     * @return the new {@link Enumerable}
     */
    public <R> Enumerable<R> map(Function<T, R> mapper) {
        List<R> result = new ArrayList<R>();
        for (T t : this.list)
            result.add(mapper.apply(t));
        return new Enumerable<R>(result);
    }

{'fraction_non_alphanumeric': 0.10702151755379388, 'fraction_numerical': 0.0, 'mean_word_length': 2.3859424920127794, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 54, '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': '6885873', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1504, 'n_words': 550}