Skip to content

Instantly share code, notes, and snippets.

@rtt
Created October 2, 2012 10:55
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 rtt/3818158 to your computer and use it in GitHub Desktop.
Save rtt/3818158 to your computer and use it in GitHub Desktop.
/*
* Similar to python's itertools.izip_longest;
* takes an array and chunks it according to a given size
*/
func chunk(s []interface{}, sz int) [][]interface{} {
r := [][]interface{}{}
j := len(s)
for i := 0; i < j; i+=sz {
r = append(r, s[i:i+sz])
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment