Skip to content

Instantly share code, notes, and snippets.

@ezhulenev
Created April 4, 2014 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezhulenev/9966059 to your computer and use it in GitHub Desktop.
Save ezhulenev/9966059 to your computer and use it in GitHub Desktop.
import java.io.ByteArrayInputStream
import scalaz.stream.io
import scalaz.std.map._
import scalaz.std.vector._
object CsvParsing extends App {
val csv =
"""|0,2014-01-01,1
|0,2014-01-02,2
|1,2014-01-01,3
|1,2014-01-01,4""".stripMargin
val is = new ByteArrayInputStream(csv.getBytes)
val process = io.linesR(is).
map(_.split(",")). // split to columns
map(arr => (arr(0), arr(2))). // pick id & number columns
runFoldMap { case (id, number) => Map(id -> Vector(number)) }
val output = process.run
println(s"Output: ")
output.foreach(println)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment