<commit_before>package akashic.storage.service

object BucketListing {

  trait Filterable {
    def name: String
  }

  trait Container[T <: Filterable] {
    def get: T
  }
  case class Single[T <: Filterable](x: T) extends Container[T] {
    def get: T = x
    def prefixBy(delimiter: String): String = {
      val s = get.name
      s.indexOf(delimiter) match {
        case -1 => s
        case i => s.slice(0, i) + delimiter
      }
    }
  }
  case class Group[T <: Filterable](xs: Seq[Single[T]], prefix: String) extends Container[T] {
    require(xs.size > 0)
    val get: T = xs.last.get
    val size: Int = xs.size
  }

  implicit class Filtering[T <: Filterable](value: Seq[Single[T]]) {
    def takesOnlyAfter(lastName: Option[String]) = {
      lastName match {
        case Some(a) => value.dropWhile(_.get.name < a)
        case None => value
      }
    }

    def filterByPrefix(prefix: Option[String]) = {
      prefix match {
        case Some(a) => value.filter(_.get.name.startsWith(a))
        case None => value
      }
    }

    def dropWhile(fn: Single[T] => Boolean) = {
      value.dropWhile(fn)
    }
  }

  implicit class Grouping[T <: Filterable](value: Seq[Single[T]]) {
    def groupByDelimiter(delimiter: Option[String]): Seq[Container[T]] = {
      delimiter match {
        case Some(a) =>
          val deli = encodeKeyName(a)
          val newValue: Seq[Container[T]] = value
            .groupBy(_.prefixBy(deli)).toSeq // [prefix -> seq(contents)]
            .sortBy(_._1) // sort by prefix
            .map { case (prefix, members) =>
              if (members.size > 1) {<commit_msg>fix<commit_after>package akashic.storage.service

object BucketListing {

  trait Filterable {
    def name: String
  }

  trait Container[T <: Filterable] {
    def get: T
  }
  case class Single[T <: Filterable](x: T) extends Container[T] {
    def get: T = x
    def prefixBy(delimiter: String): String = {
      val s = get.name
      s.indexOf(delimiter) match {
        case -1 => s
        case i => s.slice(0, i) + delimiter
      }
    }
  }
  case class Group[T <: Filterable](xs: Seq[Single[T]], prefix: String) extends Container[T] {
    require(xs.size > 0)
    val get: T = xs.last.get
    val size: Int = xs.size
  }

  implicit class Filtering[T <: Filterable](value: Seq[Single[T]]) {
    def takesOnlyAfter(lastName: Option[String]) = {
      lastName match {
        case Some(a) => value.dropWhile(_.get.name <= a)
        case None => value
      }
    }

    def filterByPrefix(prefix: Option[String]) = {
      prefix match {
        case Some(a) => value.filter(_.get.name.startsWith(a))
        case None => value
      }
    }

    def dropWhile(fn: Single[T] => Boolean) = {
      value.dropWhile(fn)
    }
  }

  implicit class Grouping[T <: Filterable](value: Seq[Single[T]]) {
    def groupByDelimiter(delimiter: Option[String]): Seq[Container[T]] = {
      delimiter match {
        case Some(a) =>
          val deli = encodeKeyName(a)
          val newValue: Seq[Container[T]] = value
            .groupBy(_.prefixBy(deli)).toSeq // [prefix -> seq(contents)]
            .sortBy(_._1) // sort by prefix
            .map { case (prefix, members) =>
              if (members.size > 1) {
{'fraction_non_alphanumeric': 0.13836671802773498, 'fraction_numerical': 0.0030816640986132513, 'mean_word_length': 2.3156281920326864, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '5042146', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1078, 'n_words': 258}