Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created April 2, 2011 05:35
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 amalloy/899263 to your computer and use it in GitHub Desktop.
Save amalloy/899263 to your computer and use it in GitHub Desktop.
(defn alternates
"Split coll into 'threads' subsequences (defaults to 2), feeding
each alternately from the input sequence. Effectively the inverse of
interleave:
(alternates 3 (range 9))
;=> ((0 3 6) (1 4 7) (2 5 8))"
([coll] (alternates 2 coll))
([threads coll]
(for [offset (range threads)]
(take-nth threads
(drop offset coll)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment