Cross product in Scala

后端 未结 7 2064
滥情空心
滥情空心 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:47

    cross x_list and y_list with:

    val cross = x_list.flatMap(x => y_list.map(y => (x, y)))
    

提交回复
热议问题