Skip to content

Instantly share code, notes, and snippets.

@dchrusciak
Last active August 29, 2015 13:57
Show Gist options
  • Save dchrusciak/9649289 to your computer and use it in GitHub Desktop.
Save dchrusciak/9649289 to your computer and use it in GitHub Desktop.
def grouped[T](ts: Seq[T], n: Int) = {
def go(xs: Seq[T], acc: Seq[Seq[T]]): Seq[Seq[T]] = xs match {
case Nil => acc
case _ =>
val (first, second) = xs.splitAt(n)
go(second, first +: acc)
}
go(ts, Seq()).reverse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment