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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:27:42+00:00 2026-06-12T12:27:42+00:00

Consider the following structure (in reality the structure is a bit more complex): case

  • 0

Consider the following structure (in reality the structure is a bit more complex):

case class A(id:String,name:String) {
   override def equals(obj: Any):Boolean = {
      if (obj == null || !obj.isInstanceOf[A]) return false
      val a = obj.asInstanceOf[A]
      name == a.name
   }

   override def hashCode() = {
      31 + name.hashCode
   }
}

val a1 = A("1","a")
val a2 = A("2","a")
val a3 = A("3","b")
val list = List((a1,a2),(a1,a3),(a2,a3))

Now let’s say I want to group all tuples with equal A’s. I could implement it like this

list.groupBy {
  case (x,y) => (x,y)
}

But, I don’t like to use pattern matching here, because it’s not adding anything here. I want something simple, like this:

list.groupBy(_)

Unfortunately, this doesn’t compile. Not even when I do:

list.groupBy[(A,A)](_)

Any suggestions how to simplify my code?

  • 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-12T12:27:43+00:00Added an answer on June 12, 2026 at 12:27 pm
    list.groupBy { case (x,y) => (x,y) }
    

    Here you are deconstructing the tuple into its two constituent parts, just to immediately reassemble them exactly like they were before. In other words: you aren’t actually doing anything useful. The input and output are identical. This is just the same as

    list.groupBy { t => t }
    

    which is of course just the identity function, which Scala helpfully provides for us:

    list groupBy identity
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following data structure: List<Person> People; class Person { List<Car> Cars; List<Hobby> Hobbies;
consider the following html structure: <div> <div class=top> <div id=id1>123</div> <div> <div class=top> <div
Consider the following class structure: class Filter { virtual void filter() = 0; virtual
Consider i have 4 workbooks with the following structure... 1. Main.xlsx Name Jan Feb
Consider the following class structure: public class Foo<T> { public virtual void DoSomething() {
Consider the following structure: <ul> <li><a href=>Home</a><img src=menu_hover_line.jpg class=whiteBarHover /></li> <li><a href=>Contacts</a><img src=menu_hover_line.jpg class=whiteBarHover
Consider the following HTML structure: <div class=content> <div class=field field-type-date field-field-event-date> <div class=field-items> <div
Consider I have some big String in the following structure: parameter1|parameter2|parameter3|parameter4+\0 *Where parameter is
Consider a huge CSV with the following structure (modified for simplicity): ID, NAME, ADDRESS,
Consider the following html structure: <div class=entry> <h1>Title</h1> <p>...</p> <p>...</p> <div class=tagged>...</div> <div class=comments>...</div>

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.