I am new to scala programming and am facing difficulty to convert from String to Option[String]. I am not sure if the approach I am following is correct or not. Here is the code:
EmpInfo.scala:
package model
case class EmpInfo(empType: Option[String]) extends Named {
override def name: String = clientName
}
EmpReconciliator.scala
import scalaz._
import Scalaz._
import scala.concurrent.Future
import play.api.mvc.Action
import play.api.mvc.AnyContent
import model.EmpInfo
trait EmpReconciliator[A] extends BaseController[A] {
val oldName = "abc"
val newName = "xyz"
def reconcileGeneric(genericResource: A) = {
(genericResource match {
case empInfo : EmpInfo => reconcileEmpInfo(empInfo)
case other@_ => other
}).asInstanceOf[A]
}
def reconcileEmpInfo(empInfo: EmpInfo) = {
empInfo.empTypeType match {
case Some(oldName) => empInfo.copy(empType = Some(newName))
case _ => empInfo
}
}
}
Here, I need to replace all instances of oldName
with newName
.
But instead, I am getting "1"
in the response. I cannot change type of empType: Option[String]
to String
(need it that way).
I know it's a very minor change needed but cannot place what.
Please help.