Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created July 2, 2015 13:50
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 oisdk/b0d4b24c7c6206ce1cce to your computer and use it in GitHub Desktop.
Save oisdk/b0d4b24c7c6206ce1cce to your computer and use it in GitHub Desktop.
extension Array {
func splitEvery(nInEach: Int)
-> LazySequence<MapSequenceView<StrideTo<Int>, ArraySlice<T>>> {
return lazy(stride(from: 0, to: self.count, by: nInEach)).map {
from in self[from ..< advance(from, nInEach, self.count)]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment