How to transform Scala collection of Option[X] to collection of X

前端 未结 2 1340
误落风尘
误落风尘 2020-12-04 23:47

I\'m starting to explore Scala, and one of the things I\'m intrigued by is the Option type and the promise of being able to eliminate null related

2条回答
  •  心在旅途
    2020-12-05 00:07

    val list1 = List(Some(1), None, Some(2))
    val list2 = list1.flatten // will be: List(1,2)
    

提交回复
热议问题