<commit_before>package com.nrinaudo.csv

import simulacrum.typeclass

object CellReader {
  def apply[A](f: String => A): CellReader[A] = new CellReader[A] {
    override def read(a: String) = f(a)
  }

  implicit val string: CellReader[String]  = apply(s => s)
  implicit val int   : CellReader[Int]     = apply(_.toInt)
  implicit val float : CellReader[Float]   = apply(_.toFloat)
  implicit val double: CellReader[Double]  = apply(_.toDouble)
  implicit val long  : CellReader[Long]    = apply(_.toLong)
  implicit val short : CellReader[Short]   = apply(_.toShort)
  implicit val byte  : CellReader[Byte]    = apply(_.toByte)
  implicit val bool  : CellReader[Boolean] = apply(_.toBoolean)
}

@typeclass trait CellReader[A] {
  def read(a: String): A
}<commit_msg>Document CellReader.<commit_after>package com.nrinaudo.csv

import simulacrum.typeclass

/** Provides default implementations and construction methods for {{{CellReader}}}. */
object CellReader {
  /** Creates a new instance of {{{CellReader}}} that uses the specified function to parse data. */
  def apply[A](f: String => A): CellReader[A] = new CellReader[A] {
    override def read(a: String) = f(a)
  }

  implicit val string: CellReader[String]  = apply(s => s)
  implicit val int   : CellReader[Int]     = apply(_.toInt)
  implicit val float : CellReader[Float]   = apply(_.toFloat)
  implicit val double: CellReader[Double]  = apply(_.toDouble)
  implicit val long  : CellReader[Long]    = apply(_.toLong)
  implicit val short : CellReader[Short]   = apply(_.toShort)
  implicit val byte  : CellReader[Byte]    = apply(_.toByte)
  implicit val bool  : CellReader[Boolean] = apply(_.toBoolean)
}

/** Typeclass used to reader the content of a single CSV cell.
  *
  * Standard types are already provided for in the companion object.
  *
  * See also the companion class, {{{CellWriter}}}, as well as {{{RowReader}}}, used to read wholes rows.
  */
@typeclass trait CellReader[A] {
  /** Turns the content of a CSV cell into an {{{A}}}. */
  def read(a: String): A

  /** Creates a new {{{CellReader}}} that applies the specified function to the result of {{{read}}}.
    *
    * This can be useful if you just need a {{{CellReader}}} implementation that specialises an existing type - to add
    * a scalaz tag, say.
    */
  def map[B](f: A => B): CellReader[B] = CellReader(str => f(read(str)))
}
{'fraction_non_alphanumeric': 0.12763268744734624, 'fraction_numerical': 0.0, 'mean_word_length': 3.8568507157464214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1457041', 'n_tokens_mistral': 748, 'n_tokens_neox': 754, 'n_words': 244}