change
Well, with the new information, I would suggest you create a case class that stores data instead of using Map , so you save type information. I know that distributing hashes / maps for them in dynamically typed languages, but in statically typed languages ββlike scala data types are the preferred way.
orig
Since I do not know what e , and what is the signature of top10Tweets , I can only guess. But from your code and error, I assume that e is Map[String, String] , and you are trying to get the string representation of the integer for the key "retweets" and convert it to Int . You pass Int as the default value, so the inferencer type introduces the Any type, because it is the most common type of Super String and Int . However, Any does not have a toInt method and, therefore, you get an error.
Map("x" -> "2").getOrElse("x", 4).toInt <console>:8: error: value toInt is not a member of Any Map("x" -> "2").getOrElse("x", 4).toInt
Either enter the default value as String , or change the value of "retweets" to Int earlier if it exists:
e.get("retweets").map(_.toInt).getOrElse(0)
In any case, a little more information will help give an accurate answer.
drexin
source share