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.
- Self Type
- CsvSource[S]
- Source
- CsvSource.scala
- Alphabetic
- By Inheritance
- CsvSource
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def open(s: S): ParseResult[Reader]
Turns the specified
S
into aReader
.Turns the specified
S
into aReader
.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.
- s
instance of
S
to turn into a CsvSource.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def contramap[T](f: (T) => S): CsvSource[T]
Turns an instance of
CsvSource[S]
into one ofCsvSource[T]
.Turns an instance of
CsvSource[S]
into one ofCsvSource[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
toS
is safe. If it fail, one should use econtramap instead.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))
- See also
Example: - def econtramap[SS <: S, T](f: (T) => ParseResult[SS]): CsvSource[T]
Turns an instance of
CsvSource[S]
into one ofCsvSource[T]
.Turns an instance of
CsvSource[S]
into one ofCsvSource[T]
.This allows developers to adapt existing instances of CsvSource rather than write new ones from scratch.
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
toS
is safe, it's better to use contramap and bypass the error handling mechanism altogether.- See also
Example: - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def read[C[_], A](s: S, conf: CsvConfiguration)(implicit arg0: 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.
- C
collection type in which to parse the specified
S
.- A
type in which to parse each row.
- s
instance of
S
that will be opened an parsed.- conf
CSV parsing behaviour.
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)))
Example: - def reader[A](s: S, conf: CsvConfiguration)(implicit arg0: HeaderDecoder[A], e: ReaderEngine): CsvReader[ReadResult[A]]
Turns the specified
S
into an iterator onReadResult[A]
.Turns the specified
S
into an iterator onReadResult[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.
- A
type to parse each row as. This must have a corresponding implicit HeaderDecoder instance in scope.
- s
instance of
S
that will be opened an parsed.- conf
CSV parsing behaviour.
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)))
Example: - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unsafeRead[C[_], A](s: S, conf: CsvConfiguration)(implicit arg0: 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.
- C
collection type in which to parse the specified
S
.- A
type in which to parse each row.
- s
instance of
S
that will be opened an parsed.- conf
CSV parsing behaviour.
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))
Example: - def unsafeReader[A](s: S, conf: CsvConfiguration)(implicit arg0: HeaderDecoder[A], engine: ReaderEngine): CsvReader[A]
Turns the specified
S
into an iterator onA
.Turns the specified
S
into an iterator onA
.This is the "unsafe" version of reader: it will throw as soon as an error is encountered.
- A
type to parse each row as. This must have a corresponding implicit HeaderDecoder instance in scope.
- s
instance of
S
that will be opened an parsed.- conf
CSV parsing behaviour.
- Annotations
- @SuppressWarnings()
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))
Example: - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Deprecated Value Members
- def contramapResult[SS <: S, T](f: (T) => ParseResult[SS]): CsvSource[T]
- Annotations
- @deprecated
- Deprecated
(Since version 0.3.2) Use econtramap instead
- def read[C[_], A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], e: ReaderEngine, factory: Factory[ReadResult[A], C[ReadResult[A]]]): C[ReadResult[A]]
- Annotations
- @deprecated
- Deprecated
(Since version 0.1.18) use read(S, CsvConfiguration) instead
- def reader[A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], e: ReaderEngine): CsvReader[ReadResult[A]]
- Annotations
- @deprecated
- Deprecated
(Since version 0.1.18) use reader(S, CsvConfiguration) instead
- def unsafeRead[C[_], A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], e: ReaderEngine, factory: Factory[A, C[A]]): C[A]
- Annotations
- @deprecated
- Deprecated
(Since version 0.1.18) use unsafeRead(S, CsvConfiguration) instead
- def unsafeReader[A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], engine: ReaderEngine): CsvReader[A]
- Annotations
- @deprecated
- Deprecated
(Since version 0.1.18) use unsafeReader(S, CsvConfiguration) instead