Skip to content

Commit a7cd3af

Browse files
committed
Use Seq[String] for interface instead of List[String]
1 parent afa0c03 commit a7cd3af

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/main/scala/com/github/tototoshi/csv/CSVParser.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ object CSVParser {
3131
/**
3232
* {{{
3333
* scala> com.github.tototoshi.csv.CSVParser.parse("a,b,c", '\\', ',', '"')
34-
* res0: Option[List[String]] = Some(List(a, b, c))
34+
* res0: Option[Seq[String]] = Some(List(a, b, c))
3535
*
3636
* scala> com.github.tototoshi.csv.CSVParser.parse("\"a\",\"b\",\"c\"", '\\', ',', '"')
37-
* res1: Option[List[String]] = Some(List(a, b, c))
37+
* res1: Option[Seq[String]] = Some(List(a, b, c))
3838
* }}}
3939
*/
40-
def parse(input: String, escapeChar: Char, delimiter: Char, quoteChar: Char): Option[List[String]] = {
40+
def parse(input: String, escapeChar: Char, delimiter: Char, quoteChar: Char): Option[Seq[String]] = {
4141
val buf: Array[Char] = input.toCharArray
4242
var fields: Vector[String] = Vector()
4343
var field = new StringBuilder
@@ -299,7 +299,7 @@ object CSVParser {
299299

300300
class CSVParser(format: CSVFormat) extends Serializable {
301301

302-
def parseLine(input: String): Option[List[String]] = {
302+
def parseLine(input: String): Option[Seq[String]] = {
303303
val parsedResult = CSVParser.parse(input, format.escapeChar, format.delimiter, format.quoteChar)
304304
if (parsedResult == Some(List("")) && format.treatEmptyLineAsNil) Some(Nil)
305305
else parsedResult

src/main/scala/com/github/tototoshi/csv/CSVReader.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class CSVReader protected (private val lineReader: LineReader)(implicit format:
2525

2626
private val parser = new CSVParser(format)
2727

28-
def readNext(): Option[List[String]] = {
28+
def readNext(): Option[Seq[String]] = {
2929

3030
@scala.annotation.tailrec
31-
def parseNext(lineReader: LineReader, leftOver: Option[String] = None): Option[List[String]] = {
31+
def parseNext(lineReader: LineReader, leftOver: Option[String] = None): Option[Seq[String]] = {
3232

3333
val nextLine = lineReader.readLineWithTerminator()
3434
if (nextLine == null) {
@@ -86,18 +86,18 @@ class CSVReader protected (private val lineReader: LineReader)(implicit format:
8686

8787
def toStreamWithHeaders: Stream[Map[String, String]] = iteratorWithHeaders.toStream
8888

89-
def toStream: Stream[List[String]] =
89+
def toStream: Stream[Seq[String]] =
9090
Stream.continually(readNext()).takeWhile(_.isDefined).map(_.get)
9191

92-
def all(): List[List[String]] = {
92+
def all(): Seq[Seq[String]] = {
9393
toStream.toList
9494
}
9595

96-
def allWithHeaders(): List[Map[String, String]] = {
96+
def allWithHeaders(): Seq[Map[String, String]] = {
9797
allWithOrderedHeaders._2
9898
}
9999

100-
def allWithOrderedHeaders(): (List[String], List[Map[String, String]]) = {
100+
def allWithOrderedHeaders(): (Seq[String], Seq[Map[String, String]]) = {
101101
val headers = readNext()
102102
val data = headers.map(headers => {
103103
val lines = all()

src/test/scala/com/github/tototoshi/csv/CSVReaderSpec.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
1313
describe("CSVReader") {
1414

1515
it("should be constructed with java.io.File") {
16-
var res: List[String] = Nil
16+
var res: Seq[String] = Nil
1717
using(CSVReader.open(new File("src/test/resources/simple.csv"))) { reader =>
1818
reader foreach { fields =>
1919
res = res ++ fields
@@ -23,7 +23,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
2323
}
2424

2525
it("should be constructed with filename") {
26-
var res: List[String] = Nil
26+
var res: Seq[String] = Nil
2727
using(CSVReader.open("src/test/resources/simple.csv")) { reader =>
2828
reader foreach { fields =>
2929
res = res ++ fields
@@ -83,7 +83,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
8383
}
8484

8585
it("read simple CSV from file") {
86-
var res: List[String] = Nil
86+
var res: Seq[String] = Nil
8787
using(CSVReader.open(new FileReader("src/test/resources/simple.csv"))) { reader =>
8888
reader foreach { fields =>
8989
res = res ++ fields
@@ -94,7 +94,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
9494

9595
it("read simple CSV string") {
9696
val csvString = "a,b,c\nd,e,f\n"
97-
var res: List[String] = Nil
97+
var res: Seq[String] = Nil
9898
using(CSVReader.open(new StringReader(csvString))) { reader =>
9999
reader foreach { fields =>
100100
res = res ++ fields
@@ -104,7 +104,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
104104
}
105105

106106
it("issue #22") {
107-
var res: List[String] = Nil
107+
var res: Seq[String] = Nil
108108
using(CSVReader.open("src/test/resources/issue22.csv")) { reader =>
109109
reader foreach { fields =>
110110
res = res ++ fields
@@ -113,7 +113,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
113113
}
114114

115115
it("issue #32") {
116-
var res: List[String] = Nil
116+
var res: Seq[String] = Nil
117117
using(CSVReader.open("src/test/resources/issue32.csv")(new DefaultCSVFormat {
118118
override val escapeChar: Char = '\\'
119119
})) { reader =>
@@ -124,7 +124,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
124124
}
125125

126126
it("should read csv file whose escape char is backslash") {
127-
var res: List[String] = Nil
127+
var res: Seq[String] = Nil
128128
implicit val format = new DefaultCSVFormat {
129129
override val escapeChar: Char = '\\'
130130
}
@@ -137,7 +137,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
137137
}
138138

139139
it("read simple CSV file with empty quoted fields") {
140-
var res: List[String] = Nil
140+
var res: Seq[String] = Nil
141141
using(CSVReader.open("src/test/resources/issue30.csv")) { reader =>
142142
reader foreach { fields =>
143143
res = res ++ fields
@@ -147,7 +147,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
147147
}
148148

149149
it("should read a file starting with BOM") {
150-
var res: List[String] = Nil
150+
var res: Seq[String] = Nil
151151
using(CSVReader.open("src/test/resources/bom.csv")) { reader =>
152152
reader foreach { fields =>
153153
res = res ++ fields
@@ -165,7 +165,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
165165
}
166166

167167
it("read CSV file including escaped fields") {
168-
var res: List[String] = Nil
168+
var res: Seq[String] = Nil
169169
using(CSVReader.open(new FileReader("src/test/resources/escape.csv"))) { reader =>
170170
reader foreach { fields =>
171171
res = res ++ fields
@@ -175,7 +175,7 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
175175
}
176176

177177
it("should correctly parse fields with line breaks enclosed in double quotes") {
178-
var res: List[Seq[String]] = Nil
178+
var res: Seq[Seq[String]] = Nil
179179
using(CSVReader.open(new FileReader("src/test/resources/line-breaks.csv"))) { reader =>
180180
reader foreach { fields =>
181181
res = res :+ fields
@@ -187,10 +187,10 @@ class CSVReaderSpec extends FunSpec with Matchers with Using {
187187

188188
it("read TSV from file") {
189189
implicit val format = new TSVFormat {}
190-
var res: List[Seq[String]] = Nil
190+
var res: Seq[Seq[String]] = Nil
191191
using(CSVReader.open(new FileReader("src/test/resources/simple.tsv"))(format)) { reader =>
192192
reader.foreach { fields =>
193-
res = res ::: fields :: Nil
193+
res = res :+ fields
194194
}
195195
}
196196
res(0) should be(List("a", "b", "c"))

0 commit comments

Comments
 (0)