Cross product in Scala
问题 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 = 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')) What is the best way to do this in Scala only (i.e. not using something like scalaz)? 回答1: You can do this pretty straightforwardly with an implicit