Trait/Object

kantan.csv

CsvSource

Related Docs: object CsvSource | package csv

Permalink

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]
Linear Supertypes
Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. CsvSource
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def open(s: S): ParseResult[Reader]

    Permalink

    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.

    s

    instance of S to turn into a CsvSource.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def contramap[T](f: (T) ⇒ S): CsvSource[T]

    Permalink

    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.

    For 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))

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

    See also

    contramapResult

  7. def contramapResult[SS <: S, T](f: (T) ⇒ ParseResult[SS]): CsvSource[T]

    Permalink

    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.

    For example:

    scala> case class StringWrapper(value: String)
    
    scala> implicit val source: CsvSource[StringWrapper] = CsvSource[String].contramapResult(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.

    See also

    contramap

  8. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. def read[C[_], A](s: S, conf: CsvConfiguration)(implicit arg0: HeaderDecoder[A], e: ReaderEngine, cbf: CanBuildFrom[Nothing, ReadResult[A], C[ReadResult[A]]]): C[ReadResult[A]]

    Permalink

    Reads the entire CSV data into a collection.

    Reads the entire CSV data into a collection.

    For example:

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

    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.

  18. def reader[A](s: S, conf: CsvConfiguration)(implicit arg0: HeaderDecoder[A], e: ReaderEngine): CsvReader[ReadResult[A]]

    Permalink

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

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

    For example:

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

    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.

  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  20. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  21. def unsafeRead[C[_], A](s: S, conf: CsvConfiguration)(implicit arg0: HeaderDecoder[A], e: ReaderEngine, cbf: CanBuildFrom[Nothing, A, C[A]]): C[A]

    Permalink

    Reads the entire CSV data into a collection.

    Reads the entire CSV data into a collection.

    For 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))

    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.

  22. def unsafeReader[A](s: S, conf: CsvConfiguration)(implicit arg0: HeaderDecoder[A], engine: ReaderEngine): CsvReader[A]

    Permalink

    Turns the specified S into an iterator on A.

    Turns the specified S into an iterator on A.

    For 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))

    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()
  23. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def read[C[_], A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], e: ReaderEngine, cbf: CanBuildFrom[Nothing, ReadResult[A], C[ReadResult[A]]]): C[ReadResult[A]]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.1.18) use read(S, CsvConfiguration) instead

  2. def reader[A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], e: ReaderEngine): CsvReader[ReadResult[A]]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.1.18) use reader(S, CsvConfiguration) instead

  3. def unsafeRead[C[_], A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], e: ReaderEngine, cbf: CanBuildFrom[Nothing, A, C[A]]): C[A]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.1.18) use unsafeRead(S, CsvConfiguration) instead

  4. def unsafeReader[A](s: S, sep: Char, header: Boolean)(implicit arg0: HeaderDecoder[A], engine: ReaderEngine): CsvReader[A]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.1.18) use unsafeReader(S, CsvConfiguration) instead

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped