Thanks Randall Schulz on the good one-line answer.
I was looking for this possibility in order to make an INVARIANT tool that would run multiple asserts together. The solution I then came up with is to simply have 1..5 apply
methods, since the number of varargs needed here is finite.
object INVARIANT {
def apply = {}
def apply( conds: => Boolean * ) = { // DOES NOT COMPILE
conds.foreach( assert(_) )
}
}
object TestX extends App {
class A {
println("A body")
INVARIANT( true )
}
class B extends A {
println("B body")
INVARIANT( true, false )
}
new B
}
I posted this to show what I believe is a valid use case for varargs on 'by-name' variables. If there is a better name, please leave a comment. Thanks.