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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:47:09+00:00 2026-05-14T16:47:09+00:00

val cross = (for (x<-setA; y<-setB) yield (x,y)) val cross2 = (setA flatMap (x

  • 0
val cross = (for (x<-setA; y<-setB) yield (x,y))

val cross2 = (setA flatMap (x => setB map ((x,_)))

Is there a more elegant way to do this with a cross product operator, or some such?
E.g:

val cross3 = setA cross setB
  • 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-14T16:47:10+00:00Added an answer on May 14, 2026 at 4:47 pm
    import scala.collection.Set
    
    class
    Crossable[E1](es1: Traversable[E1])
    {
        def
        ×[E2](es2: Traversable[E2]): Traversable[(E1, E2)] =
          for (e1 <- es1; e2 <- es2) yield (e1, e2)
    
        def
        cross[E2](es2: Traversable[E2]): Traversable[(E1, E2)] =
          for (e1 <- es1; e2 <- es2) yield (e1, e2)
    }
    
    
    object
    Crossable
    {
        implicit
        def
        trav2Crossable[E1](es1: Traversable[E1]): Crossable[E1] =
            new Crossable[E1](es1)
    }
    
    
    object
    CrossableTest
    {
        def
        main(args: Array[String]): Unit = {
            import Crossable.trav2Crossable
    
            val es1 = Set(1, 2, 3)
            val es2 = List("a", "b", "c")
    
            (es1 × es2) foreach(printf("  %s%n", _))
        }
    }
    
    % scala -cp . CrossableTest
      (1,c)
      (2,b)
      (3,a)
      (2,a)
      (1,a)
      (3,b)
      (3,c)
      (1,b)
      (2,c)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: <td>firstTD</td> <td>secondTD</td> <td>thirdTD</td> <td> <img src=img/cross.png onclick=alert($(this).parent().parent().filter('td:first').val());> </td> Why I didn't get
i have this script: val.split( /(?:,.| )+/ ) and i need to split any
Suppose I have a Map: val m = Map(foo -> 10, bar -> 5)
I'm aware that there is a Cross site forgery attack that can be performed
is there a way to add a specific directory to the Windows systemvariable %PATH%?
In the val docs written this description: .val() Returns: String, Number, Array I tried
I have the following: val it = DATAX (hello,DATAX (world,DATAX #,DATAX #),... Is there
val m: java.util.Map[String, Int] = ... m.foreach { entry => val (key, value) =
type SQLConn = val mutable private connection : string option member this.Connection with get()
Possible Duplicate: val and object inside a scala class? Is there a substantive difference

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.