Created
April 24, 2014 19:17
-
-
Save mkremins/11266204 to your computer and use it in GitHub Desktop.
Clojure: parse sequential opts delimited by a known set of names
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 parse-opts [ks aseq] | |
(let [ks (set ks)] | |
(loop [last-k nil | |
opts {} | |
frontier aseq] | |
(if-let [value (first frontier)] | |
(if (ks value) | |
(recur value opts (rest frontier)) | |
(recur last-k (update-in opts [last-k] (fnil conj []) value) (rest frontier))) | |
opts)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment