CsvSource

kantan.csv.CsvSource
See theCsvSource companion object
trait CsvSource[-S] extends Serializable

Turns instances of S into valid sources of CSV data.

Instances of CsvSource are rarely used directly. The preferred, idiomatic way is to use the implicit syntax provided by CsvSourceOps, brought in scope by importing kantan.csv.ops._.

See the companion object for default implementations and construction methods.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
class Object
trait Matchable
class Any
Self type

Members list

Value members

Abstract methods

def open(s: S): ParseResult[Reader]

Turns the specified S into a Reader.

Turns the specified S into a Reader.

Implementations of this method must be safe: all non-fatal exceptions should be caught and wrapped in an ParseError.IOError. This is easily achieved by wrapping unsafe code in a call to ParseResult.apply.

Value parameters

s

instance of S to turn into a CsvSource.

Attributes

Concrete methods

def contramap[T](f: T => S): CsvSource[T]

Turns an instance of CsvSource[S] into one of CsvSource[T].

Turns an instance of CsvSource[S] into one of CsvSource[T].

This allows developers to adapt existing instances of CsvSource rather than write new ones from scratch.

Note that this method assumes that the transformation from T to S is safe. If it fail, one should use econtramap instead.

Attributes

See also
Example
scala> case class StringWrapper(value: String)
scala> implicit val wrapperSource: CsvSource[StringWrapper] = CsvSource[String].contramap(_.value)
scala> CsvSource[StringWrapper].unsafeRead[List, List[Int]](StringWrapper("1,2,3\n4,5,6"), rfc)
res0: List[List[Int]] = List(List(1, 2, 3), List(4, 5, 6))
def econtramap[SS <: S, T](f: T => ParseResult[SS]): CsvSource[T]

Turns an instance of CsvSource[S] into one of CsvSource[T].

Turns an instance of CsvSource[S] into one of CsvSource[T].

This allows developers to adapt existing instances of CsvSource rather than write new ones from scratch.

Attributes

See also
Example
scala> case class StringWrapper(value: String)
scala> implicit val source: CsvSource[StringWrapper] = CsvSource[String].econtramap(s => ParseResult(s.value))
scala> CsvSource[StringWrapper].unsafeRead[List, List[Int]](StringWrapper("1,2,3\n4,5,6"), rfc)
res0: List[List[Int]] = List(List(1, 2, 3), List(4, 5, 6))

Note that if the transformation from T to S is safe, it's better to use contramap and bypass the error handling mechanism altogether.

def read[C[_], A : HeaderDecoder](s: S, conf: CsvConfiguration)(implicit evidence$1: HeaderDecoder[A], e: ReaderEngine, factory: Factory[ReadResult[A], C[ReadResult[A]]]): C[ReadResult[A]]

Reads the entire CSV data into a collection.

Reads the entire CSV data into a collection.

This method is "safe", in that it does not throw exceptions when errors are encountered. This comes with the small cost of having each row wrapped in a ReadResult that then need to be unpacked. See unsafeRead for an alternative.

Type parameters

A

type in which to parse each row.

C

collection type in which to parse the specified S.

Value parameters

conf

CSV parsing behaviour.

s

instance of S that will be opened an parsed.

Attributes

Example
scala> CsvSource[String].read[List, List[Int]]("1,2,3\n4,5,6", rfc)
res0: List[ReadResult[List[Int]]] = List(Right(List(1, 2, 3)), Right(List(4, 5, 6)))
def reader[A : HeaderDecoder](s: S, conf: CsvConfiguration)(implicit evidence$1: HeaderDecoder[A], e: ReaderEngine): ResourceIterator[ReadResult[A]]

Turns the specified S into an iterator on ReadResult[A].

Turns the specified S into an iterator on ReadResult[A].

This method is "safe", in that it does not throw exceptions when errors are encountered. This comes with the small cost of having each row wrapped in a ReadResult that then need to be unpacked. See unsafeReader for an alternative.

Type parameters

A

type to parse each row as. This must have a corresponding implicit HeaderDecoder instance in scope.

Value parameters

conf

CSV parsing behaviour.

s

instance of S that will be opened an parsed.

Attributes

Example
scala> CsvSource[String].reader[List[Int]]("1,2,3\n4,5,6", rfc).toList
res0: List[ReadResult[List[Int]]] = List(Right(List(1, 2, 3)), Right(List(4, 5, 6)))
def unsafeRead[C[_], A : HeaderDecoder](s: S, conf: CsvConfiguration)(implicit evidence$1: HeaderDecoder[A], e: ReaderEngine, factory: Factory[A, C[A]]): C[A]

Reads the entire CSV data into a collection.

Reads the entire CSV data into a collection.

This is the "unsafe" version of read: it will throw as soon as an error is encountered.

Type parameters

A

type in which to parse each row.

C

collection type in which to parse the specified S.

Value parameters

conf

CSV parsing behaviour.

s

instance of S that will be opened an parsed.

Attributes

Example
scala> CsvSource[String].unsafeRead[List, List[Int]]("1,2,3\n4,5,6", rfc)
res0: List[List[Int]] = List(List(1, 2, 3), List(4, 5, 6))
def unsafeReader[A : HeaderDecoder](s: S, conf: CsvConfiguration)(implicit evidence$1: HeaderDecoder[A], engine: ReaderEngine): ResourceIterator[A]

Turns the specified S into an iterator on A.

Turns the specified S into an iterator on A.

This is the "unsafe" version of reader: it will throw as soon as an error is encountered.

Type parameters

A

type to parse each row as. This must have a corresponding implicit HeaderDecoder instance in scope.

Value parameters

conf

CSV parsing behaviour.

s

instance of S that will be opened an parsed.

Attributes

Example
scala> CsvSource[String].unsafeReader[List[Int]]("1,2,3\n4,5,6", rfc).toList
res0: List[List[Int]] = List(List(1, 2, 3), List(4, 5, 6))

Deprecated methods

def contramapResult[SS <: S, T](f: T => ParseResult[SS]): CsvSource[T]

Attributes

Deprecated
true
def read[C[_], A : HeaderDecoder](s: S, sep: Char, header: Boolean)(implicit evidence$1: HeaderDecoder[A], e: ReaderEngine, factory: Factory[ReadResult[A], C[ReadResult[A]]]): C[ReadResult[A]]

Attributes

Deprecated
true
def reader[A : HeaderDecoder](s: S, sep: Char, header: Boolean)(implicit evidence$1: HeaderDecoder[A], e: ReaderEngine): ResourceIterator[ReadResult[A]]

Attributes

Deprecated
true
def unsafeRead[C[_], A : HeaderDecoder](s: S, sep: Char, header: Boolean)(implicit evidence$1: HeaderDecoder[A], e: ReaderEngine, factory: Factory[A, C[A]]): C[A]

Attributes

Deprecated
true
def unsafeReader[A : HeaderDecoder](s: S, sep: Char, header: Boolean)(implicit evidence$1: HeaderDecoder[A], engine: ReaderEngine): ResourceIterator[A]

Attributes

Deprecated
true