Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Last active December 27, 2015 09:59
Show Gist options
  • Select an option

  • Save pedrofurla/7307932 to your computer and use it in GitHub Desktop.

Select an option

Save pedrofurla/7307932 to your computer and use it in GitHub Desktop.
Combinations
scala> List(1,2);
res12: List[Int] = List(1, 2)
scala> for(x <- res12) yield List(x)
res16: List[List[Int]] = List(List(1), List(2))
scala> for(x <- res12; y <- res12) yield List(x,y)
res13: List[List[Int]] = List(List(1, 1), List(1, 2), List(2, 1), List(2, 2))
scala> for(x <- res12; y <- res12; z <- res12) yield List(x,y,z)
res15: List[List[Int]] = List(List(1, 1, 1), List(1, 1, 2), List(1, 2, 1), List(1, 2, 2), List(2, 1, 1), List(2, 1, 2), List(2, 2, 1), List(2, 2, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment