In below apply method what is "as: A*" ?
List(1, 2, 3)
constucts a List of type : Cons(1,Cons(2,Cons(3,Nil)))
From reading the method code it appears that its a kind of syntax sugar for multiple type parameters of same type ?
sealed trait List[+A]
case object Nil extends List[Nothing]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
object List {
def apply[A](as: A*): List[A] =
if (as.isEmpty) Nil
else {
Cons(as.head, apply(as.tail: _*))
}
}
If this is true should'nt this be also valid :
object List {
def apply[A](asHead: A , asTail : A): List[A] =
if (asHead.isEmpty) Nil
else {
Cons(asHead.head, apply(asTail.tail: _*))
}