It really returns an array, as expected, and, as conveniently, there is no reason why you need ArrayOps, it is only intended to provide additional methods for arrays. The document is erroneous.
In ArrayOps, the procedure is not actually implemented. Like most collection methods, it inherits from TraversableLike. And you see two map methods in the document:
def map [B] (f: (T) ⇒ B): ArrayOps[B] def map [B, That] (f: (T) ⇒ B)(implicit bf: CanBuildFrom[Array[T], B, That]): That
Only the second exists (inherited from TraversableLike). It is designed to allow the implementation of the map in only one place (with the possibility of passing), while it always gives the best possible behavior. For example, String is Seq [Char], if you map a function from character to character, you get a string, but if you type from a collection to say Int, the result cannot be a string, and it will just be Seq. This is explained in detail in the article dealing with bit rot with types .
However, this leads to a very complex signature that does not reflect the ease of use of the method and most of the time does very poor documentation (usually you will need to pursue with which CanBuildFrom works in the implicit area). This was discussed in the most famous scala stack overflow issue . In this way, the scaladoc tool has been expanded so that a simpler record appears to fit the intended use. If you look at the source of the GenTraversableLike where the procedure will be introduced, you will see the following in the scaladoc for the map (and similar to one of many methods)
@usecase def map[B](f: A => B): $Coll[B]
Subtypes add @define Coll <className> to their document, and the map (among other things) appears with a simplified signature marked [Use case]. In source ArrayOps there is @define Coll ArrayOps , where Array should be.
Didier dupont
source share