Scala Option object inside another Option object

后端 未结 4 2015
情书的邮戳
情书的邮戳 2021-02-08 02:05

I have a model, which has some Option fields, which contain another Option fields. For example:

case class First(second: Option[Second], name: Option[String])
ca         


        
4条回答
  •  忘了有多久
    2021-02-08 02:57

    There is no need for scalaz:

    for { 
      first  <- yourFirst
      second <- f.second
      third  <- second.third
      number <- third.numberOfSmth
    } yield number
    

    Alternatively you can use nested flatMaps

提交回复
热议问题