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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:32:09+00:00 2026-05-13T20:32:09+00:00

I have been searching for a bit but can not locate any examples that

  • 0

I have been searching for a bit but can not locate any examples that demonstrate the usage of @_* while pattern matching case classes.

Below is an example of the kind of application I am referring to.

def findPerimeter(o: SomeObject): Perimeter = o match {
case Type1(length, width) =>
  new Perimeter(0, 0, length, width)
case Type2(radius) =>
  new Perimeter(0, 0, 2*radius, 2*radius)
...

case MixedTypes(group @_*) => {
  \\How could @_* be used to check subpatterns of group?
}

}

If someone could show me some examples or point me to a web page that has a few examples that would be great.

Thanks

  • 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-13T20:32:10+00:00Added an answer on May 13, 2026 at 8:32 pm

    Remember that something like

    Type2(3.0) match {
      case t2 @ Type2(radius) => //...
    }
    

    binds radius to the value 3.0 and binds t2 to the instance of Type2 being matched against.

    Using your example:

    def findPerimeter(o: SomeObject): Perimeter = o match {
      case Type1(length, width) => new Perimeter(0, 0, length, width)
      case Type2(radius) => new Perimeter(0, 0, 2*radius, 2*radius)
      // ...
      // assume that Perimeter defines a + operator
      case MixedTypes(group @ _*) => group.reduceLeft(findPerimeter(_) + findPerimeter(_))
    
    }
    

    Here, group is bound to the sequence of SomeObjects that define the MixedTypes. You can treat is just like a sequence of whatever-the-constructor-args-for-MixedTypes-is.

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

Sidebar

Related Questions

I have been searching everywhere but I could not find an answer. I need
I have been searching around using Google but I can't find an answer to
I have been searching but unable to find a proper list. Can someone please
I've been playing around and searching a bit, but I can't figure this out.
Have been searching how to convert a dictionary to a string. But the results
I have been searching for a while for a simple right-click menu for a
It seemed like this question should have been asked before, but searching found nothing.
I know that this question has been asked loads of times, but I have
I have seen the following thread but it's a bit beyond me... How can
I know this is a popular topic, but I've been searching quite a bit

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.