Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:35:40+00:00 2026-06-08T09:35:40+00:00

As we know that we can define a repeated-parameter (varargs) function in scala, like

  • 0

As we know that we can define a repeated-parameter (varargs) function in scala, like this:

def func(s: String*) = println(s)

My question is how to rewrite the above in function literal style. Or is it impossible to do that?

Note: (s: String) => println(s) is not correct .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:35:42+00:00Added an answer on June 8, 2026 at 9:35 am

    As we know that we can define a multi-parameter function in scala, like this:

    def func(s: String*) = println(s)
    

    Actually, that’s not a function, that’s a method. The two are fundamentally different in Scala.

    My question is how to rewrite the above in function literal style. Or is it impossible to do that ?

    Note: (s: String*) => println(s) is not correct.

    You cannot define a varargs argument in a function literal. There’s a bug report about this in the Scala bug tracker and a comment by Martin Odersky himself that basically says that this would be much too complicated.

    There are several ways to cheat, however.

    If you use type inference for the function arguments, i.e. if you use the function literal in a context where the argument is statically known to be a varargs argument, then everything works fine:

    val func: (String*) => Unit = s => println(s)
    

    Alternatively, you can define a method and then convert it to a partially applied function via η-expansion:

    def meth(s: String*) = println(s)
    
    val func = meth _
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One can easily define a function that accepts a 1d array argument like this:
I know that I can track when the mouse is moved like this: $(body).mousemove(
I know that when you define a function in vim, you can use the
I know that when you define a function in vim, you can use the
I want to know Can I define any function application wide ? like say
For throwing exceptions I know that you can declare/define the function with the implication
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
I know that we can define two types linking each other, for instance: type
I know that if I have an XML file like this: <persons> <class name=English>
I know that with other properties you can define their default value by using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.