tototoshi / scala-csv

CSV Reader/Writer for Scala
Other
698 stars 141 forks source link

toStreamWithHeaders does not remember the header-line #144

Open ThijsBroersen opened 5 years ago

ThijsBroersen commented 5 years ago

When calling toStreamWithHeaders.head two times it takes the headers correctly on the first call, the second call it used the next line as header-line.

tototoshi commented 5 years ago

Some methods like toStreamWithHeaders are not intended to be called twice since it holds iterator to read lines.

scala> CSVReader.open("a.csv")
res6: com.github.tototoshi.csv.CSVReader = com.github.tototoshi.csv.CSVReader@19dd3ae0

scala> res6.toStream.toList
res7: List[List[String]] = List(List(NAME, VALUE), List(a, 1), List(b, 2), List(c, 3))

scala> res6.toStream.toList
res8: List[List[String]] = List()

When you need to read a file twice, please open the file again with CSVReader#open