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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:35:42+00:00 2026-06-11T18:35:42+00:00

I want to write a function which accepts a list of sequence in which

  • 0

I want to write a function which accepts a list of sequence in which each sequence will be used in for comprehension expression.

eg.

for (x <- (1 to 10); y <- (1 to 10)) yield List(x,y)

In the above expression, I must know before hand that I want a combination of x and y. WHat if I want a combination of x, y, z …etc… (an unknown number of combination)? If I want 10 combinations, I want to paste 10 snippets “x <- (1 to 10)” into the expression. I think I can do this with macro in Clojure (a way to paste code). How can I do this in Scala?

The function I want to write has the signature like this:

combine(list: List[List[Int]])

The body of the function will use each item in the list to paste into the for comprehension.

Hope you understand my intention.

  • 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-11T18:35:43+00:00Added an answer on June 11, 2026 at 6:35 pm

    If you want to compute the cartesian product of a list of lists, you can do it by chaining map and flatMap calls together recursively. That is what for expressions do anyway.

      def prod(l:List[List[Int]]):List[List[Int]] = l match {
        case Nil => List(Nil)
        case l::ls => l.flatMap(i => prod(ls).map(t =>i::t))
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function printAll(), which accepts only those elements that implement
I want to write a function which takes a list of elements l, a
I want to write a function which filters a list of numbers by removing
I want to write a function which will return after 5 seconds no matter
I want to write a function validate() which will take some pattern or regular
I want to write a function that accepts a parameter which can be either
I want to write a function named size() which will accept either a file
I want to write a function which would return me a Vector of the
I want to write a function which can validate a given value (passed as
i want to write a function that prints multi-dimensional objects which are text (or

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.