How to fix the pattern-matching exhaustive warning?
list, pattern-matching, scala, scala-collections
Solution
If you are using `map` after `filter`, you may to use `collect`.
list collect { case Some(x) => x + "!!!" }
Problem
Some scala code: ``` val list = List(Some("aaa"), Some("bbb"), None, ...) list.filter(_!=None).map { case Some(x) => x + "!!!" // I don't want to handle `None` case since they are not possible // case None } ``` When I run it, the compiler complains: ``` <console>:9: warning: match may not be exhaustive. It would fail on the following input: None list.filter(_!=None).map { ^ res0: List[String] = List(aaa!!!, bbb!!!) ``` How to fix that warning without providing the `case None` line?