Skip to content

Instantly share code, notes, and snippets.

@teddyknox
Created October 29, 2015 15:53
Show Gist options
  • Save teddyknox/467b6749eb7aa59ee9b5 to your computer and use it in GitHub Desktop.
Save teddyknox/467b6749eb7aa59ee9b5 to your computer and use it in GitHub Desktop.
Scala product function to generate combinations across sets.
def product[T](seqs: Seq[Seq[T]]): Seq[Seq[T]] = {
var combos = Seq[Seq[T]](Seq[T]())
for (seq <- seqs) {
combos = for {
combo <- combos
id <- seq
} yield combo :+ id
}
combos
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment