Skip to content

Instantly share code, notes, and snippets.

@jedws
Forked from fayimora/CSVParser.scala
Created November 26, 2012 20:48
Show Gist options
  • Save jedws/4150522 to your computer and use it in GitHub Desktop.
Save jedws/4150522 to your computer and use it in GitHub Desktop.
package com.fayi.ftp
object CSVParser {
val ADDRESS = "ftp://mirrors.kernel.org/gnu/README.DESCRIPTIONS"
val ADDRESS2 = "ftp://ftp.gnu.org/README"
def main(args: Array[String]) {
def parse(s: Stream[String]) = {
val cells = (_: String).split(",")
val headers = cells(s.head)
val rows = s.tail map cells
headers.zip(rows.transpose).toMap
}
parse(io.Source.fromFile("file1.csv").getLines.toStream).foreach {
case (header, rows) =>
println(header)
rows foreach println
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment