我希望有一个二进制运算符cross(交叉产品/笛卡尔积)在Scala中使用遍历运算:
val x = Seq(1, 2)
val y = List('hello', 'world', 'bye')
val z = x cross y # i can chain as many traversables e.g. x cross y cross w etc
assert z == ((1, 'hello'), (1, 'world'), (1, 'bye'), (2, 'hello'), (2, 'world'), (2, 'bye'))
Run Code Online (Sandbox Code Playgroud)
仅在Scala中执行此操作的最佳方法是什么(即不使用scalaz之类的东西)?
functional-programming scala cartesian-product cross-product