Created
December 18, 2014 23:07
-
-
Save christianromney/dc6eaf72e28a4f1cc9b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 recursive-take | |
"Recursively take from a list based on the operation list | |
For example [:h :l :l :h] will take using the following operations | |
until the list is exhausted: first last last first." | |
[col operations] | |
(loop [c col ops (cycle operations) acc []] | |
(if (empty? c) | |
acc | |
(let [op (first ops) | |
[head-fn tail-fn] (if (= op :h) | |
[first rest] | |
[last drop-last])] | |
(recur (tail-fn c) (rest ops) (concat [(head-fn c)] acc)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment