CSV is an unfortunate part of life. This attempts to alleviate the pain somewhat by letting developers treat CSV data as a simple iterator.
As much as possible, kantan.csv attempts to present a purely functional and safe interface to users. I've not hesitated to violate these principles internally however, when it afforded better performances. This approach appears to be somewhat successful.
Documentation and tutorials are available on the companion site, but for those looking for a few quick examples:
importjava.io.Fileimportkantan.csv._// All kantan.csv types.importkantan.csv.ops._// Enriches types with useful methods.importkantan.csv.generic._// Automatic derivation of codecs.// Reading from a file: returns an iterator-like structure on (Int, Int)newFile("points.csv").asCsvReader[(Int, Int)](rfc)
// "Complex" types derivation: the second column is either an int, or a string that might be empty.newFile("dodgy.csv").asCsvReader[(Int, Either[Int, Option[String]])](rfc)
caseclassPoint2D(x: Int, y: Int)
// Parsing the content of a remote URL as a List[Point2D].new java.net.URL("http://someserver.com/points.csv").readCsv[List, Point2D](rfc.withHeader)
// Writing to a CSV file.newFile("output.csv").asCsvWriter[Point2D](rfc)
.write(Point2D(0, 1))
.write(Point2D(2, 3))
.close()
// Writing a collection to a CSV filenewFile("output.csv").writeCsv[Point2D](List(Point2D(0, 1), Point2D(2, 3)), rfc)kantan.csv is distributed under the Apache 2.0 License.