Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created September 11, 2013 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlecompte/6531437 to your computer and use it in GitHub Desktop.
Save ryanlecompte/6531437 to your computer and use it in GitHub Desktop.
scala> val items = 0 to 10
scala> val numGroups = 4
scala> items.zipWithIndex.foldLeft(Vector.fill(numGroups)(Vector.empty[Int])) { case (acc, (item, idx)) => val i = idx % acc.size; acc.updated(i, acc(i) :+ item) }
Vector(Vector(0, 4, 8), Vector(1, 5, 9), Vector(2, 6, 10), Vector(3, 7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment