mitchus mitchus - 1 month ago 8
Scala Question

Where is the implementation of Array.map?

In Scala collections (e.g. 2.11 or 2.12), where can I find the code that gets executed when an

Array
is
map
ped?

i.e.

val a = Array(1,2,3)
val b = a.map(_ * 5) // <--- here

Answer

That would be TraversableLike.

When methods such as map are called on arrays, an implicit conversion to ArrayOps kicks in (e.g. Predef.intArrayOps), which in turn derives these methods from SeqLike / TraversableLike through inheritance.