everyone . Please forgive me asking a stupid question on Scala.
Though I have been programming in Scala for about 2 years, I still find it hard to understand implicit
usage. Let's take an example for discussion:
Array(1,2,3,4).map(x => x)
If you look up the scaladoc, you cant' find the method map
on Array
class. The reason that map
can apply on Array(1,2,3,4)
is that there is an implicit function implicit def intArrayOps (xs: Array[Int]): ArrayOps[Int]
defined in scala.Predef
.
However, there are two parameter lists, where the second one is written as implicit bf: CanBuildFrom[Array[T], B, That])
. Now I wonder where the compiler finds a proper argument for type CanBuildFrom
when applying map
on Array(1,2,3,4)
.