sscsv

Simple CSV library for Scala.

License

License

MIT
Categories

Categories

CSV Data Data Formats
GroupId

GroupId

com.github.snowgooseyk
ArtifactId

ArtifactId

sscsv_2.10
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

sscsv
Simple CSV library for Scala.
Project URL

Project URL

https://github.com/snowgooseyk/sscsv
Project Organization

Project Organization

com.github.snowgooseyk
Source Code Management

Source Code Management

https://github.com/snowgooseyk/sscsv

Download sscsv_2.10

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.snowgooseyk/sscsv_2.10/ -->
<dependency>
    <groupId>com.github.snowgooseyk</groupId>
    <artifactId>sscsv_2.10</artifactId>
    <version>0.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.snowgooseyk/sscsv_2.10/
implementation 'com.github.snowgooseyk:sscsv_2.10:0.1.2'
// https://jarcasting.com/artifacts/com.github.snowgooseyk/sscsv_2.10/
implementation ("com.github.snowgooseyk:sscsv_2.10:0.1.2")
'com.github.snowgooseyk:sscsv_2.10:jar:0.1.2'
<dependency org="com.github.snowgooseyk" name="sscsv_2.10" rev="0.1.2">
  <artifact name="sscsv_2.10" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.snowgooseyk', module='sscsv_2.10', version='0.1.2')
)
libraryDependencies += "com.github.snowgooseyk" % "sscsv_2.10" % "0.1.2"
[com.github.snowgooseyk/sscsv_2.10 "0.1.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.4

provided (2)

Group / Artifact Type Version
org.scoverage : scalac-scoverage-runtime_2.10 jar 1.0.4
org.scoverage : scalac-scoverage-plugin_2.10 jar 1.0.4

test (3)

Group / Artifact Type Version
org.specs2 : specs2-core_2.10 jar 3.6.2
org.specs2 : specs2-junit_2.10 jar 3.6.2
org.specs2 : specs2-mock_2.10 jar 3.6.2

Project Modules

There are no modules declared in this project.

Simple CSV library for Scala

Build Status Coverage Status License

Supports Scala 2.10+

Usage

Add SBT dependency.

"com.github.snowgooseyk" %% "sscsv" % "0.1.2"

Read CSV file

Read CSV formatted data.

foo,bar,baz
d,e,f
import com.github.snowgooseyk.sscsv._

// List(List(foo,bar,baz),List(d,e,f))
CSV("/home/snowgooseyk/import.csv").asList

// List(ListMap(foo -> d,bar -> e,baz -> f))
CSV("/home/snowgooseyk/import.csv").asMapList

// Get scala.collection.Iterator[Seq[String]]
CSV("/home/snowgooseyk/import.csv").iterator

// Map to some object
// Seq((foo,bar,baz),(d,e,f))
CSV("/home/snowgooseyk/import.csv").map { columns =>
  Tuple3(columns(0),columns(1),columns(2))
}

// Zip with index
// Seq(
//   (Seq(foo,bar,baz),0),
//   (Seq(d,e,f),1)
// )
CSV("/home/snowgooseyk/import.csv").zipWithIndex

// Zip with header values
// Seq(
//   Seq((d,foo),(e,bar),(f,baz))
// )
CSV("/home/snowgooseyk/import.csv").zipWithHeader

// Zip with header and index
// Seq(
//   (Seq((d,foo),(e,bar),(f,baz)),0)
// )
CSV("/home/snowgooseyk/import.csv").zipWithHeaderAndIndex

// Print all column value.
// foo 
// bar 
// baz 
// d 
// e 
// f 
CSV("/home/snowgooseyk/import.csv").foreach(_.foreach(println))

// You can also use java.io.File, java.io.InputStream ,java.io.Reader and CSV formatted String.
// List(List(foo,bar,baz),List(d,e,f))
import java.io.File
CSV(new File("/home/snowgooseyk/import.csv")).asList

// List(List(foo,bar,baz),List(d,e,f))
import java.io.FileInputStream
CSV(new FileInputStream(new File("/home/snowgooseyk/import.csv"))).asList

// List(List(foo,bar,baz),List(d,e,f))
import java.io.FileReader
CSV(new FileReader(new File("/home/snowgooseyk/import.csv"))).asList

// List(List(foo,bar,baz),List(d,e,f))
val csv:String = "foo,bar,baz" + scala.util.Properties.lineSeparator + "d,e,f"
CSV.from(csv).asList

This library supports a dirty CSV.

aaa,bbb,ccc
"ddd",eee,"Value contains line-separator
 or comma, or double-quote"" that have no problem."
import java.io.File
import com.github.snowgooseyk.sscsv._

// List(List(aaa,bbb,ccc),List(ddd,eee,line-separator or comma, or double-quote" that have no problem.))
CSV("/home/snowgooseyk/import.csv").asList

Write CSV file

import java.io.File
import com.github.snowgooseyk.sscsv._

val csv = CSV.into(new File("/home/snowgooseyk/export.csv"))

// Appends(++) data and flush(!) file per line(ln).
csv ++ "foo" ++ "baa" ++ "baz" ln() !
csv ++ "d" ++ "e" ++ "f" ln() !

// Show the outputs
// "foo","baa","baz"
// "d","e","f"

Versions

Version
0.1.2
0.1.1
0.1.0