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

  • Home
  • SEARCH
  • 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 6078899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:08+00:00 2026-05-23T10:53:08+00:00

Object L1 below works. I can create an L1 by passing in varargs, which

  • 0

Object L1 below works. I can “create” an L1 by passing in varargs, which is nice, but I would like to be able to assign to an L1 using the same syntax. Unfortunately, the way I’ve done it here requires the uglier syntax of nesting an Array inside the L1.

object L1 {
    def apply(stuff: String*) = stuff.mkString(",")
    def unapply(s: String) = Some(s.split(","))
}
val x1 = L1("1", "2", "3")
val L1(Array(a, b, c)) = x1
println("a=%s, b=%s, c=%s".format(a,b,c))

I attempted accomplish this in what seems like an obvious way, as in L2 below:

object L2 {
    def apply(stuff: String*) = stuff.mkString(",")
    def unapply(s: String) = Some(s.split(","):_*)
}
val x2 = L2("4", "5", "6")
val L2(d,e,f) = x2
println("d=%s, e=%s, f=%s".format(d,e,f))

But this give the error:

error: no `: _*' annotation allowed here 
(such annotations are only allowed in arguments to *-parameters)`.

Is it possible for unapply to use varargs in this way?

  • 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-05-23T10:53:09+00:00Added an answer on May 23, 2026 at 10:53 am

    I think what you want is unapplySeq. Jesse Eichar has a nice write up on unapplySeq

    scala> object L2 {
         |     def unapplySeq(s: String) : Option[List[String]] = Some(s.split(",").toList)
         |     def apply(stuff: String*) = stuff.mkString(",")
         | }
    defined module L2
    
    scala> val x2 = L2("4", "5", "6")
    x2: String = 4,5,6
    
    scala> val L2(d,e,f) = x2
    d: String = 4
    e: String = 5
    f: String = 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this plugin to create charts: http://www.filamentgroup.com/lab/update_to_jquery_visualize_accessible_charts_with_html5_from_designing_with/ The code works below if
I'm trying to create an EJB factory class, which works like this: You have
Using the jQuery code below, I'm trying to take a JSON object to create
Whats wrong in below JSON Object definition I am trying to create a new
I constantly find myself writing similar code like the example below: if (object[Object Name]
When initializing a new Date object in JavaScript using the below call, I found
As you can see below, in the constructor I'm instantiating a validation object so
I am working with an object which has sub objects within (see example below).
In the code below, I would like the second method to be generic, too,
I have the code below which works fine, steps through the rows pinging each

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.