Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created April 2, 2011 05:35
Show Gist options
  • Select an option

  • Save amalloy/899263 to your computer and use it in GitHub Desktop.

Select an option

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