Option#getOrElse(Nil) == for { _ <- Option#toList
リファクタ
... val hogeOpt = Option(1) val piyoList = 1 :: 2 :: 3 :: Nil val a = hogeOpt.map { hoge => piyoList.map(_ + hoge) }.getOrElse(Nil) val b = for { hoge <- hogeOpt.toList piyo <- piyoList } yield hoge + piyo
Option#toList
はかんがえてなかったなー・・・
/** Returns a singleton list containing the $option's value * if it is nonempty, or the empty list if the $option is empty. */ def toList: List[A] = if (isEmpty) List() else new ::(this.get, Nil)