2

I'm trying to create a scopt option for Seq[String]:

import scopt._
import scopt.Read._
opt[Seq[String]]("foobar")
                ^ error

but the compiler complains that it could not find implicit value for evidence parameter of type scopt.Read[Seq[String]].

I'm using Scala 2.11.2 and scopt 3.3.0.

Am I missing an import or something else?

Ralph
  • 31,584
  • 38
  • 145
  • 282

2 Answers2

0

This error seems to be resolved in scopt "3.6.0"

here's what my build.sbt looks like:

scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
  "org.apache.spark" % "spark-core_2.11" % "2.1.0" ,
  "com.github.scopt" %% "scopt" % "3.6.0")
-1

Looking at the source code, it looks like you just need to import scopt.Read. This will import the Read companion object which contains an implicit to handle this for you:

// reads("1,2,3,4,5") == Seq(1,2,3,4,5)
implicit def seqRead[A: Read]: Read[Seq[A]] = reads { (s: String) =>
  s.split(sep).map(implicitly[Read[A]].reads)
}

Note: I have not run this through a REPL to verify, but it should work.

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180