2

我正在使用 Scala 和桑格利亚汽酒。1)假设有一个

case class Student {
  Int rollNo,
  Int busNo,
  Int phoneNo
}

2)我得到一个请求对象,其中

req 
 - School
 - Home
 - Student
     - rollNo
     - busNo
     - phoneNo

3) 我有一个转换器函数,可以将 graphQL 样式对象转换为纯 Scala 对象。

现在,我必须检查给定输入请求中是否存在 busNo,如果不存在,则将默认 busNo 设置为 10。

马上,

def someFunc(item: Option[UIRequestModel]): Future[UIResponseModel] = {
val req = CleanseRequest(
      <SomeTHing Related to School which works fine>,
      <Something related to Home which works fine>,
      item.flatMap(_.student.map(Utils.UIStudentToStudent)) //here _.student.map(_.busNo...
    //but after that I'm struck. I would like to check if the value is set or not for busNo, if //not set default value. 
    )
}

此时我无法更改案例类代码或层次结构。

4

0 回答 0