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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:11:21+00:00 2026-06-08T08:11:21+00:00

So this compiles: def compress[T](list: List[T]): List[(T, Int)] = { list.zipWithIndex.filter { tuple =>

  • 0

So this compiles:

def compress[T](list: List[T]): List[(T, Int)] =
{
    list.zipWithIndex.filter { tuple => (tuple._2 == 0) || (tuple._1 != list(tuple._2 - 1)) }
}

This does not compile:

def compress[T](list: List[T]): List[(T, Int)] =
{
    list.zipWithIndex.filter { (_._2 == 0) || (_._1 != list(_._2 - 1)) }
}

Why?

  • 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-08T08:11:22+00:00Added an answer on June 8, 2026 at 8:11 am

    _ does not mean x. Instead, it means “use the next parameter in the parameter list” or “convert this method into a function object”, depending on context. In your case, the second one is nonsense because you want a function of one variable but use _ three times.

    Hint: use x or t. Spelling out tuple isn’t likely to help anyone, and the one-letter versions are as compact as _. Better yet,

    filter { case (t,i) => (i==0) || (t != list(i-1)) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This compiles: int* p1; const int* p2; p2 = p1; This does not: vector<int*>
this compiles :-) string name; name = 1; this does not: string name =
scala 2.9.2 This compiles fine object AppBuilder extends App { def app( blockw: Int
def list = List(1,2,3,4).map(1+_).reverse.foreach((i:Int)=> println(i)) compiles correctly but doesn't print anything to the screen.
This compiles fine in Visual studio, but why not in XCode? class A() {};
This compiles: class Ex1 { public int show() { try { int a=10/10; return
This is a simple and complex question at the same time. This compiles: int
Consider this: std::vector<int*> v(1, 0); This compiles fine with VC++10 (no warnings even at
This code compiles, and runs successfully locally, but not on another server. Both machines
In the yabe example, there is this query : def allWithAuthor:List[(Post,User)] = SQL( select

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.