Skip to content

Instantly share code, notes, and snippets.

@bkersten
Created November 23, 2011 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkersten/1388295 to your computer and use it in GitHub Desktop.
Save bkersten/1388295 to your computer and use it in GitHub Desktop.
select-vals returns a list of map values in the order of the supplied key sequence
(defn select-vals [map keyseq]
"Returns a list containing the entries in map whose key is in keys, in order of the supplied keys, with nil in place of keys not found"
(loop [ret [] keys (seq keyseq)]
(if keys
(let [value (first (rest (. clojure.lang.RT (find map (first keys)))))]
(recur
(if value
(conj ret value)
(conj ret nil))
(next keys)))
ret)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment