What is the equivalent of Haskell\'s sequence in Scala? I want to turn list of options into an option of list. It should come out as None if any of the options
None
Since you need to flatten anyway, just do it first...
def sequence(lo: List[Option[A]]): Option[List[A]] = lo.flatten match { la: List[A] if(la.length == lo.length) => Some(la) _ => None }
tail recursion might be quickest