Why Scala cannot deduce the type of map (1 & # 8594; 2) .toSet.map (_._ 2), and it can with the help of `filter`

The following code causes the Scala compiler to not output the type _placeholder

Map(1 -> 2).toSet.map(_._2)
<console>:11: error: missing parameter type for expanded function ((x$1) => x$1._2)
       Map(1 -> 2).toSet.map(_._2)

in a similar example with a function filter, Scala type output works well:

Map(1 -> 2).toSet.filter(_._2 > 2)
res6: scala.collection.immutable.Set[(Int, Int)] = Set()

I am using Scala 2.11.7.

+4
source share

Source: https://habr.com/ru/post/1609006/


All Articles