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 5930815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:36:21+00:00 2026-05-22T14:36:21+00:00

I have the following piece of code from this question : def addChild(n: Node,

  • 0

I have the following piece of code from this question:

def addChild(n: Node, newChild: Node) = n match {
  case Elem(prefix, label, attribs, scope, child @ _*) => Elem(prefix, label, attribs, scope, child ++ newChild : _*)
  case _ => error("Can only add children to elements!")
}

Everything in it is pretty clear, except this piece: child ++ newChild : _*

What does it do?

I understand there is Seq[Node] concatenated with another Node, and then? What does : _* do?

  • 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-22T14:36:22+00:00Added an answer on May 22, 2026 at 2:36 pm

    It "splats"1 the sequence.

    Look at the constructor signature

    new Elem(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding,
             child: Node*)
    

    which is called as

    new Elem(prefix, label, attributes, scope,
             child1, child2, ... childN)
    

    but here there is only a sequence, not child1, child2, etc. so this allows the result sequence to be used as the input to the constructor.


    1 This doesn’t have a cutesy-name in the SLS, but here are the details. The important thing to get is that it changes how Scala binds the arguments to the method with repeated parameters (as denoted with Node* above).

    The _* type annotation is covered in "4.6.2 Repeated Parameters" of the SLS.

    The last value parameter of a parameter section may be suffixed by “*”, e.g. (…, x:T ). The type of such a repeated parameter inside the method is then
    the sequence type scala.Seq[T]. Methods with repeated parameters T * take
    a variable number of arguments of type T . That is, if a method m with type
    (p1 : T1, . . . , pn : Tn,ps : S
    )U is applied to arguments (e1, . . . , ek) where k >= n, then
    m is taken in that application to have type (p1 : T1, . . . , pn : Tn,ps : S, . . . , ps0S)U,
    with k ¡ n occurrences of type S where any parameter names beyond ps are
    fresh. The only exception to this rule is if the last argument is marked to be
    a sequence argument via a _
    type annotation. If m above is applied to arguments (e1, . . . , en,e0 : _), then the type of m in that application is taken to be
    (p1 : T1, . . . , pn : Tn,ps :scala.Seq[S])**

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code from a book. There is this function
I have the following piece of code taken from the PHP manual on the
I have the following piece of code. This is written for getting the list
I have this following piece of code: public TimestampedRowStorage GetTimestampedRowStorage(string startTime, string endTime, long
Hey folks, I have the following piece of code from C++. for (int i=0;
I have the following piece of code def show unless logged_in? login_required return end
I have the following piece of code which is being run from a click
I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
I have the following piece of code pattern: void M1(string s, string v) {
I have the following piece of code which replaces template markers such as %POST_TITLE%

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.