Created
April 2, 2011 05:35
-
-
Save amalloy/899263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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