Skip to content

Instantly share code, notes, and snippets.

@ato
Created November 30, 2009 09:57
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 ato/245377 to your computer and use it in GitHub Desktop.
Save ato/245377 to your computer and use it in GitHub Desktop.
(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