I'm trying to return a Map[CharSequence, CharSequence]
. The point of the function is to check if another map has a certain key/value pair, and then return a particular CharSequence map.
If I just return an empty map (or string map), this compiles
def returnCharSequenceMap(someOtherMap: Option[Map[String,String]]): Map[CharSequence, CharSequence] = {
Map.empty // or something like Map("A" -> "B")
}
However, this fails to compile
def returnCharSequenceMap(someOtherMap: Option[Map[String, String]]): Map[CharSequence, CharSequence] = {
someOtherMap.map { mapRecord =>
case Some("conditionA") =>
Map("a" -> "b")
case Some("conditionB") =>
Map("a" -> "b", "c" -> "d")
case _ => Map.empty
}
}.getOrElse(Map.empty)
I get this rather obtuse error that I cannot decipher:
[error] found : scala.collection.immutable.Map[_19,String] where type _19 >: _1 <: CharSequence
[error] required: Map[CharSequence,CharSequence]
[error] Note: _19 <: CharSequence, but trait Map is invariant in type A.
[error] You may wish to investigate a wildcard type such as `_ <: CharSequence`. (SLS 3.2.10)
[error] }.getOrElse(Map.empty)
Can someone help point out what I'm doing wrong? I'm trying to understand why I can't just return the map. Thanks!