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
Members list
Value members
Abstract methods
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
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))
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
toS
is safe, it's better to use contramap and bypass the error handling mechanism altogether.
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)))
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)))
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))
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
Attributes
- Deprecated
- true
Attributes
- Deprecated
- true
Attributes
- Deprecated
- true
Attributes
- Deprecated
- true
Attributes
- Deprecated
- true