Un-optioning an optioned Option

后端 未结 6 1139
甜味超标
甜味超标 2021-02-02 07:05

Say I have a val s: Option[Option[String]]. It can thus have the following values:

Some(Some(\"foo\")) Some(None) None

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 07:24

    It's a shame that flatten doesn't exist. It should.

    Flatten does exist now.

    As before,

    s getOrElse None
    

    (in addition to the other answers) will also do the same thing.

提交回复
热议问题