2

I'm learning about collections, and I just noticed these two methods in the Traversable docs. What's the point of the first one? The second one seems to include it.

copyToArray        (xs: Array[A], start: Int, len: Int): Unit
copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit
Rob N
  • 15,024
  • 17
  • 92
  • 165

2 Answers2

6

You are correct that the second subsumes the first. However, the first doesn't actually exist. If you look closer at the docs you'll see the words [use case]:

abstract def copyToArray(xs: Array[A], start: Int, len: Int): Unit
[use case] Copies elements of this collection to an array.

A [use case] in the Scala API shows a simplified form of the signature. This gives the "typical" use in a way that isn't so scary to new Scala programmers who might otherwise be confused by the crazy type signatures.

You see the same thing with many other methods, including map (in which the CanBuildFrom stuff is hidden):

abstract def map[B](f: (A) ⇒ B): CC[B]
[use case] Builds a new collection by applying a function to all elements of this collection.

def map[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[Traversable[A], B, That]): That
Builds a new collection by applying a function to all elements of this collection.

To read an old post where Martin Odersky discusses the issue, see here.

Community
  • 1
  • 1
dhg
  • 52,383
  • 8
  • 123
  • 144
2

That seems to be a scaladoc artifact.

$ scala29
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val c = List(1,2,3)
c: List[Int] = List(1, 2, 3)

scala> c.copyToArray

def copyToArray[B >: A](xs: Array[B]): Unit                         
def copyToArray[B >: A](xs: Array[B], start: Int): Unit             
def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit  

This year's docs are much nicer.

som-snytt
  • 39,429
  • 2
  • 47
  • 129