Created
November 30, 2009 09:57
-
-
Save ato/245377 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 select-indices | |
"Given a sorted seq of indices return the items in coll at those positions." | |
([indices coll] (select-indices 0 indices coll)) | |
([start indices coll] | |
(lazy-seq | |
(when-let [[i & is] (seq indices)] | |
(let [xs (drop (- i start) coll)] | |
(cons (first xs) | |
(select-indices i is xs))))))) | |
(select-indices [0 3 3 4] [:a :b :c :d :e :f :g]) | |
;; -> (:a :d :d :e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment