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 this warning without providing a string case None?
case None
If you use mapafter filter, you can use collect.
map
filter
collect
list collect { case Some(x) => x + "!!!" }
you can use flatten
flatten
scala> val list = List(Some("aaa"), Some("bbb"), None).flatten list: List[String] = List(aaa, bbb) scala> list.map { | x => x + "!!!" | } res1: List[String] = List(aaa!!!, bbb!!!)
@unchecked, :
@unchecked
list.filter(_!=None).map { x => ( x : @unchecked) match { case Some(x) => x + "!!!" } }
get . :
get
scala> val list = List(Some("aaa"), Some("bbb"), None) list: List[Option[String]] = List(Some(aaa), Some(bbb), None) scala> list.filter(_ != None).map(_.get + "!!!") res0: List[String] = List(aaa!!!, bbb!!!)
- , filter pattern matching
pattern matching
scala> list.flatten map (_ + "!!!")
scala> list.flatMap (_ map (_ + "!!!"))
Source: https://habr.com/ru/post/1548448/More articles:Action :: Mailer does not deliver mail to recipients - ruby-on-rails-4Rails 3: no action mailer specified: from => parameters - ruby-on-railsFailed to deserialize JSON content - jsonFill the round ring with the gradient color according to the percentage. - iosDraw a curved rectangle inside a circle on iOS - iosЗаблокировано с выпуском компиляции студии Android ManifestMerger2 $MergeFailureException - androidГолос в текст Преобразование с помощью Bluetooth-гарнитуры - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1548451/rows-to-map-to-json-using-sqlx-package&usg=ALkJrhhisXsT9u95j4e2Uj0KUaIHsn1v5wFunction overloading for "integral" types - c ++Knockout: find out what observable trigger calculations - javascriptAll Articles