kantan.csv

CsvReader

trait CsvReader[+A] extends TraversableOnce[A] with Closeable

Iterator on CSV rows.

Instances of CsvReader are commonly obtained through kantan.csv.ops.CsvInputOps.asCsvReader:

import kantan.csv.ops._

val file: File = ??? // some CSV file.
file.asCsvReader[List[Int]](',', true)

CsvReader provides most of the common Scala collection operations, such as map or filter. However, working with a CsvReader of ReadResult is a very common pattern that doesn't lend itself well to using such combinators: mapping on each row would require first mapping into the CsvReader, then into each ReadResult, which is cumbersome and not terribly clear.

kantan.csv provides syntax for this pattern with kantan.csv.ops.CsvReaderOps: filtering into a result, for example, is made easier by kantan.csv.ops.CsvReaderOps.filterResult

import kantan.csv.ops._

file.asCsvReader[List[Int]](',', true).filterResult(_ % 2 == 0)
Self Type
CsvReader[A]
Linear Supertypes
Closeable, AutoCloseable, TraversableOnce[A], GenTraversableOnce[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. CsvReader
  2. Closeable
  3. AutoCloseable
  4. TraversableOnce
  5. GenTraversableOnce
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def close(): Unit

    Releases any resource used by this CsvReader.

    Releases any resource used by this CsvReader.

    This happens automatically whenever a fatal error occurs or there is no more CSV rows to read. Applications that do not read the entire stream, however, need to call close manually.

    Definition Classes
    CsvReader → Closeable → AutoCloseable
  2. abstract def hasNext: Boolean

    Returns true if there is at least one mor row to read, false otherwise.

  3. abstract def readNext(): A

    Reads the next CSV row.

    Reads the next CSV row.

    This method is not meant for internal purposes only and is not meant to be called directly. Use next instead.

    Attributes
    protected

Concrete Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def /:[B](z: B)(op: (B, A) ⇒ B): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  5. def :\[B](z: B)(op: (A, B) ⇒ B): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. def addString(b: StringBuilder): StringBuilder

    Definition Classes
    TraversableOnce
  9. def addString(b: StringBuilder, sep: String): StringBuilder

    Definition Classes
    TraversableOnce
  10. def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

    Definition Classes
    TraversableOnce
  11. def aggregate[B](z: B)(seqop: (B, A) ⇒ B, combop: (B, B) ⇒ B): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  12. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  13. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def collect[B](f: PartialFunction[A, B]): CsvReader[B]

    Applies the specified partial function to all CSV rows.

    Applies the specified partial function to all CSV rows.

    Any row for which the function is not defined will be filtered out. All other rows will be replaced by the returned value.

    This is particularly useful when dealing with kantan.csv.ReadResult: it's an easy way of skipping over all failures and keeping successes only:

    val rows: CsvReader[(Int, String)] = file.asCsvReader[(Int, String)](',', true).collect {
    case Success(a) ¬ヌメ a
    }
    f

    partial function to apply to each row.

  15. def collectFirst[B](pf: PartialFunction[A, B]): Option[B]

    Definition Classes
    TraversableOnce
  16. def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  17. def copyToArray[B >: A](xs: Array[B]): Unit

    Definition Classes
    TraversableOnce → GenTraversableOnce
  18. def copyToArray[B >: A](xs: Array[B], start: Int): Unit

    Definition Classes
    TraversableOnce → GenTraversableOnce
  19. def copyToBuffer[B >: A](dest: Buffer[B]): Unit

    Definition Classes
    TraversableOnce
  20. def count(p: (A) ⇒ Boolean): Int

    Definition Classes
    TraversableOnce → GenTraversableOnce
  21. def drop(n: Int): CsvReader[A]

    Discards the first n rows.

    Discards the first n rows.

    n

    number of rows to discard.

  22. def dropWhile(p: (A) ⇒ Boolean): CsvReader[A]

    Discards rows while the specified predicate holds.

    Discards rows while the specified predicate holds.

    The returned CsvReader will start at the first row for which p returned false.

    p

    predicate to apply to each row.

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

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

    Definition Classes
    AnyRef → Any
  25. def exists(p: (A) ⇒ Boolean): Boolean

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  26. def filter(p: (A) ⇒ Boolean): CsvReader[A]

    Filters out all rows that validate the specified predicate.

    Filters out all rows that validate the specified predicate.

    Working with CsvReader of ReadResult is such a common pattern that kantan.csv provides syntax for filtering directly into the ReadResult:

    import kantan.csv.ops._
    
    someFile.asCsvReader[Person](',', true).filterResult(_.age > 18)
    p
    returns

  27. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  28. def find(p: (A) ⇒ Boolean): Option[A]

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  29. def flatMap[B](f: (A) ⇒ CsvReader[B]): CsvReader[B]

    Turns a CsvReader[A] into a CsvReader[B].

    Turns a CsvReader[A] into a CsvReader[B].

    f

    function to apply to each row.

  30. def fold[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1

    Definition Classes
    TraversableOnce → GenTraversableOnce
  31. def foldLeft[B](z: B)(op: (B, A) ⇒ B): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  32. def foldRight[B](z: B)(op: (A, B) ⇒ B): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  33. def forall(p: (A) ⇒ Boolean): Boolean

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  34. def foreach[U](f: (A) ⇒ U): Unit

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  35. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  36. def hasDefiniteSize: Boolean

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  37. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  38. def isEmpty: Boolean

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  39. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  40. def isTraversableAgain: Boolean

    Definition Classes
    CsvReader → GenTraversableOnce
  41. def map[B](f: (A) ⇒ B): CsvReader[B]

    Turns a CsvReader[A] into a CsvReader[B].

    Turns a CsvReader[A] into a CsvReader[B].

    Working with CsvReader of ReadResult is such a common pattern that kantan.csv provides syntax for mapping directly into the ReadResult:

    import kantan.csv.ops._
    
    someFile.asCsvReader[Person](',', true).mapResult(_.name)
    f

    function to apply to each row.

  42. def max[B >: A](implicit cmp: Ordering[B]): A

    Definition Classes
    TraversableOnce → GenTraversableOnce
  43. def maxBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A

    Definition Classes
    TraversableOnce → GenTraversableOnce
  44. def min[B >: A](implicit cmp: Ordering[B]): A

    Definition Classes
    TraversableOnce → GenTraversableOnce
  45. def minBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A

    Definition Classes
    TraversableOnce → GenTraversableOnce
  46. def mkString: String

    Definition Classes
    TraversableOnce → GenTraversableOnce
  47. def mkString(sep: String): String

    Definition Classes
    TraversableOnce → GenTraversableOnce
  48. def mkString(start: String, sep: String, end: String): String

    Definition Classes
    TraversableOnce → GenTraversableOnce
  49. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  50. def next(): A

    Reads the next CSV row.

    Reads the next CSV row.

    This method will automatically call close if an error occurs or the end of the CSV data has been reached.

  51. def nonEmpty: Boolean

    Definition Classes
    TraversableOnce → GenTraversableOnce
  52. final def notify(): Unit

    Definition Classes
    AnyRef
  53. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  54. def product[B >: A](implicit num: Numeric[B]): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  55. def reduce[A1 >: A](op: (A1, A1) ⇒ A1): A1

    Definition Classes
    TraversableOnce → GenTraversableOnce
  56. def reduceLeft[B >: A](op: (B, A) ⇒ B): B

    Definition Classes
    TraversableOnce
  57. def reduceLeftOption[B >: A](op: (B, A) ⇒ B): Option[B]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  58. def reduceOption[A1 >: A](op: (A1, A1) ⇒ A1): Option[A1]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  59. def reduceRight[B >: A](op: (A, B) ⇒ B): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  60. def reduceRightOption[B >: A](op: (A, B) ⇒ B): Option[B]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  61. def reversed: List[A]

    Attributes
    protected[this]
    Definition Classes
    TraversableOnce
  62. def seq: TraversableOnce[A]

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  63. def size: Int

    Definition Classes
    TraversableOnce → GenTraversableOnce
  64. def sum[B >: A](implicit num: Numeric[B]): B

    Definition Classes
    TraversableOnce → GenTraversableOnce
  65. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  66. def take(n: Int): CsvReader[A]

    Takes the first n rows, discarding the remaining ones.

    Takes the first n rows, discarding the remaining ones.

    n

    number of rows to take.

  67. def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A]]): Col[A]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  68. def toArray[B >: A](implicit arg0: ClassTag[B]): Array[B]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  69. def toBuffer[B >: A]: Buffer[B]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  70. def toIndexedSeq: IndexedSeq[A]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  71. def toIterable: Iterable[A]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  72. def toIterator: Iterator[A]

    Definition Classes
    CsvReader → GenTraversableOnce
  73. def toList: List[A]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  74. def toMap[T, U](implicit ev: <:<[A, (T, U)]): Map[T, U]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  75. def toSeq: Seq[A]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  76. def toSet[B >: A]: Set[B]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  77. def toStream: Stream[A]

    Definition Classes
    CsvReader → GenTraversableOnce
  78. def toString(): String

    Definition Classes
    AnyRef → Any
  79. def toTraversable: Traversable[A]

    Definition Classes
    CsvReader → TraversableOnce → GenTraversableOnce
  80. def toVector: Vector[A]

    Definition Classes
    TraversableOnce → GenTraversableOnce
  81. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  84. def withFilter(p: (A) ⇒ Boolean): CsvReader[A]

Deprecated Value Members

  1. def /:\[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1

    Definition Classes
    GenTraversableOnce
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) use fold instead

Inherited from Closeable

Inherited from AutoCloseable

Inherited from TraversableOnce[A]

Inherited from GenTraversableOnce[A]

Inherited from AnyRef

Inherited from Any

Ungrouped