Skip to content

Instantly share code, notes, and snippets.

@jsuereth
Created August 13, 2011 02:23
Show Gist options
  • Save jsuereth/1143392 to your computer and use it in GitHub Desktop.
Save jsuereth/1143392 to your computer and use it in GitHub Desktop.
Demystifying varags... hopefully..
scala> def foo[A](x: A*): Seq[A] = x
foo: [A](x: A*)Seq[A]
scala> foo(1,2,3,4,5,6)
res0: Seq[Int] = WrappedArray(1, 2, 3, 4, 5, 6)
scala> def foo[A](x: A*) = x
foo: [A](x: A*)A*
scala> foo(1,2,3,4,5)
res1: Int* = WrappedArray(1, 2, 3, 4, 5)
scala> foo(1,2,3,4,5).map(_+10)
res2: Seq[Int] = ArrayBuffer(11, 12, 13, 14, 15)
@jsuereth
Copy link
Author

foo[A](x: A*)A* ???? really? Why not just desugar to Seq[A] here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment