Sunday, 15 May 2011

scala - How to transform Seq[Option[A]] into Seq[A]? -



scala - How to transform Seq[Option[A]] into Seq[A]? -

i want filter seq some alternative types, , extract contents.

is there single function phone call this?

val list = optionlist.flatmap(_.tolist)

as sschaef points out in comments, can utilize flatten:

val list = optionlist.flatten

scala

No comments:

Post a Comment