WestCoastProjects
WestCoastProjects

Reputation: 63172

Simple destructuring extractor for command line args

The preferred approach would be to use something similar to the commented out line below.

  def main(args: Array[String]) {
//    val (dbPropsFile, tsvFile, dbTable) = args
    val dbPropsFile = args(0)
    val tsvFile = args(1)
    val dbTable = args(2)

However I am having a little quarrel with the compiler over it:

Error:(13, 9) constructor cannot be instantiated to expected type;
 found   : (T1, T2, T3)
 required: Array[String]
    val (dbPropsFile, tsvFile, dbTable) = args

    ^

So all told this should be an easy few points for someone out there.

Upvotes: 2

Views: 71

Answers (1)

Marth
Marth

Reputation: 24812

Use val Array(dbPropsFile, tsvFile, dbTable) = args

scala> val Array(a,b,c) = Array(1,2,3)
a: Int = 1
b: Int = 2
c: Int = 3

scala> a
res0: Int = 1

Upvotes: 3

Related Questions