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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:44:58+00:00 2026-05-24T23:44:58+00:00

So say i have some list like val l = List((1, blue), (5, red),

  • 0

So say i have some list like

val l = List((1, "blue"), (5, "red"), (2, "green"))

And then i want to filter one of them out, i can do something like

val m = l.filter(item => {
    val (n, s) = item          // "unpack" the tuple here
    n != 2
}

Is there any way i can “unpack” the tuple as the parameter to the lambda directly, instead of having this intermediate item variable?

Something like the following would be ideal, but eclipse tells me wrong number of parameters; expected=1

val m = l.filter( (n, s) => n != 2 )

Any help would be appreciated – using 2.9.0.1

  • 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-24T23:44:59+00:00Added an answer on May 24, 2026 at 11:44 pm

    This is about the closest you can get:

     val m = l.filter { case (n, s) => n != 2 }
    

    It’s basically pattern matching syntax inside an anonymous PartialFunction. There are also the tupled methods in Function object and traits, but they are just a wrapper around this pattern matching expression.

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

Sidebar

Related Questions

Say I have an unordered list like so: <ul> <li>Some Text</li> <li>Some Text</li> <li>Some
I have some methods that return a List of T like say GetAllEvents. In
Say you have some list L and you want to split it into two
Say you have a std::list of some class. There are two ways you can
Say you have a simple class with some storage data structure (list, vector, queue,
Let's say I have some simple Javascript like: <script> var hello = function(){ alert(Hello
Let's say I have some code (using CherryPy) that looks like this: import cherrypy
i have some code that looks like this and creates a list from an
Say I have a list of names. case class Name(val first: String, val last:
Say I have two lists val L1 = List[(Int, Int)]((1,1), (2,2)) val L2 =

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.