guymers / ceesvee   1.0.1

MIT License GitHub

A CSV library designed for use with steams

Scala versions: 3.x 2.13

ceeSvee

A CSV library designed for use with steams. Can be used with Iterator, fs2.Stream and zio.stream.ZStream.

Supports the CSV format described by Model for Tabular Data and Metadata on the Web:

  • a new line can be \n or \r\n
  • a double quote is escaped by a double quote

Example

case class Test(
  str: String,
  int: Int,
  bool: Boolean,
  optInt: Option[Int],
)
object Test {
  implicit val decoder: CsvRecordDecoder[Test] = CsvRecordDecoder.derive
  val header = ::("str", List("int", "bool", "opt_int"))
  val csvHeader = CsvHeader.create(header)(decoder)
}

Iterator

val input: Iterator[String]
val result: Either[CsvHeader.MissingHeaders, Iterator[Either[CsvRecordDecoder.Error, Test]]] =
  CsvParser.decodeWithHeader(input, Test.csvHeader, options)

fs2

val stream: fs2.Stream[F[?], String]
val result: fs2.Stream[F[?], Either[CsvRecordDecoder.Error, Test]] = stream.through {
  Fs2CsvParser.decodeWithHeader(Test.csvHeader, options)
}

zio

val stream: zio.stream.ZStream[R, E, String]
val result: zio.ZIO[
  Scope & R,
  Either[Either[E, CsvParser.Error], CsvHeader.MissingHeaders],
  zio.stream.ZStream[E, Either[E, CsvParser.Error], Either[CsvRecordDecoder.Error, Test]]
] = ZioCsvParser.decodeWithHeader(stream, Test.csvHeader, options)