I have a function that should find command-line parameter with it's value and return converted to type P:
def parameter[P](name: String)(implicit tag: ClassTag[P]): P = {
val paramName = s"--$name"
args.sliding(2, 2).toList.collectFirst {
case Array(`paramName`, param: String) => {
// if P is Int => param.toInt
// if P is Double => param.toDouble
}
}.get
}
How do I do that? I've found that ClassTag is a way to go, but can't figure out how to use it in this case.