Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
を変換する Scala API メソッドはありSeq[Option[T]] -> Seq[T]ますか?
Seq[Option[T]] -> Seq[T]
これは、次の方法で手動で行うことができます。
seq.filter(_.isDefined).map(_.get)
一般的なAPIで上記を行うメソッドがあるかどうか疑問に思っています。
絶対に、そうではありません。(いいえ!)
scala> val so1 = List(Some(1), None, Some(2), None, Some(3)) so1: List[Option[Int]] = List(Some(1), None, Some(2), None, Some(3)) scala> so1.flatten res0: List[Int] = List(1, 2, 3)