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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:50:33+00:00 2026-05-24T02:50:33+00:00

Say I have two lists val L1 = List[(Int, Int)]((1,1), (2,2)) val L2 =

  • 0

Say I have two lists

val L1 = List[(Int, Int)]((1,1), (2,2))
val L2 = List[(Int, Int, Int)]((1,1,1), (2,2,2))

Now I want to make a function func that takes in an Int value i and all items from both lists where the first element matches i. One way is

def func(i:Int) = {
  L1.collect.collect{case any if any._1 != i => any}
  L2.collect.collect{case any if any._1 != i => any}
}

considering that the two lines are so similar, it would be nice if code can be shortened. I am thinnking of some way where I could pass L1 (and L2) as a parameter to func. The function should not know in advance how many elements the tuple will have, just that the first element is Int.

Is this possible?

[EDIT: I think the question was not clear enough. My apologies.]

Here is what I want to do. I would like to do this on more than two lists, say n, by calling func several times, once for each list.

  L1 = L1.collect.collect{case any if any._1 != i => any}
  L2 = L2.collect.collect{case any if any._1 != i => any}
  ...
  Ln = Ln.collect.collect{case any if any._1 != i => any}

where each L1, L2, … Ln are lists of tuples with first element Int

[EDIT2]

In the above, L1 could be list of (Int, String), L2 could be of (Int, Int, Int), etc. The only guarantee is that the first element is Int.

  • 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-24T02:50:33+00:00Added an answer on May 24, 2026 at 2:50 am
      def func(i:Int, lst: List[Product]) = {
        lst.filter(_.productElement(0) == i)
      }
    

    Edited as per your edit & Dan’s comment above.

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

Sidebar

Related Questions

Lets say I have a function f[x_, y_] , and two lists l1 ,
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
let's say I have two lists: a = list(1,2,3) b = list(4,5,6) So I
I need to run a function that takes two arguments several times. I have
Let's say I have a list somewhere called majorPowers which contain these two lists:
Say I have a trait that has two lists. Sometimes I'm interested in the
Say I have two lists or arrays of strings. For example: list 1: a,
Say I have two lists: List<CanidateSkill> canidateSkills; List<JobDesiredSkill> desiredSkills; class CanidateSkill { public Guid
I have two generic lists. Let's say they are List< A > and List<
Say I have two lists: var list1 = new int[] {1, 2, 3}; var

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.