<commit_before>package strawman.collection

import Predef.{augmentString => _, wrapString => _, _}
import scala.reflect.ClassTag
import annotation.unchecked.uncheckedVariance
import annotation.tailrec

/* ------------ Base Traits -------------------------------- */

/** Iterator can be used only once */
trait IterableOnce[+A] {
  def iterator: Iterator[A]
}

/** Base trait for instances that can construct a collection from an iterable */
trait FromIterable[+C[X] <: Iterable[X]] {
  def fromIterable[B](it: Iterable[B]): C[B]
}

/** Base trait for companion objects of collections */
trait IterableFactory[+C[X] <: Iterable[X]] extends FromIterable[C] {
  def empty[X]: C[X] = fromIterable(View.Empty)
  def apply[A](xs: A*): C[A] = fromIterable(View.Elems(xs: _*))
}

/** Base trait for generic collections */
trait Iterable[+A] extends IterableOnce[A] with IterableLike[A, Iterable] {
  /** The collection itself */
  protected def coll: this.type = this
}

/** A trait representing indexable collections with finite length */
trait ArrayLike[+A] extends Any {
  def length: Int
  def apply(i: Int): A
}

/** Base trait for sequence collections */
trait Seq[+A] extends Iterable[A] with SeqLike[A, Seq] with ArrayLike[A]

/** Base trait for linearly accessed sequences that have efficient `head` and
 *  `tail` operations.
 *  Known subclasses: List, LazyList
 */
trait LinearSeq[+A] extends Seq[A] with LinearSeqLike[A, LinearSeq] { self =>

  /** To be overridden in implementations: */
  def isEmpty: Boolean
  def head: A
  def tail: LinearSeq[A]

  /** `iterator` is overridden in terms of `head` and `tail` */
  def iterator = new Iterator[A] {
    private[this] var current: Seq[A] = self
    def hasNext = !current.isEmpty
    def next = { val r = current.head; current = current.tail; r }
  }

  /** `length is defined in terms of `iterator` */
  def length: Int = iterator.length

  /** `apply` is defined in terms of `drop`, which is in turn defined in
   *  terms of `tail`.
   */
  override def apply(n: Int): A = {
    if (n < 0) throw new IndexOutOfBoundsException(n.toString)
    val skipped = drop(n)
    if (skipped.isEmpty) throw new IndexOutOfBoundsException(n.toString)
    skipped.head
  }
}

trait IndexedSeq[+A] extends Seq[A] { self =>
  override def view: IndexedView[A] = new IndexedView[A] {
    def length: Int = self.length
    def apply(i: Int): A = self(i)
  }
}

/** Base trait for strict collections that can be built using a builder.<commit_msg>little documentation fix<commit_after>package strawman.collection

import Predef.{augmentString => _, wrapString => _, _}
import scala.reflect.ClassTag
import annotation.unchecked.uncheckedVariance
import annotation.tailrec

/* ------------ Base Traits -------------------------------- */

/** Iterator can be used only once */
trait IterableOnce[+A] {
  def iterator: Iterator[A]
}

/** Base trait for instances that can construct a collection from an iterable */
trait FromIterable[+C[X] <: Iterable[X]] {
  def fromIterable[B](it: Iterable[B]): C[B]
}

/** Base trait for companion objects of collections */
trait IterableFactory[+C[X] <: Iterable[X]] extends FromIterable[C] {
  def empty[X]: C[X] = fromIterable(View.Empty)
  def apply[A](xs: A*): C[A] = fromIterable(View.Elems(xs: _*))
}

/** Base trait for generic collections */
trait Iterable[+A] extends IterableOnce[A] with IterableLike[A, Iterable] {
  /** The collection itself */
  protected def coll: this.type = this
}

/** A trait representing indexable collections with finite length */
trait ArrayLike[+A] extends Any {
  def length: Int
  def apply(i: Int): A
}

/** Base trait for sequence collections */
trait Seq[+A] extends Iterable[A] with SeqLike[A, Seq] with ArrayLike[A]

/** Base trait for linearly accessed sequences that have efficient `head` and
 *  `tail` operations.
 *  Known subclasses: List, LazyList
 */
trait LinearSeq[+A] extends Seq[A] with LinearSeqLike[A, LinearSeq] { self =>

  /** To be overridden in implementations: */
  def isEmpty: Boolean
  def head: A
  def tail: LinearSeq[A]

  /** `iterator` is overridden in terms of `head` and `tail` */
  def iterator = new Iterator[A] {
    private[this] var current: Seq[A] = self
    def hasNext = !current.isEmpty
    def next = { val r = current.head; current = current.tail; r }
  }

  /** `length` is defined in terms of `iterator` */
  def length: Int = iterator.length

  /** `apply` is defined in terms of `drop`, which is in turn defined in
   *  terms of `tail`.
   */
  override def apply(n: Int): A = {
    if (n < 0) throw new IndexOutOfBoundsException(n.toString)
    val skipped = drop(n)
    if (skipped.isEmpty) throw new IndexOutOfBoundsException(n.toString)
    skipped.head
  }
}

trait IndexedSeq[+A] extends Seq[A] { self =>
  override def view: IndexedView[A] = new IndexedView[A] {
    def length: Int = self.length
    def apply(i: Int): A = self(i)
  }
}

/** Base trait for strict collections that can be built using a builder.
{'fraction_non_alphanumeric': 0.14145264847512037, 'fraction_numerical': 0.0004012841091492777, 'mean_word_length': 3.5775941230486685, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4262598', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1578, 'n_words': 529}