A shim around opencsv.
A shim around opencsv. In future, once it's stable, we'll switch to the CsvReader in js/src/main/scala/collections/io
A Strongly typed Csv to Case Class, CollSeq[T1,T2,...Tn] Iterator[TupleN] or Iterator[Case Class] Parser.
A Strongly typed Csv to Case Class, CollSeq[T1,T2,...Tn] Iterator[TupleN] or Iterator[Case Class] Parser. Use the companion object to instantiate the correct parser:
scala> val p = CsvParser[String,Int,Double] p: com.github.marklister.collections.io.CsvParser3[String,Int,Double] = com.github.marklister.collections.io.CsvParser3@1d8073f scala> p.parseFile("sample.csv") res2: com.github.marklister.collections.immutable.CollSeq3[String,Int,Double] = CollSeq((Jan,10,22.33), (Feb,20,44.2), (Mar,25,55.1)) scala> val data="""10,"stuff",2.2 | 11,"otherstuff",3.0""" data: String = 10,"stuff",2.2 11,"otherstuff",3.0 scala> val parsedData=CsvParser[Int,String,Double].parse(new java.io.StringReader(data)) parsedData: com.github.marklister.collections.immutable.CollSeq3[Int,String,Double] = CollSeq((10,stuff,2.2), (11,otherstuff,3.0)) scala> case class Foo (i:Int,s:String,d:Double) defined class Foo scala> CsvParser(Foo).parse(new java.io.StringReader(data)) res1: Seq[Foo] = List(Foo(10,stuff,2.2), Foo(11,otherstuff,3.0))
A CsvRenderer is a partial function (T) => String You can supply a custom renderer for any of your types that require special handling Have a look at the NaRenderer in Utils for inspiration:
A CsvRenderer is a partial function (T) => String You can supply a custom renderer for any of your types that require special handling Have a look at the NaRenderer in Utils for inspiration:
lazy val NaRenderer: CsvRenderer = {case None => "NA"}
You can chain Renderers using orElse
A General Converter is a wrapper for a function (String)=>T
A General Converter is a wrapper for a function (String)=>T
This function is used by the CsvParser to parse fields of type T
There are several default converters defined or you can make your own and make them available as implict parameters.
The reason we use a wrapper is to avoid any old (String)=>T function being selected by mistake. If you made a GeneralConverter then you almost certainly intended that the parser use it to convert type T.
Example:
implicit object ymd extends GeneralConverter[java.util.Date]{ val f= new java.text.SimpleDateFormat("yy-MM-dd") def convert(x:String)=f.parse(x.trim) }
The companion class for GeneralConverter.
The companion class for GeneralConverter. It contains several default converters used by com.github.marklister.collections.io.CsvParser