Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double variable argument list

I need something like this:

class Node (left : Node*, right : Node*)

I understand the ambiguity of this signature.

Is there a way around it better than the following?

class Node (left : Array[Node, right : Array[Node])
val n = new Node (Array(n1, n2), Array(n3))

Maybe some kind of separator like this?

val n = new Node (n1, n2, Sep, n3)
like image 744
Łukasz Lew Avatar asked Dec 08 '22 03:12

Łukasz Lew


1 Answers

You can have multiple argument lists, each of which may have (or just be) one repeated-args parameter:

scala> def m1(ints: Int*)(strs: String*): Int = ints.length + strs.length
dm1: (ints: Int*)(strs: String*)Int

scala> m1(1, 2, 3)("one", "two", "three")
res0: Int = 6

I ran this in the Scala 2.8 REPL. I don't know a reason it wouldn't work in 2.7, offhand.

like image 183
Randall Schulz Avatar answered Dec 09 '22 15:12

Randall Schulz