A Strongly typed Csv to CollSeq[T1,T2,...Tn] or Iterator[TupleN] Parser.
A Strongly typed Csv to CollSeq[T1,T2,...Tn] or Iterator[TupleN] 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))
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 converter for dates (intended to be used by CsvParser) using an underlying java.text.SimpleDateFormat.
A converter for dates (intended to be used by CsvParser) using an underlying java.text.SimpleDateFormat.
You can create one like so:
implicit val ymd=new DateConverter("yyyy-MM-dd")
The compiler will then provide this converter to CsvParser whenever you try to parse a java.util.Date
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) }
Note: the above example is a bit contrived because a pre-existing DateConverter class exists. See the com.github.marklister.collections.io.DateConverter docs.
The companion class for GeneralConverter.
The companion class for GeneralConverter. It contains several default converters used by com.github.marklister.collections.io.CsvParser