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
Maybe this helps, as it traverses once only and use recursion
def sequence[A](a: List[Option[A]]): Option[List[A]] = a match { case Nil => Some(Nil) case h :: rest => h.flatMap(x => sequence(rest).map(x :: _)) }