I am trying to use a for-comprehension to process instances of Options. However, as my last step, a function I use doesn't return an option but a List[Option[Something]] (Note, not an OptionT[List, Something]). I only want to proceed if all options in the list are instances of Some. Is there a clean way to process this as part of the flatMap calls? Currently I am set up like this:
for {
o1 <- businessLogic1
o2 <- businessLogic2(o1)
rawList = businessLogic3(o2)
list <- if (rawList.forall(_.isDefined))
Some(rawList.map(_.get))
else
None
} { /* processing list */ }
I am sorry in case this question has been asked but I don't know the terminology of what I am looking for so I can't search the web effectively in this regard.
In case I am missing an essential theoretical point, please provide pointers to literature or other resources on the thing I seem to be having troubles understanding.