Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Varargs

object varargsExample {
    //varargs and currying
    def method(arg1: Int*)(arg2: String*) = println(arg1, arg2)
    print("called with separate args: ") 
    method(1,2,3)("one")
    
    val l1 = List(3,3,4)
    print("called with sequence and with use of (_*): ")
    method(l1:_*)("one") 
    
    //partially applied function with varargs
    val method2 = method(1,2,3)_ 
    val list2 = List("hi","ho")
    print("partially applied function with varargs does NOT need _*: ")
    method2(list2)
    
    val l = List(4,5)
    method(l:_*)(list2:_*)
    
    def sum(xs: Int*) = xs.sum
    val summer = sum _
    val nums = List(1,2,3)
    println( summer(nums) )
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.