Cross product in Scala

后端 未结 7 2045
滥情空心
滥情空心 2020-12-01 09:04

I want to have a binary operator cross (cross-product/cartesian product) that operates with traversables in Scala:

val x = Seq(1, 2)
val y = Lis         


        
相关标签:
7条回答
  • 2020-12-01 09:48

    Alternative for cats users:

    sequence on List[List[A]] creates cross product:

    import cats.implicits._
    
    val xs = List(1, 2)
    val ys = List("hello", "world", "bye")
    
    List(xs, ys).sequence 
    //List(List(1, hello), List(1, world), List(1, bye), List(2, hello), List(2, world), List(2, bye))
    
    0 讨论(0)
提交回复
热议问题