<commit_before>package com.jmonad.seq;

import com.jmonad.seq.lambda.Action;
import com.jmonad.seq.lambda.BinaryFunction;
import com.jmonad.seq.lambda.Function;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;

public class Seq<T> implements Comparable<Seq<T>>, Iterable<T> {
  protected List<T> list;

  /**
   * DEPRECATED: This is a unsafe way to create a Seq. Will be removed in the future.
   * @param params The Params to initialize a List
   */
  @SafeVarargs
  @Deprecated
  public Seq(T... params) {
    this.list = new ArrayList<>(params.length);
    this.addAll(params);
  }

  /**
   * Creates a internal ArrayList and initialize it with the values of the argument list
   * @param list A list to initialize internal list.
   */
  public Seq(List<T> list) {
    this.list = new ArrayList<>(list.size());
    this.list.addAll(list);
  }

  /**
   * Add item to list
   * @param item The item to add
   * @return true if the item has been added.
   */
  public boolean add(T item) {
    return this.list.add(item);
  }

  /**
   * Adds all items in list to self.
   *
   * @param items A item list
   * @return true if all items were added.
   */
  public boolean addAll(List<T> items) {
    return this.list.addAll(items);
  }

  @SafeVarargs
  public final boolean addAll(T... params) {
    return Collections.addAll(this.list, params);
  }

  /**
   * Applies a function to each item in the list and returns the original list.
   * Used for side effects.
   * @param fn The function to apply
   * @return Seq<T> Self
   */
  public Seq<T> each(Action<T> fn) {
    for (T item : this.list) {
      fn.call(item);
    }
    return this;
  }

  /**
   * Applies a function to each item in the list, and produces a new list with
   * the results. The length of the result is the same length as the input.
   * @param fn The function to apply
   * @return Seq<T> A new Seq with the result of the mapping
   */
  public <Ret> Seq<Ret> map(Function<Ret, T> fn) {
    Seq<Ret> buffer = new Seq<>();
    for (T item : this.list) {
      buffer.add(fn.call(item));
    }
    return buffer;
  }

  public boolean some(Function<Boolean, T> fn) {
    Seq<Boolean> buffer = new Seq<>();
    for(T item : this.list) {
      if(fn.call(item)) return true;
    }
    return false;
  }

  /**
   * Returns a new list which contains only the truthy values of the inputted
   * list.
   * @return Seq<T> A new list
   */
  public Seq<T> compact() {
    Seq<T> buffer = new Seq<>();
    for (T item : this.list) {
      if (item != null && !item.equals(false)) {
        buffer.add(item);
      }
    }
    return buffer;
  }

  /**
   * Returns a new list composed of the items which pass the supplied
   * function's test.
   * @param fn The matching function
   * @return Seq<T> A new list with items that match fn
   */<commit_msg>Add some function description<commit_after>package com.jmonad.seq;

import com.jmonad.seq.lambda.Action;
import com.jmonad.seq.lambda.BinaryFunction;
import com.jmonad.seq.lambda.Function;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;

public class Seq<T> implements Comparable<Seq<T>>, Iterable<T> {
  protected List<T> list;

  /**
   * DEPRECATED: This is a unsafe way to create a Seq. Will be removed in the future.
   * @param params The Params to initialize a List
   */
  @SafeVarargs
  @Deprecated
  public Seq(T... params) {
    this.list = new ArrayList<>(params.length);
    this.addAll(params);
  }

  /**
   * Creates a internal ArrayList and initialize it with the values of the argument list
   * @param list A list to initialize internal list.
   */
  public Seq(List<T> list) {
    this.list = new ArrayList<>(list.size());
    this.list.addAll(list);
  }

  /**
   * Add item to list
   * @param item The item to add
   * @return true if the item has been added.
   */
  public boolean add(T item) {
    return this.list.add(item);
  }

  /**
   * Adds all items in list to self.
   *
   * @param items A item list
   * @return true if all items were added.
   */
  public boolean addAll(List<T> items) {
    return this.list.addAll(items);
  }

  @SafeVarargs
  public final boolean addAll(T... params) {
    return Collections.addAll(this.list, params);
  }

  /**
   * Applies a function to each item in the list and returns the original list.
   * Used for side effects.
   * @param fn The function to apply
   * @return Seq<T> Self
   */
  public Seq<T> each(Action<T> fn) {
    for (T item : this.list) {
      fn.call(item);
    }
    return this;
  }

  /**
   * Applies a function to each item in the list, and produces a new list with
   * the results. The length of the result is the same length as the input.
   * @param fn The function to apply
   * @return Seq<T> A new Seq with the result of the mapping
   */
  public <Ret> Seq<Ret> map(Function<Ret, T> fn) {
    Seq<Ret> buffer = new Seq<>();
    for (T item : this.list) {
      buffer.add(fn.call(item));
    }
    return buffer;
  }

  /**
   * Applies a boolean function to verify a case
   * in a list.
   * @param fn The function to apply
   * @return boolean The result of the list verifying
   */
  public boolean some(Function<Boolean, T> fn) {
    Seq<Boolean> buffer = new Seq<>();
    for(T item : this.list) {
      if(fn.call(item)) return true;
    }
    return false;
  }

  /**
   * Returns a new list which contains only the truthy values of the inputted
   * list.
   * @return Seq<T> A new list
   */
  public Seq<T> compact() {
    Seq<T> buffer = new Seq<>();
    for (T item : this.list) {
      if (item != null && !item.equals(false)) {
        buffer.add(item);
      }
    }
    return buffer;
  }

  /**
   * Returns a new list composed of the items which pass the supplied
   * function's test.
   * @param fn The matching function
   * @return Seq<T> A new list with items that match fn
   */
{'fraction_non_alphanumeric': 0.1163563829787234, 'fraction_numerical': 0.0, 'mean_word_length': 2.6622032866707244, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '2753979', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1954, 'n_words': 690}