Skip to content

Instantly share code, notes, and snippets.

@gkossakowski
Created March 19, 2014 19:26
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 gkossakowski/9649344 to your computer and use it in GitHub Desktop.
Save gkossakowski/9649344 to your computer and use it in GitHub Desktop.
def grouped[T](xs: Seq[T], n: Int): Iterator[Seq[T]] = {
val (segment, rest) = xs.splitAt(n)
Iterator(segment) ++ (if (rest.isEmpty) Iterator.empty else grouped(rest, n))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment