<commit_before>package se.gigurra.franklin

import Collection.Data
import scala.concurrent.{ExecutionContext, Future}
import ExecutionContext.Implicits.global


/**
  * Created by johan on 2015-12-23.
  */
trait Collection {

  def createUniqueIndex(fieldName: String): Future[Unit]

  def find(selector: Data): Future[Seq[Item]]

  def create(data: Data): Future[Unit]
  def loadOrCreate(selector: Data, ctor: () => Data): Future[Item]

  def update(selector: Data, data: Data, upsert: Boolean = false, expectVersion: Long = -1L): Future[Unit]
  def append(selector: Data, data: Data, defaultValue: () => Data): Future[Unit]

  def size(selector: Data): Future[Int]
  def isEmpty(selector: Data): Future[Boolean] = size(selector).map(_ == 0)
  def nonEmpty(selector: Data): Future[Boolean] = size(selector).map(_ != 0)

  ///////////////////////////
  // Convenience methods

  case class where(statements: (String, Any)*) {
    val selector = statements.toMap

    def find: Future[Seq[Item]] = Collection.this.find(selector)
    def update(data: Data, upsert: Boolean = false, expectVersion: Long = -1L): Future[Unit] = Collection.this.update(selector, data, upsert, expectVersion)
    def loadOrCreate(ctor: () => Data): Future[Item] = Collection.this.loadOrCreate(selector, ctor)
    def append(data: Data, defaultValue: () => Data): Future[Unit] = Collection.this.append(selector, data, defaultValue)
    def append(field: String, items: Seq[Any], defaultValue: () => Data): Future[Unit] = Collection.this.append(selector, Map(field -> items), defaultValue)
    def size: Future[Int] = Collection.this.size(statements.toMap)
    def isEmpty: Future[Boolean] = Collection.this.isEmpty(statements.toMap)
    def nonEmpty: Future[Boolean] = Collection.this.nonEmpty(statements.toMap)
  }
<commit_msg>cleanup<commit_after>package se.gigurra.franklin

import Collection.Data
import scala.concurrent.{ExecutionContext, Future}
import ExecutionContext.Implicits.global


/**
  * Created by johan on 2015-12-23.
  */
trait Collection {

  def createUniqueIndex(fieldName: String): Future[Unit]

  def find(selector: Data): Future[Seq[Item]]

  def create(data: Data): Future[Unit]
  def loadOrCreate(selector: Data, ctor: () => Data): Future[Item]

  def update(selector: Data, data: Data, upsert: Boolean = false, expectVersion: Long = -1L): Future[Unit]
  def append(selector: Data, data: Data, defaultValue: () => Data): Future[Unit]

  def size(selector: Data): Future[Int]

  
  ///////////////////////////
  // Convenience methods

  case class where(statements: (String, Any)*) {
    val selector = statements.toMap

    def find: Future[Seq[Item]] = Collection.this.find(selector)
    def update(data: Data, upsert: Boolean = false, expectVersion: Long = -1L): Future[Unit] = Collection.this.update(selector, data, upsert, expectVersion)
    def loadOrCreate(ctor: () => Data): Future[Item] = Collection.this.loadOrCreate(selector, ctor)
    def append(data: Data, defaultValue: () => Data): Future[Unit] = Collection.this.append(selector, data, defaultValue)
    def append(field: String, items: Seq[Any], defaultValue: () => Data): Future[Unit] = Collection.this.append(selector, Map(field -> items), defaultValue)
    def size: Future[Int] = Collection.this.size(statements.toMap)
    def isEmpty: Future[Boolean] = Collection.this.isEmpty(statements.toMap)
    def nonEmpty: Future[Boolean] = Collection.this.nonEmpty(statements.toMap)
  }

  def isEmpty(selector: Data): Future[Boolean] = size(selector).map(_ == 0)
  def nonEmpty(selector: Data): Future[Boolean] = size(selector).map(_ != 0)

{'fraction_non_alphanumeric': 0.15427302996670367, 'fraction_numerical': 0.006659267480577136, 'mean_word_length': 4.65934065934066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7053919', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1078, 'n_words': 274}